Subversion Repositories SmartDukaan

Rev

Details | Last modification | View Log | RSS feed

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