Subversion Repositories SmartDukaan

Rev

Rev 2821 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2821 Rev 3123
Line 1... Line 1...
1
package in.shop2020.thrift.clients;
1
package in.shop2020.thrift.clients;
2
 
2
 
3
import in.shop2020.utils.ConfigClientKeys;
-
 
4
import in.shop2020.utils.Logger;
-
 
5
import in.shop2020.warehouse.WarehouseService.Client;
3
import in.shop2020.warehouse.WarehouseService.Client;
-
 
4
import in.shop2020.utils.ConfigClientKeys;
6
 
5
 
7
import javax.annotation.PostConstruct;
-
 
8
import javax.annotation.PreDestroy;
-
 
9
 
-
 
10
import org.apache.thrift.TException;
-
 
11
import org.apache.thrift.transport.TTransportException;
6
import org.apache.thrift.transport.TTransportException;
12
 
7
 
13
public class WarehouseServiceClient extends GenericServiceClient {
8
public class WarehouseClient extends GenericClient{
-
 
9
 
-
 
10
	private Client client = null;
-
 
11
 
-
 
12
	/**
-
 
13
	 * 
-
 
14
	 * @throws TTransportException
-
 
15
	 */
-
 
16
	public WarehouseClient() throws TTransportException{
-
 
17
		this(ConfigClientKeys.warehouse_service_server_host.toString(), ConfigClientKeys.warehouse_service_server_port.toString());
-
 
18
	}
-
 
19
 
-
 
20
	/**
-
 
21
	 * get the client for given hostkey and portkey
-
 
22
	 * @param hostConfigKey
-
 
23
	 * @param portConfigKey
-
 
24
	 * @throws TTransportException
-
 
25
	 */
-
 
26
	public WarehouseClient(String hostConfigKey, String portConfigKey) throws TTransportException{
-
 
27
		super(hostConfigKey, portConfigKey);
-
 
28
		client = new Client(protocol);
-
 
29
	}
-
 
30
	
-
 
31
 
-
 
32
	/**
-
 
33
	 * Get the client
-
 
34
	 * @return
-
 
35
	 */
-
 
36
	public Client getClient(){
-
 
37
		return client;
-
 
38
	}
-
 
39
	
-
 
40
	@Override
-
 
41
	public void closeSession() {
-
 
42
		return;
-
 
43
	}
14
 
44
 
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
}
45
}