def __init__(self, connection: ConnectionAPI) -> None: self._connection = connection for attr, exchange_cls in self._exchange_config.items(): if hasattr(self, attr): raise AttributeError( f"Unable to set manager on attribute `{attr}` which is already " f"present on the class: {getattr(self, attr)}") protocol = connection.get_protocol_for_command_type( exchange_cls.get_request_cmd_type()) if not protocol.supports_command( exchange_cls.get_response_cmd_type()): raise ValidationError( f"Could not determine appropriate protocol: " f"The response command type " f"{exchange_cls.get_response_cmd_type()} is not supported by the " f"protocol that matched the request command type: " f"{protocol}") manager: ExchangeManager[Any, Any, Any] manager = ExchangeManager( connection=self._connection, requesting_on=protocol, listening_for=exchange_cls.get_response_cmd_type(), ) exchange = exchange_cls(manager) setattr(self, attr, exchange)
def qualifier(self, connection: ConnectionAPI, logic: LogicAPI) -> bool: try: protocol = connection.get_protocol_for_command_type( self.exchange.get_request_cmd_type()) except UnknownProtocol: return False else: return protocol.supports_command( self.exchange.get_response_cmd_type())
async def run_exchange(self, connection: ConnectionAPI) -> AsyncIterator[None]: protocol = connection.get_protocol_for_command_type(self.get_request_cmd_type()) response_stream: ResponseCandidateStream[TRequestCommand, TResponseCommand] = ResponseCandidateStream( # noqa: E501 connection, protocol, self.get_response_cmd_type(), ) self._manager = ExchangeManager( connection, response_stream, ) async with run_service(response_stream): yield
async def run_exchange( self, connection: ConnectionAPI) -> AsyncIterator[asyncio.Future[None]]: protocol = connection.get_protocol_for_command_type(self.get_request_cmd_type()) response_stream: ResponseCandidateStream[TRequestCommand, TResponseCommand] = ResponseCandidateStream( # noqa: E501 connection, protocol, self.get_response_cmd_type(), ) async with background_asyncio_service(response_stream) as response_stream_manager: self._manager = ExchangeManager( connection, response_stream, ) yield asyncio.create_task(response_stream_manager.wait_finished())
async def run_exchange( self, connection: ConnectionAPI) -> AsyncIterator[asyncio.Task[Any]]: protocol = connection.get_protocol_for_command_type( self.get_request_cmd_type()) response_stream: ResponseCandidateStream[ TRequestCommand, TResponseCommand] = ResponseCandidateStream( # noqa: E501 connection, protocol, self.get_response_cmd_type(), ) async with background_asyncio_service( response_stream) as response_stream_manager: self._manager = ExchangeManager( connection, response_stream, ) name = f'{self.__class__.__name__}/{connection.remote}' yield create_task(response_stream_manager.wait_finished(), name=name)
async def run_exchange(self, connection: ConnectionAPI) -> AsyncIterator[None]: protocol = connection.get_protocol_for_command_type( self.get_request_cmd_type()) response_stream: ResponseCandidateStream[ TRequestPayload, TResponsePayload] = ResponseCandidateStream( # noqa: E501 connection, protocol, self.get_response_cmd_type(), ) try: self.tracker = self.tracker_class() self._manager = ExchangeManager( connection, response_stream, ) async with run_service(response_stream): yield finally: del self._manager del self.tracker