| 4500 |
mandeep.dh |
1 |
/**
|
|
|
2 |
*
|
|
|
3 |
*/
|
|
|
4 |
package in.shop2020.warehouse.service;
|
|
|
5 |
|
|
|
6 |
import in.shop2020.thrift.clients.config.ConfigClient;
|
|
|
7 |
import in.shop2020.utils.ConfigClientKeys;
|
|
|
8 |
import in.shop2020.warehouse.WarehouseService.Iface;
|
|
|
9 |
import in.shop2020.warehouse.WarehouseService.Processor;
|
|
|
10 |
import in.shop2020.warehouse.service.handler.WarehouseServiceHandler;
|
|
|
11 |
|
|
|
12 |
import org.apache.commons.logging.Log;
|
|
|
13 |
import org.apache.commons.logging.LogFactory;
|
|
|
14 |
import org.apache.thrift.protocol.TBinaryProtocol;
|
|
|
15 |
import org.apache.thrift.protocol.TProtocolFactory;
|
|
|
16 |
import org.apache.thrift.server.TServer;
|
|
|
17 |
import org.apache.thrift.server.TThreadPoolServer;
|
|
|
18 |
import org.apache.thrift.server.TThreadPoolServer.Args;
|
|
|
19 |
import org.apache.thrift.transport.TFramedTransport;
|
|
|
20 |
import org.apache.thrift.transport.TServerSocket;
|
|
|
21 |
import org.apache.thrift.transport.TServerTransport;
|
|
|
22 |
import org.apache.thrift.transport.TTransportFactory;
|
|
|
23 |
|
|
|
24 |
/**
|
|
|
25 |
* @author mandeep
|
|
|
26 |
*
|
|
|
27 |
*/
|
|
|
28 |
public class WarehouseServer {
|
|
|
29 |
private static Log log = LogFactory.getLog(WarehouseServer.class);
|
|
|
30 |
|
|
|
31 |
private static WarehouseServiceHandler handler;
|
|
|
32 |
|
|
|
33 |
private static Processor<Iface> processor;
|
|
|
34 |
|
|
|
35 |
public static void main(String[] args){
|
|
|
36 |
try {
|
|
|
37 |
handler = new WarehouseServiceHandler();
|
|
|
38 |
processor = new Processor<Iface>(handler);
|
|
|
39 |
|
| 4574 |
mandeep.dh |
40 |
int port = 9013;
|
| 4500 |
mandeep.dh |
41 |
try {
|
|
|
42 |
String portNo = ConfigClient.getClient().get(ConfigClientKeys.warehouse_service_server_port.toString());
|
|
|
43 |
port = Integer.parseInt(portNo);
|
|
|
44 |
} catch(Exception e) {
|
|
|
45 |
log.warn("Unable to get port number from the Config server because of:", e);
|
|
|
46 |
}
|
|
|
47 |
|
|
|
48 |
TServerTransport serverTransport = new TServerSocket(port);
|
|
|
49 |
TTransportFactory tFactory = new TFramedTransport.Factory();
|
|
|
50 |
TProtocolFactory pFactory = new TBinaryProtocol.Factory();
|
|
|
51 |
|
|
|
52 |
Args serverParams = new Args(serverTransport);
|
|
|
53 |
serverParams.processor(processor);
|
|
|
54 |
serverParams.transportFactory(tFactory);
|
|
|
55 |
serverParams.protocolFactory(pFactory);
|
|
|
56 |
TServer server = new TThreadPoolServer(serverParams);
|
|
|
57 |
|
|
|
58 |
log.info("Warehouse service started on port " + port);
|
|
|
59 |
server.serve();
|
|
|
60 |
}catch(Exception ex){
|
|
|
61 |
ex.printStackTrace();
|
|
|
62 |
}
|
|
|
63 |
}
|
|
|
64 |
}
|