Line data Source code
1 : #include <signal.h>
2 : #include <thrift/protocol/TBinaryProtocol.h>
3 : #include <thrift/server/TThreadedServer.h>
4 : #include <thrift/transport/TBufferTransports.h>
5 : #include <thrift/transport/TServerSocket.h>
6 :
7 : #include "../utils.h"
8 : #include "../utils_thrift.h"
9 : #include "TextHandler.h"
10 :
11 : extern "C" void __gcov_flush();
12 :
13 : using apache::thrift::protocol::TBinaryProtocolFactory;
14 : using apache::thrift::server::TThreadedServer;
15 : using apache::thrift::transport::TFramedTransportFactory;
16 : using apache::thrift::transport::TServerSocket;
17 : using namespace social_network;
18 :
19 0 : void sigintHandler(int sig) { exit(EXIT_SUCCESS); }
20 :
21 1 : void handle_sigusr1(int signum) {
22 1 : __gcov_flush();
23 0 : }
24 :
25 1 : int main(int argc, char *argv[]) {
26 1 : signal(SIGINT, sigintHandler);
27 1 : signal(SIGUSR1, handle_sigusr1);
28 1 : init_logger();
29 1 : SetUpTracer("config/jaeger-config.yml", "text-service");
30 :
31 1 : json config_json;
32 1 : if (load_config_file("config/service-config.json", &config_json) == 0) {
33 1 : int port = config_json["text-service"]["port"];
34 :
35 1 : std::string url_addr = config_json["url-shorten-service"]["addr"];
36 1 : int url_port = config_json["url-shorten-service"]["port"];
37 1 : int url_conns = config_json["url-shorten-service"]["connections"];
38 1 : int url_timeout = config_json["url-shorten-service"]["timeout_ms"];
39 1 : int url_keepalive = config_json["url-shorten-service"]["keepalive_ms"];
40 :
41 1 : std::string user_mention_addr = config_json["user-mention-service"]["addr"];
42 1 : int user_mention_port = config_json["user-mention-service"]["port"];
43 1 : int user_mention_conns = config_json["user-mention-service"]["connections"];
44 : int user_mention_timeout =
45 1 : config_json["user-mention-service"]["timeout_ms"];
46 : int user_mention_keepalive =
47 1 : config_json["user-mention-service"]["keepalive_ms"];
48 :
49 : ClientPool<ThriftClient<UrlShortenServiceClient>> url_client_pool(
50 : "url-shorten-service", url_addr, url_port, 0, url_conns, url_timeout,
51 1 : url_keepalive, config_json);
52 :
53 : ClientPool<ThriftClient<UserMentionServiceClient>> user_mention_pool(
54 : "user-mention-service", user_mention_addr, user_mention_port, 0,
55 1 : user_mention_conns, user_mention_timeout, user_mention_keepalive, config_json);
56 :
57 1 : std::shared_ptr<TServerSocket> server_socket = get_server_socket(config_json, "0.0.0.0", port);
58 : TThreadedServer server(
59 2 : std::make_shared<TextServiceProcessor>(std::make_shared<TextHandler>(
60 : &url_client_pool, &user_mention_pool)),
61 : server_socket,
62 2 : std::make_shared<TFramedTransportFactory>(),
63 6 : std::make_shared<TBinaryProtocolFactory>());
64 :
65 2 : LOG(info) << "Starting the text-service server...";
66 1 : server.serve();
67 : } else
68 0 : exit(EXIT_FAILURE);
69 3 : }
|