def execute(self, req, keyspace=None): if self.my_proto is None: return defer.fail(error.ConnectionClosed( 'Lost connection before %s request could be made' % (req.method,))) method = getattr(self.my_proto.client, req.method, None) if method is None: raise InvalidThriftRequest("don't understand %s request" % req.method) def wrap_thrift_request(method, *args): # convenience wrapper around thrift request with timeout support d = defer.Deferred() # institute a (fairly long) hard timeout def short_circuit(): err = Exception('Timeout: %r %r' % (method, args)) if not d.called: d.errback(err) timeout = reactor.callLater(10, short_circuit) req_d = defer.succeed(True) # the actual thrift call req_d.addCallback(lambda _ : method(*args)) def pipe_callback(res): if timeout.active(): timeout.cancel() if d.called: log.msg('REQ_TIMEOUT: (%r, %r) -> %r' % (method, args, res)) else: d.callback(res) def pipe_errback(e): if timeout.active(): timeout.cancel() if d.called: log.err(e, 'REQ_TIMEOUT: Error (%r, %r)' % (method, args)) else: d.errback(e) # make sure the results gets wired to the right place req_d.addCallbacks(pipe_callback, pipe_errback) return d d = defer.succeed(0) if req.method == 'set_keyspace': newksname = req.args[0] d.addCallback(lambda _: wrap_thrift_request(method, newksname)) d.addCallback(self.store_successful_keyspace_set, newksname) else: if keyspace is not None and keyspace != self.keyspace: d.addCallback(lambda _: self.my_set_keyspace(keyspace)) args = translateArgs(req, self.api_version) d.addCallback(lambda _: wrap_thrift_request(method, *args)) d.addCallback(lambda results: postProcess(results, req.method)) return d
def submitRequest(self, request): if not self.deferred: fun = getattr(self.client, request.method, None) if not fun: raise InvalidThriftRequest else: args = translate.translateArgs(request, self.api_version) d = fun(*args) d.addCallback(lambda results: translate.postProcess(results, request.method)) self.deferred = d d.addBoth(self._complete) return d else: raise ClientBusy
def submitRequest(self, request): if not self.deferred: fun = getattr(self.client, request.method, None) if not fun: raise InvalidThriftRequest else: args = translate.translateArgs(request, self.api_version) d = fun(*args) d.addCallback(lambda results: translate.postProcess( results, request.method)) self.deferred = d d.addBoth(self._complete) return d else: raise ClientBusy
def execute(self, req, keyspace=None): if self.my_proto is None: return defer.errback(error.ConnectionClosed( 'Lost connection before %s request could be made' % (req.method,))) method = getattr(self.my_proto.client, req.method, None) if method is None: raise InvalidThriftRequest("don't understand %s request" % req.method) d = defer.succeed(0) if req.method == 'set_keyspace': newksname = req.args[0] d.addCallback(lambda _: method(newksname)) d.addCallback(self.store_successful_keyspace_set, newksname) else: if keyspace is not None and keyspace != self.keyspace: d.addCallback(lambda _: self.my_set_keyspace(keyspace)) args = translateArgs(req, self.api_version) d.addCallback(lambda _: method(*args)) d.addCallback(lambda results: postProcess(results, req.method)) return d
def execute(self, req, keyspace=None): if self.my_proto is None: return defer.errback( error.ConnectionClosed( 'Lost connection before %s request could be made' % (req.method, ))) method = getattr(self.my_proto.client, req.method, None) if method is None: raise InvalidThriftRequest("don't understand %s request" % req.method) d = defer.succeed(0) if req.method == 'set_keyspace': newksname = req.args[0] d.addCallback(lambda _: method(newksname)) d.addCallback(self.store_successful_keyspace_set, newksname) else: if keyspace is not None and keyspace != self.keyspace: d.addCallback(lambda _: self.my_set_keyspace(keyspace)) args = translateArgs(req, self.api_version) d.addCallback(lambda _: method(*args)) d.addCallback(lambda results: postProcess(results, req.method)) return d