Subversion Repositories SmartDukaan

Rev

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

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