aea.multiplexer¶
Module for the multiplexer class and related classes.
MultiplexerStatus Objects¶
The connection status class.
__
init__
¶
Initialize the connection status.
is_
connected¶
Return is connected.
is_
connecting¶
Return is connecting.
is_
disconnected¶
Return is disconnected.
is_
disconnecting¶
Return is disconnected.
AsyncMultiplexer Objects¶
This class can handle multiple connections at once.
__
init__
¶
def __init__(
connections: Optional[Sequence[Connection]] = None,
default_connection_index: int = 0,
loop: Optional[AbstractEventLoop] = None,
exception_policy: ExceptionPolicyEnum = ExceptionPolicyEnum.propagate,
threaded: bool = False,
agent_name: str = "standalone",
default_routing: Optional[Dict[PublicId, PublicId]] = None,
default_connection: Optional[PublicId] = None,
protocols: Optional[List[Union[Protocol, Message]]] = None) -> None
Initialize the connection multiplexer.
Arguments:
connections
: a sequence of connections.default_connection_index
: the index of the connection to use as default. This information is used for envelopes which don't specify any routing context. If connections is None, this parameter is ignored.loop
: the event loop to run the multiplexer. If None, a new event loop is created.exception_policy
: the exception policy used for connections.threaded
: if True, run in threaded mode, else asyncagent_name
: the name of the agent that owns the multiplexer, for logging purposes.default_routing
: default routing mapdefault_connection
: default connectionprotocols
: protocols used
default_
connection¶
Get the default connection.
in_
queue¶
Get the in queue.
out_
queue¶
Get the out queue.
connections¶
Get the connections.
is_
connected¶
Check whether the multiplexer is processing envelopes.
default_
routing¶
Get the default routing.
default_
routing¶
Set the default routing.
connection_
status¶
Get the connection status.
run¶
Run multiplexer connect and receive/send tasks.
set_
loop¶
Set event loop and all event loop related objects.
Arguments:
loop
: asyncio event loop.
add_
connection¶
Add a connection to the multiplexer.
Arguments:
connection
: the connection to add.is_default
: whether the connection added should be the default one.
connect¶
Connect the multiplexer.
disconnect¶
Disconnect the multiplexer.
get¶
Get an envelope within a timeout.
Arguments:
block
: make the call blocking (ignore the timeout).timeout
: the timeout to wait until an envelope is received.
Returns:
the envelope, or None if no envelope is available within a timeout.
async_
get¶
Get an envelope async way.
Returns:
the envelope
async_
wait¶
Get an envelope async way.
Returns:
the envelope
put¶
Schedule an envelope for sending it.
Notice that the output queue is an asyncio.Queue which uses an event loop running on a different thread than the one used in this function.
Arguments:
envelope
: the envelope to be sent.
Multiplexer Objects¶
Transit sync multiplexer for compatibility.
__
init__
¶
Initialize the connection multiplexer.
Arguments:
args
: argumentskwargs
: keyword arguments
set_
loop¶
Set event loop and all event loop related objects.
Arguments:
loop
: asyncio event loop.
connect¶
Connect the multiplexer.
Synchronously in thread spawned if new loop created.
disconnect¶
Disconnect the multiplexer.
Also stops a dedicated thread for event loop if spawned on connect.
put¶
Schedule an envelope for sending it.
Notice that the output queue is an asyncio.Queue which uses an event loop running on a different thread than the one used in this function.
Arguments:
envelope
: the envelope to be sent.
InBox Objects¶
A queue from where you can only consume envelopes.
__
init__
¶
Initialize the inbox.
Arguments:
multiplexer
: the multiplexer
empty¶
Check for a envelope on the in queue.
Returns:
boolean indicating whether there is an envelope or not
get¶
Check for a envelope on the in queue.
Arguments:
block
: make the call blocking (ignore the timeout).timeout
: times out the block after timeout seconds.
Raises:
Empty
: if the attempt to get an envelope fails.
Returns:
the envelope object.
get_
nowait¶
Check for a envelope on the in queue and wait for no time.
Returns:
the envelope object
async_
get¶
Check for a envelope on the in queue.
Returns:
the envelope object.
async_
wait¶
Check for a envelope on the in queue.
OutBox Objects¶
A queue from where you can only enqueue envelopes.
__
init__
¶
Initialize the outbox.
Arguments:
multiplexer
: the multiplexer
empty¶
Check for a envelope on the in queue.
Returns:
boolean indicating whether there is an envelope or not
put¶
Put an envelope into the queue.
Arguments:
envelope
: the envelope.
put_
message¶
Put a message in the outbox.
This constructs an envelope with the input arguments.
Arguments:
message
: the messagecontext
: the envelope context