| 1946 |
chandransh |
1 |
package in.shop2020.payment.service;
|
|
|
2 |
|
|
|
3 |
import org.apache.thrift.protocol.TBinaryProtocol;
|
|
|
4 |
import org.apache.thrift.protocol.TProtocolFactory;
|
|
|
5 |
import org.apache.thrift.server.TServer;
|
|
|
6 |
import org.apache.thrift.server.TThreadPoolServer;
|
| 3428 |
rajveer |
7 |
import org.apache.thrift.server.TThreadPoolServer.Args;
|
| 1946 |
chandransh |
8 |
import org.apache.thrift.transport.TFramedTransport;
|
|
|
9 |
import org.apache.thrift.transport.TServerSocket;
|
|
|
10 |
import org.apache.thrift.transport.TServerTransport;
|
|
|
11 |
import org.apache.thrift.transport.TTransportFactory;
|
| 1953 |
chandransh |
12 |
import org.slf4j.Logger;
|
|
|
13 |
import org.slf4j.LoggerFactory;
|
| 1946 |
chandransh |
14 |
|
| 4718 |
anupam.sin |
15 |
import org.apache.commons.daemon.Daemon;
|
|
|
16 |
import org.apache.commons.daemon.DaemonContext;
|
|
|
17 |
|
| 1946 |
chandransh |
18 |
import in.shop2020.payment.service.handler.PaymentServiceHandler;
|
| 3428 |
rajveer |
19 |
import in.shop2020.payments.PaymentService.Iface;
|
| 1946 |
chandransh |
20 |
import in.shop2020.payments.PaymentService.Processor;
|
| 2885 |
chandransh |
21 |
import in.shop2020.thrift.clients.config.ConfigClient;
|
|
|
22 |
import in.shop2020.utils.ConfigClientKeys;
|
| 1946 |
chandransh |
23 |
|
| 4718 |
anupam.sin |
24 |
public class PaymentServer implements Daemon {
|
| 1953 |
chandransh |
25 |
private static Logger logger = LoggerFactory.getLogger(PaymentServer.class);
|
|
|
26 |
|
| 1946 |
chandransh |
27 |
private static PaymentServiceHandler handler;
|
|
|
28 |
|
| 3428 |
rajveer |
29 |
private static Processor<Iface> processor;
|
| 1946 |
chandransh |
30 |
|
| 4619 |
mandeep.dh |
31 |
public static String dbHost;
|
|
|
32 |
|
| 4718 |
anupam.sin |
33 |
private static TServer server;
|
|
|
34 |
|
|
|
35 |
public static void main(String[] args) {
|
|
|
36 |
initialize();
|
|
|
37 |
}
|
|
|
38 |
|
|
|
39 |
private static void initialize() {
|
| 1946 |
chandransh |
40 |
try{
|
| 4644 |
rajveer |
41 |
|
| 4651 |
rajveer |
42 |
dbHost = "jdbc:mysql://" + ConfigClient.getClient().get(ConfigClientKeys.payments_service_db_hostname.toString()) + "/payment";
|
|
|
43 |
String portNo = ConfigClient.getClient().get(ConfigClientKeys.payments_service_server_port.toString());
|
|
|
44 |
int port = Integer.parseInt(portNo);
|
|
|
45 |
|
| 4619 |
mandeep.dh |
46 |
handler = new PaymentServiceHandler();
|
|
|
47 |
processor = new Processor<Iface>(handler);
|
|
|
48 |
|
| 4644 |
rajveer |
49 |
logger.info("DB Connection String is: " + dbHost);
|
| 4651 |
rajveer |
50 |
logger.info("URL read by data source before setting is: " + handler.getDataSourceUrl());
|
|
|
51 |
handler.setDataSourceUrl(dbHost);
|
|
|
52 |
logger.info("URL read by data source after setting is: " + handler.getDataSourceUrl());
|
| 4644 |
rajveer |
53 |
|
| 2885 |
chandransh |
54 |
TServerTransport serverTransport = new TServerSocket(port);
|
| 1946 |
chandransh |
55 |
TTransportFactory tFactory = new TFramedTransport.Factory();
|
|
|
56 |
TProtocolFactory pFactory = new TBinaryProtocol.Factory();
|
|
|
57 |
|
| 3428 |
rajveer |
58 |
Args serverParams = new Args(serverTransport);
|
|
|
59 |
serverParams.processor(processor);
|
|
|
60 |
serverParams.transportFactory(tFactory);
|
|
|
61 |
serverParams.protocolFactory(pFactory);
|
| 4718 |
anupam.sin |
62 |
server = new TThreadPoolServer(serverParams);
|
| 3428 |
rajveer |
63 |
|
| 1953 |
chandransh |
64 |
logger.info("Payment service started on port 9012");
|
| 1946 |
chandransh |
65 |
server.serve();
|
|
|
66 |
}catch(Exception ex){
|
| 4651 |
rajveer |
67 |
logger.error("Unable to get port number from the Config server because of:", ex);
|
| 1946 |
chandransh |
68 |
}
|
|
|
69 |
}
|
| 4718 |
anupam.sin |
70 |
|
|
|
71 |
public void destroy() {
|
| 4728 |
anupam.sin |
72 |
logger.info("Payment Server stopped.");
|
| 4718 |
anupam.sin |
73 |
// TODO Auto-generated method stub
|
|
|
74 |
|
|
|
75 |
}
|
|
|
76 |
|
|
|
77 |
public void init(DaemonContext dc) throws Exception {
|
| 4728 |
anupam.sin |
78 |
logger.info("Initializing Payment Server...");
|
| 4718 |
anupam.sin |
79 |
// TODO Auto-generated method stub
|
|
|
80 |
|
|
|
81 |
}
|
|
|
82 |
|
|
|
83 |
public void start() throws Exception {
|
| 4728 |
anupam.sin |
84 |
logger.info("Starting Payment Server");
|
| 4718 |
anupam.sin |
85 |
initialize();
|
|
|
86 |
// TODO Auto-generated method stub
|
|
|
87 |
|
|
|
88 |
}
|
|
|
89 |
|
|
|
90 |
public void stop() throws Exception {
|
| 4728 |
anupam.sin |
91 |
logger.info("Stopping Payment Server...");
|
| 4718 |
anupam.sin |
92 |
server.stop();
|
|
|
93 |
System.exit(0);
|
|
|
94 |
// TODO Auto-generated method stub
|
|
|
95 |
|
|
|
96 |
}
|
| 1946 |
chandransh |
97 |
}
|