fjage

2.4.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.

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 1000) default timeout for request() in ms
opts.directoryTimeout number (default 6000) default timeout for directory queries in ms
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();

Every construction opens a new connection to the master container, even if one already
exists to the same master. Applications that want a shared connection should construct
one gateway and reuse it, rather than constructing a second one.
Static Members
registerMessage(className, messageClass)
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)
services(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.

new Message(inReplyToMsg: any, perf: any)
Parameters
inReplyToMsg (any)
perf (any)
Properties
msgID (string) : unique message ID
perf (Performative) : performative of the message
sender ((AgentID | null)) : AgentID of the sender
recipient ((AgentID | null)) : AgentID of the recipient
inReplyTo ((string | null)) : ID of the message being replied to
sentAt (number?) : timestamp when the message was sent, set by the container on receipt
Static Members
fromJSON(jsonObj)
Instance Members
sender
recipient
inReplyTo
toString()
toJSON()
new MessageClass(name: string, parent: Function?): Function
Deprecated: since version 3.0.0. Use Gateway.registerMessage() instead.

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

Parameters
name (string) fully qualified message class name
parent (Function? = Message) parent Message class
Returns
Function: message class

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

new ParameterReq()

Extends Message

Instance Members

ParameterReq.Entry

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

Type: Object

Properties
param (string) : parameter name
value (any?) : parameter value

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

new GenericMessage()

Extends Message

messageClassForName

gateways/js/src/message.js

Gets a registered message class by name. Message classes are registered under both their qualified and unqualified names, so either will resolve, but a qualified name never falls back to a class registered for the same unqualified name in a different package.

messageClassForName(name: string): (Function | undefined)
Parameters
name (string) qualified or unqualified message class name
Returns
(Function | undefined): registered message class

registerMessageClass

gateways/js/src/message.js

Registers a message class for JSON serialization and inflation.

registerMessageClass(className: string, messageClass: Function): Function
Parameters
className (string) fully qualified message class name
messageClass (Function) Message subclass to register
Returns
Function: registered message class

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()
createServices()
createContainsAgent(agentID)
createAgentForService(service)
createAgentsForService(service)
Instance Members
toJSON()
MessageJSON

Type: Object

Properties
clazz (string) : qualified or unqualified message class name
data (Object<string, any>) : message data

A message that responds to a ParameterReq.

new ParameterRsp()

Extends Message

Instance Members

Request to write contents to a file, or delete a file.

new PutFileReq()

Extends Message

Instance Members
filename
contents

Request to delete a file or directory.

new DeleteFileReq()

Extends Message

Instance Members
filename

Request to read a file or directory.

new GetFileReq()

Extends Message

Instance Members
filename

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

Response to a GetFileReq.

new GetFileRsp()

Extends Message

Instance Members
filename
contents
directory

Request to execute a shell command or script.

new ShellExecReq()

Extends Message

Instance Members