Subversion Repositories SmartDukaan

Rev

Rev 4646 | Rev 4718 | 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
 
4619 mandeep.dh 28
	public static String dbHost;
29
 
1946 chandransh 30
	public static void main(String[] args){
31
		try{
4644 rajveer 32
 
4651 rajveer 33
		    dbHost = "jdbc:mysql://" + ConfigClient.getClient().get(ConfigClientKeys.payments_service_db_hostname.toString()) + "/payment";
34
		    String portNo = ConfigClient.getClient().get(ConfigClientKeys.payments_service_server_port.toString());
35
		    int port = Integer.parseInt(portNo);
36
 
4619 mandeep.dh 37
	        handler = new PaymentServiceHandler();
38
	        processor = new Processor<Iface>(handler);
39
 
4644 rajveer 40
	        logger.info("DB Connection String is: " + dbHost);
4651 rajveer 41
	        logger.info("URL read by data source before setting is: " + handler.getDataSourceUrl());
42
	        handler.setDataSourceUrl(dbHost);
43
	        logger.info("URL read by data source after setting is: " + handler.getDataSourceUrl());
4644 rajveer 44
 
2885 chandransh 45
			TServerTransport serverTransport = new TServerSocket(port);
1946 chandransh 46
			TTransportFactory tFactory = new TFramedTransport.Factory();
47
			TProtocolFactory pFactory = new TBinaryProtocol.Factory();
48
 
3428 rajveer 49
			Args serverParams = new Args(serverTransport);
50
			serverParams.processor(processor);
51
			serverParams.transportFactory(tFactory);
52
			serverParams.protocolFactory(pFactory);
53
			TServer server = new TThreadPoolServer(serverParams);
54
 
1953 chandransh 55
			logger.info("Payment service started on port 9012");
1946 chandransh 56
			server.serve();
57
		}catch(Exception ex){
4651 rajveer 58
			logger.error("Unable to get port number from the Config server because of:", ex);
1946 chandransh 59
		}
60
	}
61
}