Subversion Repositories SmartDukaan

Rev

Rev 2283 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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