Exemplo n.º 1
0
        def nested(self, seqid, iprot, oprot, server_ctx):
            fn_name = func.__name__.split('_', 1)[-1]
            handler_ctx = self._event_handler.getHandlerContext(fn_name,
                                                                server_ctx)
            args = argtype()
            reply_type = TMessageType.REPLY
            self._event_handler.preRead(handler_ctx, fn_name, args)
            args.read(iprot)
            iprot.readMessageEnd()
            self._event_handler.postRead(handler_ctx, fn_name, args)

            if hasattr(self._handler, "setRequestContext"):
                request_context = TRequestContext()
                if (isinstance(iprot, THeaderProtocol.THeaderProtocol)):
                    request_context.setHeaders(iprot.trans.get_headers())
                self._handler.setRequestContext(request_context)

            fut = func(self, args, handler_ctx)
            done_callback = partial(_done,
                                    processor=self,
                                    handler_ctx=handler_ctx,
                                    fn_name=fn_name,
                                    oprot=oprot,
                                    reply_type=reply_type,
                                    seqid=seqid,
                                    oneway=oneway)
            fut.add_done_callback(done_callback)

            if hasattr(self._handler, "setRequestContext"):
                self._handler.setRequestContext(None)
            return fut
Exemplo n.º 2
0
        def nested(self, seqid, iprot, oprot, server_ctx):
            fn_name = func.__name__.split('_', 1)[-1]
            handler_ctx = self._event_handler.getHandlerContext(
                fn_name, server_ctx)
            args = argtype()
            reply_type = TMessageType.REPLY
            self._event_handler.preRead(handler_ctx, fn_name, args)
            args.read(iprot)
            iprot.readMessageEnd()
            self._event_handler.postRead(handler_ctx, fn_name, args)

            if hasattr(self._handler, "setRequestContext"):
                request_context = TRequestContext()
                if (isinstance(iprot, THeaderProtocol.THeaderProtocol)):
                    request_context.setHeaders(iprot.trans.get_headers())
                self._handler.setRequestContext(request_context)

            fut = func(self, args, handler_ctx)
            done_callback = partial(_done,
                                    processor=self,
                                    handler_ctx=handler_ctx,
                                    fn_name=fn_name,
                                    oprot=oprot,
                                    reply_type=reply_type,
                                    seqid=seqid,
                                    oneway=oneway)
            fut.add_done_callback(done_callback)

            if hasattr(self._handler, "setRequestContext"):
                self._handler.setRequestContext(None)
            return fut
Exemplo n.º 3
0
        def nested(self, seqid, iprot, oprot, server_ctx):
            fn_name = func.__name__.split('_', 1)[-1]
            handler_ctx = self._event_handler.getHandlerContext(
                fn_name, server_ctx)
            args = argtype()
            reply_type = TMessageType.REPLY
            self._event_handler.preRead(handler_ctx, fn_name, args)
            args.read(iprot)
            iprot.readMessageEnd()
            self._event_handler.postRead(handler_ctx, fn_name, args)

            if hasattr(self._handler, "setRequestContext"):
                request_context = TRequestContext()
                if (isinstance(iprot, THeaderProtocol.THeaderProtocol)):
                    request_context.setHeaders(iprot.trans.get_headers())
                self._handler.setRequestContext(request_context)

            if twisted is True:
                return func(self, args, handler_ctx, seqid, oprot)
            elif oneway is True:
                func(self, args, handler_ctx)
            else:
                result = func(self, args, handler_ctx)
                if isinstance(result, TApplicationException):
                    reply_type = TMessageType.EXCEPTION

                self._event_handler.preWrite(handler_ctx, fn_name, result)
                oprot.writeMessageBegin(fn_name, reply_type, seqid)
                result.write(oprot)
                oprot.writeMessageEnd()
                oprot.trans.flush()
                self._event_handler.postWrite(handler_ctx, fn_name, result)
            if hasattr(self._handler, "setRequestContext"):
                self._handler.setRequestContext(None)
