Subversion Repositories SmartDukaan

Rev

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

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