academy.exchange.cloud.client¶
HttpExchange
¶
HttpExchange(
host: str,
port: int,
additional_headers: dict[str, str] | None = None,
scheme: Literal["http", "https"] = "http",
ssl_verify: str | bool | None = None,
)
Bases: ExchangeMixin
Http exchange client.
Parameters:
-
host
(str
) –Host name of the exchange server.
-
port
(int
) –Port of the exchange server.
-
additional_headers
(dict[str, str] | None
, default:None
) –Any other information necessary to communicate with the exchange. Used for passing the Globus bearer token
-
scheme
(Literal['http', 'https']
, default:'http'
) –HTTP scheme, non-protected "http" by default.
-
ssl_verify
(str | bool | None
, default:None
) –Same as requests.Session.verify. If the server's TLS certificate should be validated. Should be true if using HTTPS Only set to false for testing or local development.
Source code in academy/exchange/cloud/client.py
close
¶
register_agent
¶
register_agent(
behavior: type[BehaviorT],
*,
agent_id: AgentId[BehaviorT] | None = None,
name: str | None = None
) -> AgentId[BehaviorT]
Create a new agent identifier and associated mailbox.
Parameters:
-
behavior
(type[BehaviorT]
) –Type of the behavior this agent will implement.
-
agent_id
(AgentId[BehaviorT] | None
, default:None
) –Specify the ID of the agent. Randomly generated default.
-
name
(str | None
, default:None
) –Optional human-readable name for the agent. Ignored if
agent_id
is provided.
Returns:
-
AgentId[BehaviorT]
–Unique identifier for the agent's mailbox.
Source code in academy/exchange/cloud/client.py
register_client
¶
Create a new client identifier and associated mailbox.
Parameters:
-
name
(str | None
, default:None
) –Optional human-readable name for the client.
Returns:
-
ClientId
–Unique identifier for the client's mailbox.
Source code in academy/exchange/cloud/client.py
terminate
¶
terminate(uid: EntityId) -> None
Close the mailbox for an entity from the exchange.
Note
This method is a no-op if the mailbox does not exists.
Parameters:
-
uid
(EntityId
) –Entity identifier of the mailbox to close.
Source code in academy/exchange/cloud/client.py
discover
¶
Discover peer agents with a given behavior.
Warning
Discoverability is not implemented on the HTTP exchange.
Parameters:
-
behavior
(type[Behavior]
) –Behavior type of interest.
-
allow_subclasses
(bool
, default:True
) –Return agents implementing subclasses of the behavior.
Returns:
Source code in academy/exchange/cloud/client.py
get_mailbox
¶
get_mailbox(uid: EntityId) -> HttpMailbox
Get a client to a specific mailbox.
Parameters:
-
uid
(EntityId
) –EntityId of the mailbox.
Returns:
-
HttpMailbox
–Mailbox client.
Raises:
-
BadEntityIdError
–if a mailbox for
uid
does not exist.
Source code in academy/exchange/cloud/client.py
send
¶
Send a message to a mailbox.
Parameters:
Raises:
-
BadEntityIdError
–if a mailbox for
uid
does not exist. -
MailboxClosedError
–if the mailbox was closed.
Source code in academy/exchange/cloud/client.py
get_handle
¶
get_handle(
aid: AgentId[BehaviorT],
) -> UnboundRemoteHandle[BehaviorT]
Create a new handle to an agent.
A handle enables a client to invoke actions on the agent.
Note
It is not possible to create a handle to a client since a handle is essentially a new client of a specific agent.
Parameters:
-
aid
(AgentId[BehaviorT]
) –EntityId of the agent to create an handle to.
Returns:
-
UnboundRemoteHandle[BehaviorT]
–Handle to the agent.
Raises:
Source code in academy/exchange/__init__.py
HttpMailbox
¶
HttpMailbox(uid: EntityId, exchange: HttpExchange)
Client interface to a mailbox hosted in an HTTP exchange.
Parameters:
-
uid
(EntityId
) –EntityId of the mailbox.
-
exchange
(HttpExchange
) –Exchange client.
Raises:
-
BadEntityIdError
–if a mailbox with
uid
does not exist.
Source code in academy/exchange/cloud/client.py
close
¶
Close this mailbox client.
Warning
This does not close the mailbox in the exchange. I.e., the exchange will still accept new messages to this mailbox, but this client will no longer be listening for them.
Source code in academy/exchange/cloud/client.py
recv
¶
Receive the next message in the mailbox.
This blocks until the next message is received or the mailbox is closed.
Parameters:
-
timeout
(float | None
, default:None
) –Optional timeout in seconds to wait for the next message. If
None
, the default, block forever until the next message or the mailbox is closed.
Raises:
-
MailboxClosedError
–if the mailbox was closed.
-
TimeoutError
–if a
timeout
was specified and exceeded.
Source code in academy/exchange/cloud/client.py
spawn_http_exchange
¶
spawn_http_exchange(
host: str = "0.0.0.0",
port: int = 5463,
*,
level: int | str = WARNING,
timeout: float | None = None
) -> Generator[HttpExchange]
Context manager that spawns an HTTP exchange in a subprocess.
This function spawns a new process (rather than forking) and wait to
return until a connection with the exchange has been established.
When exiting the context manager, SIGINT
will be sent to the exchange
process. If the process does not exit within 5 seconds, it will be
killed.
Warning
The exclusion of authentication and ssl configuration is intentional. This method should only be used for temporary exchanges in trusted environments (i.e. the login node of a cluster).
Parameters:
-
host
(str
, default:'0.0.0.0'
) –Host the exchange should listen on.
-
port
(int
, default:5463
) –Port the exchange should listen on.
-
level
(int | str
, default:WARNING
) –Logging level.
-
timeout
(float | None
, default:None
) –Connection timeout when waiting for exchange to start.
Returns:
-
Generator[HttpExchange]
–Exchange interface connected to the spawned exchange.