Example #1
0
    def sendAsync(self, command, value, onSuccess, onError, no_ack=False):
        if self.faulted:  # TODO(Nacho): should we fault through onError on fault or bow up on the callers face?
            self._raise(
                common.ConnectionFaulted(
                    "Can't send message when connection is on a faulted state."
                ), onError)
            return  #skip the rest

        # fail fast on NotConnected
        if not self.isConnected:  # TODO(Nacho): should we fault through onError on fault or bow up on the callers face?
            self._raise(common.NotConnected("Not connected."), onError)
            return  #skip the rest

        def innerSuccess(m, response, value):
            try:
                operations._check_status(response)
                onSuccess(m, response, value)
            except Exception as ex:
                onError(ex)

        # get sequence
        self.update_header(command)

        if not no_ack:
            # add callback to pending dictionary
            self._pending[command.header.sequence] = (innerSuccess, onError)

        # transmit
        self.network_send(command, value)
Example #2
0
    def _processAsync(self, op, onSuccess, onError, *args, **kwargs):
        if not self.isConnected: raise common.NotConnected("Must call connect() before sending operations.")

        def innerSuccess(m, header, value):
            onSuccess(op.parse(header, value))

        def innerError(e):
            try:
                v = op.onError(e)
                onSuccess(v)
            except Exception as e2:
                onError(e2)

        header, value = op.build(*args, **kwargs)
        self.sendAsync(header, value, innerSuccess, innerError)
Example #3
0
    def sendAsync(self, header, value, onSuccess, onError):
        if self.closing:
            raise common.ConnectionClosed(
                "Client is closing, can't queue more operations.")

        if self.faulted:
            self._raise(
                common.ConnectionFaulted(
                    "Can't send message when connection is on a faulted state."
                ), onError)
            return  #skip the rest

        # fail fast on NotConnected
        if not self.isConnected:
            self._raise(common.NotConnected("Not connected."), onError)
            return  #skip the rest

        if LOG.isEnabledFor(logging.DEBUG):
            LOG.debug("Queue: {0}".format(self.queue.qsize()))
        self.queue.put((header, value, onSuccess, onError))
        eventlet.sleep(0)
Example #4
0
 def _process(self, op, *args, **kwargs):
     if not self.isConnected:
         raise common.NotConnected(
             "Must call connect() before sending operations.")
     return super(BaseAsync, self)._process(op, *args, **kwargs)