| 3024 |
mandeep.dh |
1 |
/**
|
|
|
2 |
*
|
|
|
3 |
*/
|
|
|
4 |
package in.shop2020.crm.service;
|
|
|
5 |
|
| 3428 |
rajveer |
6 |
import in.shop2020.crm.CRMService.Iface;
|
| 3024 |
mandeep.dh |
7 |
import in.shop2020.crm.CRMService.Processor;
|
|
|
8 |
import in.shop2020.crm.service.handler.CRMServiceHandler;
|
|
|
9 |
import in.shop2020.thrift.clients.config.ConfigClient;
|
|
|
10 |
import in.shop2020.utils.ConfigClientKeys;
|
|
|
11 |
|
| 4718 |
anupam.sin |
12 |
import org.apache.commons.daemon.Daemon;
|
|
|
13 |
import org.apache.commons.daemon.DaemonContext;
|
| 3024 |
mandeep.dh |
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;
|
| 3428 |
rajveer |
18 |
import org.apache.thrift.server.TThreadPoolServer.Args;
|
| 3024 |
mandeep.dh |
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 |
import org.slf4j.Logger;
|
|
|
24 |
import org.slf4j.LoggerFactory;
|
|
|
25 |
|
|
|
26 |
/**
|
|
|
27 |
* Service for accessing all necessary data relevant for CRM tool.
|
|
|
28 |
* Example tickets, activities, agents etc.
|
|
|
29 |
*
|
|
|
30 |
* @author mandeep
|
|
|
31 |
*/
|
| 4718 |
anupam.sin |
32 |
public class CRMServer implements Daemon {
|
| 3024 |
mandeep.dh |
33 |
private static Logger logger = LoggerFactory.getLogger(CRMServer.class);
|
|
|
34 |
|
|
|
35 |
private static CRMServiceHandler handler;
|
|
|
36 |
|
| 3428 |
rajveer |
37 |
private static Processor<Iface> processor;
|
| 4718 |
anupam.sin |
38 |
|
|
|
39 |
private static TServer server;
|
|
|
40 |
|
|
|
41 |
public static void main(String[] args) {
|
|
|
42 |
initialize();
|
|
|
43 |
}
|
| 3024 |
mandeep.dh |
44 |
|
| 4718 |
anupam.sin |
45 |
private static void initialize() {
|
| 3024 |
mandeep.dh |
46 |
try {
|
|
|
47 |
handler = new CRMServiceHandler();
|
| 3428 |
rajveer |
48 |
processor = new Processor<Iface>(handler);
|
| 3024 |
mandeep.dh |
49 |
int port = 9014;
|
|
|
50 |
try {
|
|
|
51 |
String portNo = ConfigClient.getClient().get(
|
|
|
52 |
ConfigClientKeys.crm_service_server_port
|
|
|
53 |
.toString());
|
|
|
54 |
port = Integer.parseInt(portNo);
|
|
|
55 |
} catch (Exception e) {
|
|
|
56 |
logger.warn(
|
|
|
57 |
"Unable to get port number from the Config server because of:",
|
|
|
58 |
e);
|
|
|
59 |
}
|
|
|
60 |
|
|
|
61 |
TServerTransport serverTransport = new TServerSocket(port);
|
|
|
62 |
TTransportFactory tFactory = new TFramedTransport.Factory();
|
|
|
63 |
TProtocolFactory pFactory = new TBinaryProtocol.Factory();
|
| 3428 |
rajveer |
64 |
|
|
|
65 |
Args serverParams = new Args(serverTransport);
|
|
|
66 |
serverParams.processor(processor);
|
|
|
67 |
serverParams.transportFactory(tFactory);
|
|
|
68 |
serverParams.protocolFactory(pFactory);
|
|
|
69 |
|
| 4718 |
anupam.sin |
70 |
server = new TThreadPoolServer(serverParams);
|
| 3024 |
mandeep.dh |
71 |
|
|
|
72 |
logger.info("CRM service started on port 9014");
|
|
|
73 |
server.serve();
|
|
|
74 |
} catch (Exception ex) {
|
| 3853 |
mandeep.dh |
75 |
logger.error("Error starting server", ex);
|
| 3024 |
mandeep.dh |
76 |
}
|
|
|
77 |
}
|
| 4718 |
anupam.sin |
78 |
|
|
|
79 |
public void destroy() {
|
|
|
80 |
System.out.println("CRMServer stopped.");
|
|
|
81 |
// TODO Auto-generated method stub
|
|
|
82 |
|
|
|
83 |
}
|
|
|
84 |
|
|
|
85 |
public void init(DaemonContext dc) throws Exception {
|
|
|
86 |
System.out.println("Initializing CRMServer...");
|
|
|
87 |
// TODO Auto-generated method stub
|
|
|
88 |
|
|
|
89 |
}
|
|
|
90 |
|
|
|
91 |
public void start() throws Exception {
|
|
|
92 |
System.out.println("Starting CRM");
|
|
|
93 |
initialize();
|
|
|
94 |
// TODO Auto-generated method stub
|
|
|
95 |
|
|
|
96 |
}
|
|
|
97 |
|
|
|
98 |
public void stop() throws Exception {
|
|
|
99 |
System.out.println("Stopping CRMServer...");
|
|
|
100 |
server.stop();
|
|
|
101 |
System.exit(0);
|
|
|
102 |
// TODO Auto-generated method stub
|
|
|
103 |
|
|
|
104 |
}
|
|
|
105 |
}
|