2.4.0A 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 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 |
(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();
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.
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.directoryTimeout)
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.
(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.
(any)
(any)
(string)
: unique message ID
(Performative)
: performative of the message
((AgentID | null))
: AgentID of the sender
((AgentID | null))
: AgentID of the recipient
((string | null))
: ID of the message being replied to
(number?)
: timestamp when the message was sent, set by the container on receipt
Create a message from a parsed JSON representation.
(MessageJSON)
parsed message JSON
Message:
message created from the JSON object
Type: Performative
Convert a message into an object for JSON serialization.
MessageJSON:
JSON representation of the message
Gateway.registerMessage()
instead.
Creates an unqualified message class based on a fully qualified name.
Function:
message class
A message that requests one or more parameters of an agent.
Extends Message
Type: Object
(string)
: parameter name
(any?)
: parameter value
A message class that can convey generic key-value messages.
Extends Message
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.
(string)
qualified or unqualified message class name
(Function | undefined):
registered message class
Registers a message class for JSON serialization and inflation.
(string)
fully qualified message class name
(Function)
Message subclass to register
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.
(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 request the list of services.
JSONMessage:
JSONMessage object with request for the list of services
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
Type: Object
A message that responds to a ParameterReq.
Extends Message
Request to write contents to a file, or delete a file.
Extends Message
Request to delete a file or directory.
Extends Message
Request to read a file or directory.
Extends Message
Actions supported by the fjåge JSON message protocol. See fjage documentation for more details.
Type: string
Response to a GetFileReq.
Extends Message
Request to execute a shell command or script.
Extends Message