Subversion Repositories SmartDukaan

Rev

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

Rev 1360 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;
-
 
4
import javax.annotation.PreDestroy;
-
 
5
 
-
 
6
import org.apache.thrift.TException;
-
 
7
import org.apache.thrift.transport.TTransportException;
-
 
8
 
3
 
9
import in.shop2020.model.v1.order.TransactionService.Client;
4
import in.shop2020.model.v1.order.TransactionService.Client;
10
import in.shop2020.utils.ConfigClientKeys;
5
import in.shop2020.utils.ConfigClientKeys;
11
import in.shop2020.utils.Logger;
-
 
12
 
6
 
-
 
7
import org.apache.thrift.TException;
-
 
8
import org.apache.thrift.transport.TTransportException;
-
 
9
 
13
public class TransactionServiceClient extends GenericServiceClient{
10
public class TransactionClient extends GenericClient{
14
 
11
 
15
	private Client client = null;
12
	private Client client = null;
16
	
13
 
17
	public TransactionServiceClient(String clientIdentifier,
-
 
18
			String hostConfigKey, String portConfigKey) throws Exception {
-
 
19
		super(clientIdentifier, hostConfigKey, portConfigKey);
-
 
20
		client = new Client(protocol);
-
 
21
		
14
	/**
22
	}
15
	 * 
-
 
16
	 * @throws TTransportException
23
	
17
	 */
24
	public TransactionServiceClient()throws Exception{
18
	public TransactionClient() throws TTransportException{
25
		this(TransactionServiceClient.class.getSimpleName(), ConfigClientKeys.transaction_service_server_host.toString(), ConfigClientKeys.transaction_service_server_port.toString());
19
		this(ConfigClientKeys.transaction_service_server_host.toString(), ConfigClientKeys.transaction_service_server_port.toString());
26
		if(transport.isOpen()){
-
 
27
			Logger.log("Transport was already open", this);
-
 
28
		}
-
 
29
		try {
-
 
30
			transport.open();
-
 
31
		} catch (TTransportException e) {
-
 
32
			Logger.log("Encountered exception while open transport "+ e, this);
-
 
33
		}
-
 
34
	}
20
	}
35
	
21
 
36
	@PostConstruct
22
	/**
37
	private void openTransport(){
23
	 * get the client for given hostkey and portkey
-
 
24
	 * @param hostConfigKey
38
		if(transport.isOpen()){
25
	 * @param portConfigKey
39
			Logger.log("Transport was already open", this);
26
	 * @throws TTransportException
40
		}
27
	 */
41
		try {
-
 
42
			transport.open();
28
	public TransactionClient(String hostConfigKey, String portConfigKey) throws TTransportException{
43
		} catch (TTransportException e) {
29
		super(hostConfigKey, portConfigKey);
44
			Logger.log("Encountered exception while open transport "+ e, this);
30
		client = new Client(protocol);
45
		}
-
 
46
	}
31
	}
47
	
32
	
-
 
33
 
48
	//Api methods
34
	/**
49
	//TODO: Add logging to this class.
35
	 * Get the client
-
 
36
	 * @return
50
	
37
	 */
51
	public Client getClient(){
38
	public Client getClient(){
52
		return client;
39
		return client;
53
	}
40
	}
54
	
41
	
55
	@PreDestroy
-
 
56
	private void closeTransport(){
-
 
57
		if(transport != null && transport.isOpen()){
-
 
58
			Logger.log("Closing transport :", this);
-
 
59
			transport.close();
-
 
60
		}
-
 
61
	}
-
 
62
	
-
 
63
	@Override
42
	@Override
64
	public void closeSession() {
43
	public void closeSession() {
65
		try {
44
		try {
66
			client.closeSession();
45
			client.closeSession();
67
		} catch (TException e) {
46
		} catch (TException e) {
68
			e.printStackTrace();
47
			e.printStackTrace();
69
		}
48
		}
70
	}
49
	}
-
 
50
 
71
}
51
}