Exemplo n.º 1
0
    def delete(self, name):
        message = msgpackio.MessagePackMessage(command='del', name=name)
        self.socket.send(message.dumps())

        response = msgpackio.MessagePackMessage(
            msgpack_message=self.socket.recv())
        if not response.result:
            print("Consumer:delete failed to del {name}".format(name=name))
Exemplo n.º 2
0
    def stop(self):
        message = msgpackio.MessagePackMessage(command='stop')
        self.socket.send(message.dumps())

        response = msgpackio.MessagePackMessage(
            msgpack_message=self.socket.recv())
        if not response.result:
            print("Consumer:stop failed to stop")
Exemplo n.º 3
0
    def get(self, name, query=None):
        if query is None:
            message = msgpackio.MessagePackMessage(command='get', name=name)
        else:
            message = msgpackio.MessagePackMessage(command='get',
                                                   query=query,
                                                   name=name)

        self.socket.send(message.dumps())
        return self.deserialize_func(self.socket.recv())
Exemplo n.º 4
0
    def _write(self, command, name, data):
        message = msgpackio.MessagePackMessage(command=command,
                                               name=name,
                                               data=self.serialize_func(data))
        self.socket.send(message.dumps())

        response = msgpackio.MessagePackMessage(
            msgpack_message=self.socket.recv())
        if not response.result:
            print("Consumer:_write failed to {command} {name}".format(
                command=command, name=name))
Exemplo n.º 5
0
    def mainloop(self):
        print("Service:mainloop: Starting...")

        runloop = True
        while runloop:
            #  Wait for next request from client
            message = msgpackio.MessagePackMessage(
                msgpack_message=self.socket.recv())

            return_data = ''
            if message.command == "get":
                return_data = self.get_data(message)
            elif message.command == "set":
                return_data = msgpackio.MessagePackMessage(
                    result=self.set_data(message)).dumps()
            elif message.command == "del":
                return_data = msgpackio.MessagePackMessage(
                    result=self.del_data(message)).dumps()
            elif message.command == "append":
                return_data = msgpackio.MessagePackMessage(
                    result=self.append_data(message)).dumps()
            elif message.command == 'append_all':
                return_data = msgpackio.MessagePackMessage(
                    result=self.append_all_data(message)).dumps()
            elif message.command == 'info':
                return_data = msgpackio.MessagePackMessage(
                    self.info(message)).dumps()
            elif message.command == 'stop':
                runloop = False
                return_data = msgpackio.MessagePackMessage(result=True).dumps()
            else:
                print("Service:mainloop: Unknown command {command}".format(
                    command=message.command))

            #  Send reply back to client
            self.socket.send(return_data)