Every agent must live in a container. A container can contain one ore more agents. Containers are responsible for making connections to other containers and agents. They also provide a factory function for spawning new agent instances and registering them with the container.
SSLCerts(cafile, certfile, keyfile)¶
namedtuple()storing the names of a CA file, a certificate file and the associated private key file.
Alias for field number 0
Alias for field number 1
Alias for field number 2
Container(base_url, loop, clock, connect_kwargs)¶
Container for agents.
You should not instantiate containers directly but use the
create()method/coroutine instead. This makes sure that the container’s server socket is fully operational when it is created.
The container allows its agents to create connections to other agents (via
In order to destroy a container and close all of its sockets, call
create(addr, *, clock=None, codec=None, extra_serializers=None, ssl=None, as_coro=False, loop=None)¶
Instantiate a container and create a server socket for it.
This function is a classmethod and coroutine.
- addr –
is the address that the server socket is bound to. It may be a
(host, port)tuple for a TCP socket, a path for a Unix domain socket, or a LocalQueue instance as returned by the
'::', the server is bound to all available IPv4 or IPv6 interfaces respectively. If
'', the server is bound to all available IPv4 and IPv6 interfaces. In these cases, the machine’s FQDN (see
socket.getfqdn()) should be resolvable and point to that machine as it will be used for the agent’s addresses.
hostis a simple (IPv4 or IPv6) IP address, it will be used for the agent’s addresses as is.
In contrast to TCP, multiple LocalQueue connections between containers (within the same thread and OS process) send and receive message in a deterministic order, which is useful for testing and debugging.
LocalQueue instances should be retrieved via the
aiomas.local_queue.get_queue()function (which also available as
aiomas.get_queue()). This function always returns the same instance for a given queue ID.
- clock –
can be an instance of
It allows you to decouple the container’s (and thus, its agent’s) time from the system clock. This makes it easier to integrate your system with other simulators that may provide a clock for you or to let your MAS run as fast as possible.
By default, the real-time
AsyncioClockwill be used.
- codec – can be a
Codecsubclass (not an instance!).
JSONis used by default.
- extra_serializers – is an optional list of extra serializers for the codec. The list
entries need to be callables that return a tuple with the arguments
- ssl – allows you to enable TLS for all incoming and outgoing TCP
connections. It may either be an
SSLCertsinstance or a tuple containing two
SSLContextinstances, where the first one will be used for the server socket, the second one for client sockets.
- as_coro – must be set to
Trueif the event loop is already running when you call this method. This function then returns a coroutine that you need to
awaitin order to get the container. By default it will block until the server has been started and return the container.
- loop – The asyncio event loop to use. If
None, the default one will be used.
a fully initialized
Containerinstance if async is
Falseor else a coroutine returning the instance when it is done.
# Synchronous: container = Container.create(...) # Asynchronous: container = await Container.create(..., as_coro=True)
- addr –
The event loop the container is using.
Connect to the argent available at url and return a proxy to it.
url is a string
With a timeout of 0 (the default), there will only be one connection attempt before an error is raised (
ConnectionRefusedErrorfor TCP sockets and LocalQueue,
FileNotFoundErrorfor Unix domain sockets). If you set timeout to a number > 0 or
None, this function will try to connect repeatedly for at most that many seconds (or indefinitely) before an error is raised. Use this if the remote agent’s container may not yet exist.
This function is a coroutine.
Close the container’s server socket and the RPC services for all outgoing TCP connections.
If async is left to
False, this method calls
asyncio.AbstractEventLoop.run_until_complete()in order to wait until all sockets are closed.
Set async to
Trueif the event loop is already running (e.g., because you are in a coroutine). The return value then is a coroutine that you need to
awaitin order to actually shut the container down:
Return the class name for the agent represented by aid if it exists or