Subversion Repositories SmartDukaan

Rev

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

Rev Author Line No. Line
1986 varun.gupt 1
package in.shop2020.thrift.clients;
2
 
3
import javax.annotation.PostConstruct;
4
import javax.annotation.PreDestroy;
5
 
6
import org.apache.thrift.transport.TTransportException;
7
 
8
import in.shop2020.model.v1.user.PromotionService.Client;
9
import in.shop2020.utils.ConfigClientKeys;
10
import in.shop2020.utils.Logger;
11
 
12
public class PromotionServiceClient extends GenericServiceClient {
13
 
14
    private Client client = null;
15
 
16
    public PromotionServiceClient(String clientIdentifier, String hostConfigKey, String portConfigKey) throws Exception {
17
        super(clientIdentifier, hostConfigKey, portConfigKey);
18
 
19
        client = new Client(protocol);
20
    }
21
 
22
    public PromotionServiceClient() throws Exception{
23
        this(PromotionServiceClient.class.getSimpleName(), ConfigClientKeys.promotion_service_server_host.toString(), ConfigClientKeys.promotion_service_server_port.toString());
24
        if(transport.isOpen()){
25
            Logger.log("Transport was already open", this);
26
        }
27
        try {
28
            transport.open();
29
        } catch (TTransportException e) {
30
            Logger.log("Encountered exception while open transport " + e, this);
31
        }
32
 
33
    }
34
    @PostConstruct
35
    private void openTransport(){
36
        if(transport.isOpen()){
37
            Logger.log("Transport was already open", this);
38
        }
39
        try {
40
            transport.open();
41
        } catch (TTransportException e) {
42
            Logger.log("Encountered exception while open transport " + e, this);
43
        }
44
    }
45
 
46
    @PreDestroy
47
    private void closeTransport(){
48
        if(transport != null && transport.isOpen()){
49
            Logger.log("Closing transport :", this);
50
            transport.close();
51
        }
52
    }
53
 
54
    public Client getClient(){
55
        return client;
56
    }
57
 
58
    @Override
59
    public void closeSession() {
60
        try {
61
            client.closeSession();
62
        } catch (Exception e) {
63
            e.printStackTrace();
64
        }
65
    }
66
}