Subversion Repositories SmartDukaan

Rev

Rev 447 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
434 ashish 1
'''
2
Created on 17-Aug-2010
3
 
4
@author: ashish
5
'''
6
from shop2020.thriftpy.model.v1.order import TransactionService
7
from thrift.protocol.TBinaryProtocol import TBinaryProtocol
8
from thrift.transport.TTransport import TFramedTransport
9
from thrift.transport.TSocket import TSocket
10
from shop2020.utils.Utils import log_entry
11
from shop2020.config.client.ConfigClient import ConfigClient
12
 
13
class TransactionClient:
14
 
15
    host = "localhost"
16
    port = "9003"
17
 
18
    def __init__(self):
19
        try:
20
            self.config_client = ConfigClient()
21
            self.host = self.config_client.get_property("transaction_service_hostname")
22
            self.host = self.config_client.get_property("transaction_service_port")
23
            self.__start__()
24
        except:
25
            log_entry("error getting data from config")
26
 
27
    def __start__(self):
28
        self.transport = TSocket(self.host, self.port)
29
        self.transport = TFramedTransport(self.transport)
30
        self.protocol = TBinaryProtocol(self.transport)    
31
        self.client = TransactionService.Client(self.protocol)
32
        self.transport.open()
33
 
34
    def get_client(self):
35
        if self.transport.isOpen():
36
            return self.client
37
        self.transport.open()
38
        return self.client