def frame_received(self, frame: Frame): if isinstance(frame, CancelFrame): self.subscriber.subscription.cancel() self._finish_stream() elif isinstance(frame, RequestNFrame): if self.subscriber.subscription is not None: self.subscriber.subscription.request(frame.request_n) else: logger().warning( '%s: Received request_n but no publisher provided', self.__class__.__name__) elif isinstance(frame, PayloadFrame): if frame.flags_next: self.remote_subscriber.on_next( payload_from_frame(frame), is_complete=frame.flags_complete) elif frame.flags_complete: self.remote_subscriber.on_complete() if frame.flags_complete: self.mark_completed_and_finish(received=True) elif isinstance(frame, ErrorFrame): self.remote_subscriber.on_error(error_frame_to_exception(frame)) self.mark_completed_and_finish(received=True)
def frame_received(self, frame: Frame): if isinstance(frame, PayloadFrame): if frame.flags_next: self._subscriber.on_next(payload_from_frame(frame), is_complete=frame.flags_complete) elif frame.flags_complete: self._subscriber.on_complete() if frame.flags_complete: self._finish_stream() elif isinstance(frame, ErrorFrame): self._subscriber.on_error(error_frame_to_exception(frame)) self._finish_stream()
async def handle_request_stream(self, frame: RequestStreamFrame): stream_id = frame.stream_id self._stream_control.assert_stream_id_available(stream_id) handler = self._handler try: publisher = await handler.request_stream(payload_from_frame(frame)) except Exception as exception: self.send_error(stream_id, exception) return request_responder = RequestStreamResponder(self, publisher) self._register_stream(stream_id, request_responder) request_responder.frame_received(frame)
async def handle_request_response(self, frame: RequestResponseFrame): stream_id = frame.stream_id self._stream_control.assert_stream_id_available(stream_id) handler = self._handler try: response_future = await handler.request_response( payload_from_frame(frame)) except Exception as exception: self.send_error(stream_id, exception) return self._register_stream(stream_id, RequestResponseResponder( self, response_future)).setup()
async def handle_setup(self, frame: SetupFrame): if frame.flags_resume: raise RSocketProtocolError(ErrorCode.UNSUPPORTED_SETUP, data='Resume not supported') if frame.flags_lease: if self._lease_publisher is None: raise RSocketProtocolError(ErrorCode.UNSUPPORTED_SETUP, data='Lease not available') else: self._subscribe_to_lease_publisher() handler = self._handler try: await handler.on_setup(frame.data_encoding, frame.metadata_encoding, payload_from_frame(frame)) except Exception as exception: logger().error('%s: Setup error', self._log_identifier(), exc_info=True) raise RSocketProtocolError(ErrorCode.REJECTED_SETUP, data=str(exception)) from exception
async def handle_fire_and_forget(self, frame: RequestFireAndForgetFrame): self._stream_control.assert_stream_id_available(frame.stream_id) await self._handler.request_fire_and_forget(payload_from_frame(frame))
async def handle_error(self, frame: ErrorFrame): await self._handler.on_error(frame.error_code, payload_from_frame(frame))