fjagepy package
- class fjagepy.AgentID(name, topic=False, owner=None)[source]
Bases:
objectAn identifier for an agent or a topic. This can be used to send, receive messages, and set or get parameters on an agent or topic on the fjåge container. The AgentID is typically owned by a Gateway which is used to send and receive messages.
The AgentID object can be used to set and get parameters on the agent using dot notation. For example, to get the value of a parameter named “param” on an agent represented by an AgentID object aid, you can use value = aid.param. To set the value of the parameter, you can use aid.param = value. If the parameter is indexed, you can use aid[index].param to refer to the indexed parameter. For example, aid[1].param refers to the first indexed parameter “param” of the agent.
- Parameters:
name (str) – name of the agent
topic (bool) – True if this represents a topic. Defaults to False.
owner (Optional['Gateway']) – Gateway owner for this AgentID. Defaults to None.
- get(index=-1)[source]
Gets the values of all parameters on the agent.
- Parameters:
index (int | None) – index for indexed parameters. Defaults to -1 (no index).
- Returns:
dictionary of all parameters and their values
- Return type:
dict
- Raises:
RuntimeError – if this AgentID has no owner (unowned AgentID cannot get parameters)
- get_name()[source]
Gets the name of the agent or topic.
- Returns:
name of agent or topic
- Return type:
str
- is_topic()[source]
Returns True if the agent id represents a topic.
- Returns:
True if the agent id represents a topic, False if it represents an agent
- Return type:
bool
- class fjagepy.Gateway(hostname='localhost', port=1100, connector=<class 'fjagepy.TCPConnector.TCPConnector'>, reconnect=True, timeout=1000, directory_timeout=6000)[source]
Bases:
objectA Gateway is used to connect to a fjåge container and send and receive messages, query for agents and services, and set or get parameters on agents from Python.
The Gateway class provides methods for sending and receiving messages, subscribing to topics, and querying for agents and services. It uses a Connector to handle the underlying communication with the fjåge container.
The Gateway is thread-safe and can be used from multiple threads. It maintains an internal message queue with a configurable maximum size (default 512 messages). A gw.receive() call will first check the internal queue for a matching message before blocking for new messages.
The Gateway can be used as a context manager to ensure proper cleanup of resources.
- Parameters:
hostname (str)
port (int)
connector (Type[Connector])
reconnect (bool)
timeout (int)
directory_timeout (int)
- BLOCKING = -1
- NON_BLOCKING = 0
- agentForService(service, timeout=None)[source]
Finds an agent that provides the given service.
- Parameters:
service (str | Enum)
timeout (int | None)
- Return type:
AgentID | None
- agent_for_service(service, timeout=None)[source]
A python style method name for agentForService()
- Parameters:
service (str | Enum)
timeout (int | None)
- Return type:
AgentID | None
- agents(timeout=None)[source]
Gets the list of all agents connected to the fjage container
- Parameters:
timeout (int | None)
- Return type:
list[AgentID]
- agentsForService(service, timeout=None)[source]
Retrieves a list of all agents that provide the given service.
- Parameters:
service (str | Enum)
timeout (int | None)
- Return type:
list[AgentID]
- agents_for_service(service, timeout=None)[source]
A python style method name for agentsForService()
- Parameters:
service (str | Enum)
timeout (int | None)
- Return type:
list[AgentID]
- containsAgent(agentID, timeout=None)[source]
Checks if the given agent is connected to the fjage container
- Parameters:
agentID (AgentID)
timeout (int | None)
- Return type:
bool
- contains_agent(agentID, timeout=None)[source]
A python style method name for containsAgent()
- Parameters:
agentID (AgentID)
timeout (int | None)
- Return type:
bool
- getAgentID()[source]
Java style method name for agent_id()
Deprecated since version 2.0.0: Use
agent_id()instead.- Return type:
- isConnected()[source]
Java style method name for is_connected()
Deprecated since version 2.0.0: Use
is_connected()instead.- Return type:
bool
- is_connected()[source]
Returns True if the gateway is connected to the fjage container.
- Returns:
True if connected, False otherwise
- Return type:
bool
- send(msg)[source]
Sends a message to the fjage container.
- Parameters:
msg (Message) – message to send
- Return type:
None
- services(timeout=None)[source]
Gets the list of all services provided by agents connected to the fjage container
- Parameters:
timeout (int | None)
- Return type:
list[str]
- subscribe(topic)[source]
Subscribes to the given topic.
- Parameters:
topic (AgentID)
- Return type:
bool
- class fjagepy.GetFileReq(filename=None, offset=0, length=0, **kwargs)[source]
Bases:
Message- Parameters:
filename (str | None)
offset (int)
length (int)
- filename: str | None
- length: int
- offset: int
- class fjagepy.GetFileRsp(filename=None, offset=0, contents=None, directory=False, **kwargs)[source]
Bases:
Message- Parameters:
filename (str | None)
offset (int)
contents (list[int] | None)
directory (bool)
- class fjagepy.JSONMessage(json_str=None, owner=None)[source]
Bases:
objectA JSONMessage is used to create and parse the on-the-wire JSON based protocol used by fjåge containers. It can be used to send and receive messages, query for agents and services, and set or get parameters on agents. The JSONMessage class provides static factory methods for creating common types of JSON messages and also can parse a JSON string into a JSONMessage object.
- Parameters:
json_str (str | None)
- class fjagepy.Message(in_reply_to_msg=None, perf=Performative.INFORM, **kwargs)[source]
Bases:
objectBase class for messages transmitted by one agent to another.
- Parameters:
in_reply_to_msg (Message | None)
perf (Performative)
- inReplyTo: str | None
- msgID: str
- perf: Performative
- sentAt: int | None
- fjagepy.MessageClass(name, parent=<class 'fjagepy.Message.Message'>)[source]
Creates an unqualified message class based on a fully qualified name.
- class fjagepy.ParameterReq(index=-1, **kwargs)[source]
Bases:
Message- Parameters:
index (int)
- get(param)[source]
Request a parameter by name.
- Parameters:
param (str) – name of the parameter to request
- index: int
- param: str | None
- perf: Performative
- requests: list[dict]
- set(param, value)[source]
Set a parameter value.
- Parameters:
param (str) – name of the parameter to set
value – value to set the parameter to
- value: Any | None
- class fjagepy.ParameterRsp(**kwargs)[source]
Bases:
Message- get(param)[source]
Get the value of a parameter by name from the response.
- Parameters:
param (str) – name of the parameter to get
- Returns:
value of the parameter, or None if not found
- index: int
- param: str | None
- parameters()[source]
Get all parameters in the response as a dictionary.
- Return type:
dict[str, Any]
- perf: Performative
- value: Any | None
- values: dict | None
- class fjagepy.Performative(*values)[source]
Bases:
Enum- AGREE = 'AGREE'
- CANCEL = 'CANCEL'
- CFP = 'CFP'
- CONFIRM = 'CONFIRM'
- DISCONFIRM = 'DISCONFIRM'
- FAILURE = 'FAILURE'
- INFORM = 'INFORM'
- NOT_UNDERSTOOD = 'NOT_UNDERSTOOD'
- PROPOSE = 'PROPOSE'
- QUERY_IF = 'QUERY_IF'
- REFUSE = 'REFUSE'
- REQUEST = 'REQUEST'
- class fjagepy.PutFileReq(filename=None, contents=None, offset=0, **kwargs)[source]
Bases:
Message- Parameters:
filename (str | None)
contents (list[int] | None)
offset (int)
- contents: list[int] | None
- filename: str | None
- offset: int
- class fjagepy.Services[source]
Bases:
object- DOCUMENTATION = 'org.arl.fjage.shell.Services.DOCUMENTATION'
- SHELL = 'org.arl.fjage.shell.Services.SHELL'
- class fjagepy.ShellExecReq(command=None, script=None, scriptArgs=None, ans=False, **kwargs)[source]
Bases:
Message- Parameters:
command (str | None)
script (str | None)
scriptArgs (list[str] | None)
ans (bool)
- ans: bool
- command: str | None
- script: str | None
- scriptArgs: list[str] | None