Ejemplo n.º 1
0
 def _protocol_send(self, command, args=""):
     if self._closing_state:
         return Event()
     self.trace("_protocol_send %s %s" % (command, args))
     # Append command to pool
     # and send it to eventsocket
     _cmd_uuid = str(uuid1())
     _async_res = gevent.event.AsyncResult()
     with self._lock:
         self._commands_pool.append((_cmd_uuid, _async_res))
         self._send("%s %s" % (command, args))
     self.trace("_protocol_send %s wait ..." % command)
     _uuid, event = _async_res.get()
     if _cmd_uuid != _uuid:
         raise InternalSyncError("in _protocol_send")
     # Casts Event to appropriate event type :
     # Casts to ApiResponse, if event is api
     if command == 'api':
         event = ApiResponse.cast(event)
     # Casts to BgapiResponse, if event is bgapi
     elif command == "bgapi":
         event = BgapiResponse.cast(event)
     # Casts to CommandResponse by default
     else:
         event = CommandResponse.cast(event)
     self.trace("_protocol_send %s done" % command)
     return event
Ejemplo n.º 2
0
 def _protocol_send(self, command, args=""):
     if self._closing_state:
         return Event()
     self.trace("_protocol_send %s %s" % (command, args))
     # Append command to pool
     # and send it to eventsocket
     _cmd_uuid = str(uuid1())
     _async_res = gevent.event.AsyncResult()
     with self._lock:
         self._commands_pool.append((_cmd_uuid, _async_res))
         self._send("%s %s" % (command, args))
     self.trace("_protocol_send %s wait ..." % command)
     _uuid, event = _async_res.get()
     if _cmd_uuid != _uuid:
         raise InternalSyncError("in _protocol_send")
     # Casts Event to appropriate event type :
     # Casts to ApiResponse, if event is api
     if command == 'api':
         event = ApiResponse.cast(event)
     # Casts to BgapiResponse, if event is bgapi
     elif command == "bgapi":
         event = BgapiResponse.cast(event)
     # Casts to CommandResponse by default
     else:
         event = CommandResponse.cast(event)
     self.trace("_protocol_send %s done" % command)
     return event
Ejemplo n.º 3
0
 def _protocol_sendmsg(self, name, args=None, uuid="", lock=False, loops=1):
     if self._closing_state:
         return Event()
     self._lock.acquire()
     try:
         self._sendmsg(name, args, uuid, lock, loops)
         event = self._response_queue.get()
     finally:
         self._lock.release()
     # Always casts Event to CommandResponse
     return CommandResponse.cast(event)
Ejemplo n.º 4
0
 def _protocol_send(self, command, args=""):
     if self._closing_state:
         return Event()
     self._lock.acquire()
     try:
         self._send("%s %s" % (command, args))
         event = self._response_queue.get()
     finally:
         self._lock.release()
     # Casts Event to appropriate event type :
     # Casts to ApiResponse, if event is api
     if command == 'api':
         event = ApiResponse.cast(event)
     # Casts to BgapiResponse, if event is bgapi
     elif command == "bgapi":
         event = BgapiResponse.cast(event)
     # Casts to CommandResponse by default
     else:
         event = CommandResponse.cast(event)
     return event
Ejemplo n.º 5
0
        # Casts to CommandResponse by default
        else:
            event = CommandResponse.cast(event)
        self.trace("_protocol_send %s done" % command)
        return event

    def _protocol_sendmsg(self,
                          name,
                          args=None,
                          uuid="",
                          lock=False,
                          loops=1,
                          async=False):
        if self._closing_state:
            return Event()
        self.trace("_protocol_sendmsg %s" % name)
        # Append command to pool
        # and send it to eventsocket
        _cmd_uuid = str(uuid1())
        _async_res = gevent.event.AsyncResult()
        with self._lock:
            self._commands_pool.append((_cmd_uuid, _async_res))
            self._sendmsg(name, args, uuid, lock, loops, async)
        self.trace("_protocol_sendmsg %s wait ..." % name)
        _uuid, event = _async_res.get()
        if _cmd_uuid != _uuid:
            raise InternalSyncError("in _protocol_sendmsg")
        self.trace("_protocol_sendmsg %s done" % name)
        # Always casts Event to CommandResponse
        return CommandResponse.cast(event)
Ejemplo n.º 6
0
        # Casts to ApiResponse, if event is api
        if command == 'api':
            event = ApiResponse.cast(event)
        # Casts to BgapiResponse, if event is bgapi
        elif command == "bgapi":
            event = BgapiResponse.cast(event)
        # Casts to CommandResponse by default
        else:
            event = CommandResponse.cast(event)
        self.trace("_protocol_send %s done" % command)
        return event

    def _protocol_sendmsg(self, name, args=None, uuid="", lock=False, loops=1, async=False):
        if self._closing_state:
            return Event()
        self.trace("_protocol_sendmsg %s" % name)
        # Append command to pool
        # and send it to eventsocket
        _cmd_uuid = str(uuid1())
        _async_res = gevent.event.AsyncResult()
        with self._lock:
            self._commands_pool.append((_cmd_uuid, _async_res))
            self._sendmsg(name, args, uuid, lock, loops, async)
        self.trace("_protocol_sendmsg %s wait ..." % name)
        _uuid, event = _async_res.get()
        if _cmd_uuid != _uuid:
            raise InternalSyncError("in _protocol_sendmsg")
        self.trace("_protocol_sendmsg %s done" % name)
        # Always casts Event to CommandResponse
        return CommandResponse.cast(event)