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.

new Gateway(opts: Object)
Parameters
opts (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
Properties
aid (AgentID) : agent id of the gateway
connected (boolean) : true if the gateway is connected to the master container
debug (boolean) : true if debug messages should be logged to the console

Constructor arguments:

Example

Connects to the localhost:1100

const gw = new Gateway({ hostname: 'localhost', port: 1100 });

Connects to the origin

const gw = new Gateway();
Instance Members
addEventListener(type, listener)
removeEventListener(type, listener)
addMessageListener(listener)
removeMessageListener(listener)
addConnListener(listener)
removeConnListener(listener)
getAgentID()
agent(name)
topic(topic, topic2?)
subscribe(topic)
unsubscribe(topic)
agents(timeout)
containsAgent(agentID, timeout)
agentForService(service, timeout)
agentsForService(service, timeout)
send(msg)
flush()
request(msg, timeout)
receive(filter, timeout)
close()

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.

new AgentID(name: string, topic: boolean, owner: Gateway?)
Parameters
name (string) name of the agent
topic (boolean = false) name of topic
owner (Gateway?) Gateway owner for this AgentID
Static Members
fromJSON(json, owner?)
Instance Members
getName()
isTopic()
send(msg)
request(msg, timeout)
toString()
toJSON()
set(params, values, index, timeout)
get(params, index, timeout)

Services supported by fjage agents.

Services
Static Members

An action represented by a message. The performative actions are a subset of the FIPA ACL recommendations for interagent communication.

Performative

Type: string

Static Members

Base class for messages transmitted by one agent to another. Creates an empty message.

new Message(inReplyToMsg: any, perf: any)
Parameters
inReplyToMsg (any)
perf (any = Performative.INFORM)
Properties
msgID (string) : unique message ID
perf (Performative) : performative of the message
sender (AgentID?) : AgentID of the sender of the message
recipient (AgentID?) : AgentID of the recipient of the message
inReplyTo (string?) : ID of the message to which this message is a response
sentAt (number?) : timestamp when the message was sent
Static Members
fromJSON(jsonObj)
Instance Members
toString()
toJSON()

Creates a unqualified message class based on a fully qualified name.

new MessageClass(name: string, parent: any)
Parameters
name (string) fully qualified name of the message class to be created
parent (any = Message)
Example
const ParameterReq = MessageClass('org.arl.fjage.param.ParameterReq');
let pReq = new ParameterReq()

A message that requests one or more parameters of an agent.

ParameterReq

Type: Message

Properties
param (string) : parameters name to be get/set if only a single parameter is to be get/set
value (Object) : parameters value to be set if only a single parameter is to be set
requests (Array<ParameterReq.Entry>) : a list of multiple parameters to be get/set
index (number?) : index of parameter(s) to be set*
Example

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'
});

ParameterReq.Entry

gateways/js/src/message.js
ParameterReq.Entry

Type: Object

Properties
param (string) : parameter name
value (Object) : parameter value

A message class that can convey generic messages represented by key-value pairs.

new GenericMessage()

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.

new JSONMessage(jsonString: any, owner: any)
Parameters
jsonString (any)
owner (any)
Properties
id (string?) : A UUID assigned to each JSONMessage object.
action (string?) : Denotes the main action the object is supposed to perform.
inResponseTo (string?) : This attribute contains the action to which this object is a response to.
agentID (AgentID?) : An AgentID. This attribute is populated in objects which are responses to objects requesting the ID of an agent providing a specific service.
agentIDs (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.
agentTypes (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.
service (string?) : Used in conjunction with "action" : "agentForService" and "action" : "agentsForService" to query for agent(s) providing this specific service.
services (Array<string>?) : This attribute is populated in objects which are responses to objects requesting the services available with "action" : "services".
answer (boolean?) : This attribute is populated in objects which are responses to query objects with "action" : "containsAgent".
message (Message?) : This holds the main payload of the message. The structure and format of this object is discussed in the fjage documentation .
relay (boolean?) : This attribute defines if the target container should relay (forward) the message to other containers it is connected to or not.
creds (Object?) : Credentials to be used for authentication.
auth (Object?) : Authentication information to be used for the message.
Example
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
Static Members
createSend(msg, relay)
createWantsMessagesFor(agentIDs)
createAgents()
createContainsAgent(agentID)
createAgentForService(service)
createAgentsForService(service)
Instance Members
toJSON()

A message that is a response to a ParameterReq message.

ParameterRsp

Type: Message

Properties
param (string) : parameters name if only a single parameter value was requested
value (Object) : parameters value if only a single parameter was requested
values (Map<string, Object>) : a map of multiple parameter names and their values if multiple parameters were requested
readonly (Array<boolean>) : a list of booleans indicating if the parameters are read-only
index (number?) : index of parameter(s) being returned
Example

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.

Actions

Type: string

Static Members
CONTAINS_AGENT
AGENT_FOR_SERVICE
AGENTS_FOR_SERVICE
WANTS_MESSAGES_FOR