Exemplo n.º 4
0
        def nested(self, seqid, iprot, oprot, server_ctx):
            fn_name = func.__name__.split('_', 1)[-1]
            handler_ctx = self._event_handler.getHandlerContext(fn_name,
                    server_ctx)
            args = argtype()
            reply_type = TMessageType.REPLY
            self._event_handler.preRead(handler_ctx, fn_name, args)
            args.read(iprot)
            iprot.readMessageEnd()
            self._event_handler.postRead(handler_ctx, fn_name, args)

            if hasattr(self._handler, "setRequestContext"):
                request_context = TRequestContext()
                if (isinstance(iprot, THeaderProtocol.THeaderProtocol)):
                    request_context.setHeaders(iprot.trans.get_headers())
                self._handler.setRequestContext(request_context)

            if twisted is True:
                return func(self, args, handler_ctx, seqid, oprot)
            elif oneway is True:
                func(self, args, handler_ctx)
            else:
                result = func(self, args, handler_ctx)
                if isinstance(result, TApplicationException):
                    reply_type = TMessageType.EXCEPTION

                self._event_handler.preWrite(handler_ctx, fn_name, result)
                oprot.writeMessageBegin(fn_name, reply_type, seqid)
                result.write(oprot)
                oprot.writeMessageEnd()
                oprot.trans.flush()
                self._event_handler.postWrite(handler_ctx, fn_name, result)
            if hasattr(self._handler, "setRequestContext"):
                self._handler.setRequestContext(None)
Exemplo n.º 5
0
        def nested(self, seqid, iprot, oprot, server_ctx):
            _mem_before = _process_method_mem_usage()

            handler_ctx = self._event_handler.getHandlerContext(fn_name,
                    server_ctx)
            args = argtype()
            reply_type = TMessageType.REPLY
            self._event_handler.preRead(handler_ctx, fn_name, args)
            args.read(iprot)
            iprot.readMessageEnd()
            self._event_handler.postRead(handler_ctx, fn_name, args)

            if hasattr(self._handler, "setRequestContext"):
                request_context = TRequestContext()
                if (isinstance(iprot, THeaderProtocol.THeaderProtocol)):
                    request_context.setHeaders(iprot.trans.get_headers())
                self._handler.setRequestContext(request_context)

            if twisted is True:
                return func(self, args, handler_ctx, seqid, oprot)
            elif oneway is True:
                func(self, args, handler_ctx)
            else:
                result = func(self, args, handler_ctx)
                if isinstance(result, TApplicationException):
                    reply_type = TMessageType.EXCEPTION

                self._event_handler.preWrite(handler_ctx, fn_name, result)
                oprot.writeMessageBegin(fn_name, reply_type, seqid)
                result.write(oprot)
                oprot.writeMessageEnd()
                oprot.trans.flush()
                self._event_handler.postWrite(handler_ctx, fn_name, result)
            if hasattr(self._handler, "setRequestContext"):
                self._handler.setRequestContext(None)

            _mem_after = _process_method_mem_usage()
            if _mem_after - _mem_before > MEMORY_WARNING_THRESHOLD:
                log.error(
                    'Memory usage rose from %d to %d while processing `%s` '
                    'with args `%s`',
                    _mem_before,
                    _mem_after,
                    fn_name,
                    str(args),
                )
Exemplo n.º 6
0
def set_request_context(processor, iprot):
    if needs_request_context(processor):
        request_context = TRequestContext()
        if isinstance(iprot, THeaderProtocol.THeaderProtocol):
            request_context.setHeaders(iprot.trans.get_headers())
        processor._handler.setRequestContext(request_context)
Exemplo n.º 7
0
def set_request_context(processor, iprot):
    if needs_request_context(processor):
        request_context = TRequestContext()
        if isinstance(iprot, THeaderProtocol.THeaderProtocol):
            request_context.setHeaders(iprot.trans.get_headers())
        processor._handler.setRequestContext(request_context)