2.2.0
A gateway for connecting to a fjage master container. This class provides methods to send and receive messages, subscribe to topics, and manage connections to the master container. It can be used to connect to a fjage master container over WebSockets or TCP.
(Object
= {}
)
Name | Description |
---|---|
opts.hostname string
(default "localhost" )
|
hostname/ip address of the master container to connect to |
opts.port number
(default 1100 )
|
port number of the master container to connect to |
opts.pathname string
(default "" )
|
path of the master container to connect to (for WebSockets) |
opts.keepAlive boolean
(default true )
|
try to reconnect if the connection is lost |
opts.queueSize number
(default 128 )
|
size of the queue of received messages that haven't been consumed yet |
opts.timeout number
(default 10000 )
|
timeout for fjage level messages in ms |
opts.returnNullOnFailedResponse boolean
(default true )
|
return null instead of throwing an error when a parameter is not found |
opts.cancelPendingOnDisconnect boolean
(default false )
|
cancel pending requests on disconnects |
(AgentID)
: agent id of the gateway
(boolean)
: true if the gateway is connected to the master container
Connects to the localhost:1100
const gw = new Gateway({ hostname: 'localhost', port: 1100 });
Connects to the origin
const gw = new Gateway();
Finds an agent that provides a named service. If multiple agents are registered to provide a given service, any of the agents' id may be returned.
(string)
the named service of interest
(number
= opts.timeout
)
timeout in milliseconds
Promise<AgentID?>
:
a promise which returns an agent id for an agent that provides the service when resolved
Flush the Gateway queue for all pending messages. This drops all the pending messages.
void
:
Returns a response message received by the gateway. This method returns a {Promise} which resolves when a response is received or if no response is received after the timeout.
(any)
(number
= 0
)
timeout in milliseconds
Promise<(Message | void)>
:
received response message, null on timeout
Closes the gateway. The gateway functionality may not longer be accessed after this method is called.
void
:
An identifier for an agent or a topic. This can be to send, receive messages, and set or get parameters on an agent or topic on the fjåge master container.
(string)
name of the agent
(boolean
= false
)
name of topic
(Gateway?)
Gateway owner for this AgentID
Sets parameter(s) on the Agent referred to by this AgentID.
(number
= -1
)
index of parameter(s) to be set
(number
= owner.timeout
)
timeout for the response
Promise<(Object | Array<Object>)>
:
a promise which returns the new value(s) of the parameters
Gets parameter(s) on the Agent referred to by this AgentID.
(number
= -1
)
index of parameter(s) to be get
(number
= owner.timeout
)
timeout for the response
Promise<(Object | Array<Object>)>
:
a promise which returns the value(s) of the parameters
Services supported by fjage agents.
An action represented by a message. The performative actions are a subset of the FIPA ACL recommendations for interagent communication.
Type: string
Base class for messages transmitted by one agent to another. Creates an empty message.
(any)
(any
= Performative.INFORM
)
(string)
: unique message ID
(Performative)
: performative of the message
(AgentID?)
: AgentID of the sender of the message
(AgentID?)
: AgentID of the recipient of the message
(string?)
: ID of the message to which this message is a response
(number?)
: timestamp when the message was sent
Creates a unqualified message class based on a fully qualified name.
(string)
fully qualified name of the message class to be created
(any
= Message
)
const ParameterReq = MessageClass('org.arl.fjage.param.ParameterReq');
let pReq = new ParameterReq()
A message that requests one or more parameters of an agent.
Type: Message
(string)
: parameters name to be get/set if only a single parameter is to be get/set
(Object)
: parameters value to be set if only a single parameter is to be set
(Array<ParameterReq.Entry>)
: a list of multiple parameters to be get/set
(number?)
: index of parameter(s) to be set*
Setting a parameter myAgent.x to 42
let req = new ParameterReq({
recipient: myAgentId,
param: 'x',
value: 42
});
Getting the value of myAgent.x
let req = new ParameterReq({
recipient: myAgentId,
param: 'x'
});
Type: Object
A message class that can convey generic messages represented by key-value pairs.
Extends Message
Class representing a fjage's on-the-wire JSON message. A JSONMessage object contains all the fields that can be a part of a fjage JSON message. The class provides methods to create JSONMessage objects from raw strings and to convert JSONMessage objects to JSON strings in the format of the fjage on-the-wire protocol. See fjage documentation for more details on the JSON message format.
Most users will not need to create JSONMessage objects directly, but rather use the Gateway and Message classes to send and receive messages. However, this class can be useful for low-level access to the fjage protocol or for generating/consuming the fjåge protocol messages without having them be transmitted over a network.
(any)
(any)
(string?)
: A UUID assigned to each JSONMessage object.
(string?)
: Denotes the main action the object is supposed to perform.
(string?)
: This attribute contains the action to which this object is a response to.
(AgentID?)
: An AgentID. This attribute is populated in objects which are responses to objects requesting the ID of an agent providing a specific service.
(Array<AgentID>?)
: This attribute is populated in objects which are responses to objects requesting the IDs of agents providing a specific service, or objects which are responses to objects requesting a list of all agents running in a container.
(Array<string>?)
: This attribute is optionally populated in objects which are responses to objects requesting a list of all agents running in a container. If populated, it contains a list of agent types running in the container, with a one-to-one mapping to the agent IDs in the "agentIDs" attribute.
(string?)
: Used in conjunction with "action" : "agentForService" and "action" : "agentsForService" to query for agent(s) providing this specific service.
(Array<string>?)
: This attribute is populated in objects which are responses to objects requesting the services available with "action" : "services".
(boolean?)
: This attribute is populated in objects which are responses to query objects with "action" : "containsAgent".
(Message?)
: This holds the main payload of the message. The structure and format of this object is discussed in the
fjage documentation
.
(boolean?)
: This attribute defines if the target container should relay (forward) the message to other containers it is connected to or not.
(Object?)
: Credentials to be used for authentication.
(Object?)
: Authentication information to be used for the message.
const jsonMsg = new JSONMessage();
jsonMsg.action = 'send';
jsonMsg.message = new Message();
jsonMsg.message.sender = new AgentID('agent1');
jsonMsg.message.recipient = new AgentID('agent2');
jsonMsg.message.perf = Performative.INFORM;
jsonMsg.toJSON(); // Converts to JSON string in the fjage on-the-wire protocol format
const jsonString = '{"id":"1234",...}'; // JSON string representation of a JSONMessage
const jsonMsg = new JSONMessage(jsonString); // Parses the JSON string into a JSONMessage object
jsonMsg.message; // Access the Message object contained in the JSONMessage
Creates a JSONMessage object to send a message.
JSONMessage
:
JSONMessage object with request to send a message
Creates a JSONMessage object to update WantsMessagesFor list.
JSONMessage
:
JSONMessage object with request to update WantsMessagesFor list
Creates a JSONMessage object to request the list of agents.
JSONMessage
:
JSONMessage object with request for the list of agents
Creates a JSONMessage object to check if an agent is contained
(AgentID)
AgentID of the agent to check
JSONMessage
:
JSONMessage object with request to check if the agent is contained
Creates a JSONMessage object to get an agent for a service.
(string)
service which the agent must provide
JSONMessage
:
JSONMessage object with request for an agent providing the service
Creates a JSONMessage object to get all agents for a service.
(string)
service which the agents must provide
JSONMessage
:
JSONMessage object with request for all agent providing the service
A message that is a response to a ParameterReq message.
Type: Message
(string)
: parameters name if only a single parameter value was requested
(Object)
: parameters value if only a single parameter was requested
(Map<string, Object>)
: a map of multiple parameter names and their values if multiple parameters were requested
(number?)
: index of parameter(s) being returned
Receiving a parameter from myAgent
let rsp = gw.receive(ParameterRsp)
rsp.sender // = myAgentId; sender of the message
rsp.param // = 'x'; parameter name that was get/set
rsp.value // = 42; value of the parameter that was set
rsp.readonly // = [false]; indicates if the parameter is read-only
Actions supported by the fjåge JSON message protocol. See fjage documentation for more details.
Type: string