Exemplo n.º 1
0
 def connect(self):
     self.socket = TSocket.TSocket(self.host, self.port)
     if self.timeout:
         self.socket.setTimeout(self.timeout)
     if self.use_plain_sasl:
         self.transport = SaslClientTransport(self.host, self.socket, service=STORM_SASL_SERVICE, mechanism='PLAIN')
     else:    
         self.transport = TTransport.TFramedTransport(self.socket)
     self.protocol = TBinaryProtocol.TBinaryProtocol(self.transport)
     self.transport.open()
     self.client = Client(self.protocol)
Exemplo n.º 2
0
class DRPCClient:
    def __init__(self, host, port=3772, timeout=None, reconnect=False):
        self.host = host
        self.port = port
        self.timeout = timeout
        self.reconnect = reconnect
        if not reconnect:
            self.connect()

    def connect(self):
        self.socket = TSocket.TSocket(self.host, self.port)
        if self.timeout:
            self.socket.setTimeout(self.timeout)
        self.transport = TTransport.TFramedTransport(self.socket)
        self.protocol = TBinaryProtocol.TBinaryProtocol(self.transport)
        self.transport.open()
        self.client = Client(self.protocol)

    def execute(self, func, args):
        if self.reconnect:
            self.connect()
        r = json.loads(self.client.execute(func, args))
        if self.reconnect:
            self.close()
        return r

    def executeJSON(self, func, **kwargs):
        return self.execute(func, json.dumps(kwargs))

    def close(self):
        self.transport.close()
Exemplo n.º 3
0
class DRPCClient:
    def __init__(self, host, port=3772, timeout=None, reconnect=False, use_plain_sasl=False):
        self.host = host
        self.port = port
        self.timeout = timeout
        self.reconnect = reconnect
        self.use_plain_sasl = use_plain_sasl
        if not reconnect:
            self.connect()

    def connect(self):
        self.socket = TSocket.TSocket(self.host, self.port)
        if self.timeout:
            self.socket.setTimeout(self.timeout)
        if self.use_plain_sasl:
            self.transport = SaslClientTransport(self.host, self.socket, service=STORM_SASL_SERVICE, mechanism='PLAIN')
        else:    
            self.transport = TTransport.TFramedTransport(self.socket)
        self.protocol = TBinaryProtocol.TBinaryProtocol(self.transport)
        self.transport.open()
        self.client = Client(self.protocol)

    def execute(self, func, args):
        if self.reconnect:
            self.connect()
        r = json.loads(self.client.execute(func, args))
        if self.reconnect:
            self.close()
        return r

    def executeJSON(self, func, **kwargs):
        return self.execute(func, json.dumps(kwargs))

    def close(self):
        self.transport.close()
Exemplo n.º 4
0
 def connect(self):
     self.socket = TSocket.TSocket(self.host, self.port)
     if self.timeout:
         self.socket.setTimeout(self.timeout)
     self.transport = TTransport.TFramedTransport(self.socket)
     self.protocol = TBinaryProtocol.TBinaryProtocol(self.transport)
     self.transport.open()
     self.client = Client(self.protocol)