| 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 |
|
|
|
15 |
import in.shop2020.payment.service.handler.PaymentServiceHandler;
|
| 3428 |
rajveer |
16 |
import in.shop2020.payments.PaymentService.Iface;
|
| 1946 |
chandransh |
17 |
import in.shop2020.payments.PaymentService.Processor;
|
| 2885 |
chandransh |
18 |
import in.shop2020.thrift.clients.config.ConfigClient;
|
|
|
19 |
import in.shop2020.utils.ConfigClientKeys;
|
| 1946 |
chandransh |
20 |
|
|
|
21 |
public class PaymentServer {
|
| 1953 |
chandransh |
22 |
private static Logger logger = LoggerFactory.getLogger(PaymentServer.class);
|
|
|
23 |
|
| 1946 |
chandransh |
24 |
private static PaymentServiceHandler handler;
|
|
|
25 |
|
| 3428 |
rajveer |
26 |
private static Processor<Iface> processor;
|
| 1946 |
chandransh |
27 |
|
| 4619 |
mandeep.dh |
28 |
public static String dbHost;
|
|
|
29 |
|
| 1946 |
chandransh |
30 |
public static void main(String[] args){
|
|
|
31 |
try{
|
| 2885 |
chandransh |
32 |
int port = 9012;
|
|
|
33 |
try {
|
| 4619 |
mandeep.dh |
34 |
dbHost = "jdbc:mysql://" + ConfigClient.getClient().get(ConfigClientKeys.payments_service_db_hostname.toString()) + "/payment";
|
| 2885 |
chandransh |
35 |
String portNo = ConfigClient.getClient().get(ConfigClientKeys.payments_service_server_port.toString());
|
|
|
36 |
port = Integer.parseInt(portNo);
|
|
|
37 |
}catch(Exception e){
|
|
|
38 |
logger.warn("Unable to get port number from the Config server because of:", e);
|
|
|
39 |
}
|
| 4619 |
mandeep.dh |
40 |
|
|
|
41 |
// Setting dbHost env property to make this value accessible in context.xml
|
|
|
42 |
// while spring context creation.
|
|
|
43 |
System.setProperty("dbHost", dbHost);
|
| 4644 |
rajveer |
44 |
|
|
|
45 |
|
| 4619 |
mandeep.dh |
46 |
handler = new PaymentServiceHandler();
|
|
|
47 |
processor = new Processor<Iface>(handler);
|
|
|
48 |
|
| 4644 |
rajveer |
49 |
//TODO Remove these three lines
|
|
|
50 |
logger.info("DB Connection String is: " + dbHost);
|
|
|
51 |
org.apache.commons.dbcp.BasicDataSource ds = (org.apache.commons.dbcp.BasicDataSource)handler.context.getBean("dataSource");
|
|
|
52 |
logger.info("URL read by data source is: " + ds.getUrl());
|
|
|
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);
|
|
|
62 |
TServer server = new TThreadPoolServer(serverParams);
|
|
|
63 |
|
| 1953 |
chandransh |
64 |
logger.info("Payment service started on port 9012");
|
| 1946 |
chandransh |
65 |
server.serve();
|
|
|
66 |
}catch(Exception ex){
|
|
|
67 |
ex.printStackTrace();
|
|
|
68 |
}
|
|
|
69 |
}
|
|
|
70 |
}
|