Subversion Repositories SmartDukaan

Rev

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

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