Ejemplo n.º 1
0
def main():
    n = 100000

    print("binary protocol struct benchmark for {} times:".format(n))
    encode(n)
    decode(n)

    print("\ncybin protocol struct benchmark for {} times:".format(n))
    encode(n, TCyBinaryProtocolFactory())
    decode(n, TCyBinaryProtocolFactory())
Ejemplo n.º 2
0
def decode_msg(kafka_msg):
    raw_payload = deserialize(STRUCTS.CollectorPayload(), kafka_msg,
                              TCyBinaryProtocolFactory())
    querystring = raw_payload.querystring
    obj = raw_payload.__dict__
    obj['querystring_parsed'] = parse.parse_qs(raw_payload.querystring)
    return obj
Ejemplo n.º 3
0
 def __create_client(self):
     socket = TSocket(self.__host,
                      self.__port,
                      socket_timeout=self.__timeout)
     self.__transport = TCyFramedTransportFactory().get_transport(socket)
     protocol = TCyBinaryProtocolFactory().get_protocol(self.__transport)
     self.__client = TClient(recs_thrift.RecommendationsService, protocol)
Ejemplo n.º 4
0
def print_thrift(timestamp, data):
    json_payload = json.loads(data.decode('utf-8'))
    decoded_thrift_payload = base64.b64decode(json_payload['line'])
    thrift_payload = deserialize(collector_payload, decoded_thrift_payload,
                                 TCyBinaryProtocolFactory())
    print('{}: {}, {}'.format(timestamp, thrift_payload,
                              json_payload['errors']))
Ejemplo n.º 5
0
def main():
    server = make_server(calc.Calculator,
                         Dispatcher(),
                         '127.0.0.1',
                         6000,
                         proto_factory=TCyBinaryProtocolFactory())
    print("serving...")
    server.serve()
Ejemplo n.º 6
0
def main():
    server = make_server(tutorial.Calculator,
                         CalculatorHandler(),
                         '127.0.0.1',
                         6000,
                         proto_factory=TCyBinaryProtocolFactory())
    print("serving...")
    server.serve()
Ejemplo n.º 7
0
def client(thrift, host, port, service):
    calc_thrift = thriftpy.load(str(thrift))
    with client_context(getattr(calc_thrift, service),
                        host,
                        port,
                        proto_factory=TCyBinaryProtocolFactory(),
                        trans_factory=TCyBufferedTransportFactory()) as client:
        IPython.embed(header="Call client.api(*args)")
Ejemplo n.º 8
0
def decode_event(data, collector_payload):
    json_payload = json.loads(data.decode('utf-8'))
    decoded_thrift_payload = base64.b64decode(json_payload['line'])
    thrift_payload = deserialize(collector_payload, decoded_thrift_payload,
                                 TCyBinaryProtocolFactory())

    qs = thrift_payload.querystring
    event = {'qs': parse.parse_qs(qs), 'errors': json_payload['errors']}
    return event
Ejemplo n.º 9
0
def main():
    server = make_server(calc_thrift.Calculator,
                         Dispatcher(),
                         '127.0.0.1',
                         6000,
                         proto_factory=TCyBinaryProtocolFactory(),
                         trans_factory=TCyBufferedTransportFactory())
    print("serving...")
    server.serve()
Ejemplo n.º 10
0
def main():
    with client_context(calc.Calculator, '127.0.0.1', 6000,
                        proto_factory=TCyBinaryProtocolFactory()) as cal:
        a = cal.mult(5, 2)
        b = cal.sub(7, 3)
        c = cal.sub(6, 4)
        d = cal.mult(b, 10)
        e = cal.add(a, d)
        f = cal.div(e, c)
        print(f)
Ejemplo n.º 11
0
def main():
    print("TBinaryProtocol:")

    start = time.time()
    encode(10000)
    end = time.time()
    print(end - start)

    start = time.time()
    decode(10000)
    end = time.time()
    print(end - start)

    print("\nTCyBinaryProtocol:")

    start = time.time()
    encode(10000, TCyBinaryProtocolFactory())
    end = time.time()
    print(end - start)

    start = time.time()
    decode(10000, TCyBinaryProtocolFactory())
    end = time.time()
    print(end - start)
Ejemplo n.º 12
0
 def get_protoco_factory(self):
     from thriftpy.protocol import TCyBinaryProtocolFactory
     return TCyBinaryProtocolFactory().get_protocol
Ejemplo n.º 13
0
            return json.dumps(to_send)
        except fs.FileNotFound as e:
            to_send['err'] = str(e)
            return json.dumps(to_send)
        else:
            to_send['err'] = 'An unexpected error occurred'
            return json.dumps(to_send)


#Signal handler to ensure that on a termination signal, the file store saves
#the state of the system. Probably don't need this anymore.
def signal_handler(signal, frame):
    sys.exit(0)  #And now its watch has ended


signal.signal(signal.SIGTERM,
              signal_handler)  #Really, this is just like signing a will

#Starts the thrift service running on port 6000
#Remember, use 127.0.0.1 and not localhost. We still want to avoid the apocalypse!
server = make_server(link_thrift.Link,
                     Dispatcher(),
                     '127.0.0.1',
                     6000,
                     proto_factory=TCyBinaryProtocolFactory(),
                     trans_factory=TCyBufferedTransportFactory())
print("Service activated")
server.serve()

finished = True