-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathservice_layer.cc
69 lines (60 loc) · 1.83 KB
/
service_layer.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include <iostream>
#include <memory>
#include <stack>
#include <string>
#include <gflags/gflags.h>
#include <glog/logging.h>
#include <grpcpp/grpcpp.h>
#include "kvs_client.h"
#include "KeyValueStore.grpc.pb.h"
#include "ServiceLayer.grpc.pb.h"
#include "sl_server.h"
using grpc::Server;
using grpc::ServerBuilder;
using grpc::ServerContext;
using grpc::Status;
using chirp::Chirp;
using chirp::RegisterRequest;
using chirp::RegisterReply;
using chirp::ChirpRequest;
using chirp::ChirpReply;
using chirp::FollowRequest;
using chirp::FollowReply;
using chirp::ReadRequest;
using chirp::ReadReply;
using chirp::MonitorRequest;
using chirp::MonitorReply;
using chirp::ServiceLayer;
using chirp::PutRequest;
using chirp::PutReply;
using chirp::GetRequest;
using chirp::GetReply;
using chirp::DeleteRequest;
using chirp::DeleteReply;
using chirp::KeyValueStore;
// Service Layer's execution (receives requests from command line)
// and creates requests to key-value store
void run() {
// run server on localhost:50002
std::string server_address("0.0.0.0:50002");
ServiceLayerServer service;
ServerBuilder builder;
// listen on server address
builder.AddListeningPort(server_address, grpc::InsecureServerCredentials());
// Register as synchronous service
builder.RegisterService(&service);
// assemble server to receive requests from command line
std::unique_ptr<Server> server(builder.BuildAndStart());
std::cout << "Server listening on " << server_address << std::endl;
LOG(INFO) << "Server listening on " << server_address << std::endl;
// Keep running until shutdown signal received
server->Wait();
}
int main(int argc, char** argv) {
// initialize glog
google::InitGoogleLogging(argv[0]);
gflags::ParseCommandLineFlags(&argc, &argv, true);
// run service layer server to receive requests from command line
run();
return 0;
}