Subversion Repositories SmartDukaan

Rev

Rev 2885 | Rev 4619 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
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
 
28
	public static void main(String[] args){
29
		try{
30
			handler = new PaymentServiceHandler();
3428 rajveer 31
			processor = new Processor<Iface>(handler);
32
 
1946 chandransh 33
 
2885 chandransh 34
			int port = 9012;
35
			try {
36
			    String portNo = ConfigClient.getClient().get(ConfigClientKeys.payments_service_server_port.toString());
37
			    port = Integer.parseInt(portNo);
38
			}catch(Exception e){
39
			    logger.warn("Unable to get port number from the Config server because of:", e);
40
			}
41
 
42
			TServerTransport serverTransport = new TServerSocket(port);
1946 chandransh 43
			TTransportFactory tFactory = new TFramedTransport.Factory();
44
			TProtocolFactory pFactory = new TBinaryProtocol.Factory();
45
 
3428 rajveer 46
			Args serverParams = new Args(serverTransport);
47
			serverParams.processor(processor);
48
			serverParams.transportFactory(tFactory);
49
			serverParams.protocolFactory(pFactory);
50
			TServer server = new TThreadPoolServer(serverParams);
51
 
1953 chandransh 52
			logger.info("Payment service started on port 9012");
1946 chandransh 53
			server.serve();
54
		}catch(Exception ex){
55
			ex.printStackTrace();
56
		}
57
	}
58
}