def _read_response(self, header, buffer, offset): client = self.client request, async_object, xid = client._pending.get() if header.zxid and header.zxid > 0: client.last_zxid = header.zxid if header.xid != xid: raise RuntimeError('xids do not match, expected %r ' 'received %r', xid, header.xid) # Determine if its an exists request and a no node error exists_error = header.err == NoNodeError.code and \ request.type == Exists.type # Set the exception if its not an exists error if header.err and not exists_error: callback_exception = EXCEPTIONS[header.err]() if self.log_debug: log.debug('Received error %r', callback_exception) if async_object: async_object.set_exception(callback_exception) elif request and async_object: if exists_error: # It's a NoNodeError, which is fine for an exists # request async_object.set(None) else: try: response = request.deserialize(buffer, offset) except Exception as exc: if self.log_debug: log.debug("Exception raised during deserialization" " of request: %s", request) log.exception(exc) async_object.set_exception(exc) return log.debug('Received response: %r', response) # We special case a Transaction as we have to unchroot things if request.type == Transaction.type: response = Transaction.unchroot(client, response) async_object.set(response) # Determine if watchers should be registered watcher = getattr(request, 'watcher', None) with client._state_lock: if not client._stopped.is_set() and watcher: if isinstance(request, GetChildren): client._child_watchers[request.path].append(watcher) else: client._data_watchers[request.path].append(watcher) if isinstance(request, Close): if self.log_debug: log.debug('Read close response') self._socket.close() return True
def commit_async(self): """Commit the transaction asynchronously. :rtype: :class:`~kazoo.interfaces.IAsyncResult` """ self._check_tx_state() self.committed = True async_object = self.client.handler.async_result() self.client._call(Transaction(self.operations), async_object) return async_object
def _read_response(self, header, buffer, offset): client = self.client request, async_object, xid = client._pending.popleft() if header.zxid and header.zxid > 0: client.last_zxid = header.zxid if header.xid != xid: raise RuntimeError("xids do not match, expected %r " "received %r", xid, header.xid) # Determine if its an exists request and a no node error exists_error = header.err == NoNodeError.code and request.type == Exists.type # Set the exception if its not an exists error if header.err and not exists_error: callback_exception = EXCEPTIONS[header.err]() self.logger.debug("Received error(xid=%s) %r", xid, callback_exception) if async_object: async_object.set_exception(callback_exception) elif request and async_object: if exists_error: # It's a NoNodeError, which is fine for an exists # request async_object.set(None) else: try: response = request.deserialize(buffer, offset) except Exception as exc: self.logger.exception("Exception raised during deserialization " "of request: %s", request) async_object.set_exception(exc) return self.logger.debug("Received response(xid=%s): %r", xid, response) # We special case a Transaction as we have to unchroot things if request.type == Transaction.type: response = Transaction.unchroot(client, response) async_object.set(response) # Determine if watchers should be registered watcher = getattr(request, "watcher", None) if not client._stopped.is_set() and watcher: if isinstance(request, GetChildren): client._child_watchers[request.path].add(watcher) else: client._data_watchers[request.path].add(watcher) if isinstance(request, Close): self.logger.log(BLATHER, "Read close response") return CLOSE_RESPONSE