Subversion Repositories SmartDukaan

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
3093 mandeep.dh 1
/**
2
 * 
3
 */
4
package in.shop2020.thrift.clients;
5
 
6
import in.shop2020.crm.CRMService.Client;
7
import in.shop2020.utils.ConfigClientKeys;
8
import in.shop2020.utils.Logger;
9
 
10
import javax.annotation.PostConstruct;
11
import javax.annotation.PreDestroy;
12
 
13
import org.apache.thrift.transport.TTransportException;
14
 
15
/**
16
 * @author mandeep
17
 * 
18
 */
19
public class CRMServiceClient extends GenericServiceClient {
20
 
21
    private Client client;
22
 
23
    public CRMServiceClient(String clientIdentifier, String hostConfigKey,
24
            String portConfigKey) throws Exception {
25
        super(clientIdentifier, hostConfigKey, portConfigKey);
26
        client = new Client(protocol);
27
    }
28
 
29
    public CRMServiceClient() throws Exception {
30
        this(CRMServiceClient.class.getSimpleName(),
31
                ConfigClientKeys.crm_service_server_host.name(),
32
                ConfigClientKeys.crm_service_server_port.name());
33
 
34
        if (transport.isOpen()) {
35
            Logger.log("Transport was already open", this);
36
        }
37
        try {
38
            transport.open();
39
            Logger.log("Transport opened", this);
40
        } catch (TTransportException e) {
41
            Logger.log("Encountered exception while opening transport: ", e);
42
        }
43
    }
44
 
45
    @PostConstruct
46
    private void openTransport() {
47
        if (transport.isOpen()) {
48
            Logger.log("Transport was already open", this);
49
        }
50
        try {
51
            transport.open();
52
        } catch (TTransportException e) {
53
            Logger.log("Encountered exception while open transport " + e, this);
54
        }
55
    }
56
 
57
    @PreDestroy
58
    private void closeTransport() {
59
        if (transport != null && transport.isOpen()) {
60
            Logger.log("Closing transport :", this);
61
            transport.close();
62
        }
63
    }
64
 
65
    public Client getClient() {
66
        return client;
67
    }
68
 
69
    /*
70
     * (non-Javadoc)
71
     * 
72
     * @see in.shop2020.thrift.clients.GenericServiceClient#closeSession()
73
     */
74
    @Override
75
    public void closeSession() {
76
        // TODO Auto-generated method stub
77
 
78
    }
79
}