Router Class
Probe location and message routing
The router is a class used internally to locate probes and connect events so messages are correctly routed between probes and their monitors.
It is a singleton class, designed to run one instance within
a monitor process, and accessed via the (protected) getRouter()
method of the Monitor object.
It manages all outbound requests to probes, either internally or externally via the Connection to the remote process.
Constructor
Item Index
Methods
Events
Methods
addConnection
-
options
Add a connection to a remote Monitor process
Parameters:
-
options
Object- Connection parameters
-
hostName
String- Name of the host to connect with
-
hostPort
Integer- Port number to connect with
-
url
String- The URL used to connect (created, or used if supplied)
-
socket
Io.socket- Pre-connected socket.io socket to a Monitor server.
-
gateway
Boolean- Allow this connection to use me as a gateway (default false)
-
firewall
BooleanFirewall inbound probe requests on this connection?
Returns:
addHostConnections
-
hostName
-
callback
Add connections for the specified host
This performs a scan of monitor ports on the server, and adds connections for newly discovered servers.
It can take a while to complete, and if called for the same host before completion, it will save the callback and call all callbacks when the original task is complete.
Parameters:
-
hostName
String- The host to add connections with
-
callback
Function(error)- Called when complete
buildProbeKey
-
probeJSON
Build a probe key from the probe data
Parameters:
Returns:
connectExternal
-
monitorJSON
-
connection
-
callback
Connect to an external probe implementation.
This connects with a probe running in another process. It will coordinate the remote instantiation of the probe if it's not running.
Parameters:
-
monitorJSON
Object- An object containing:
-
connection
Connection- The connection to use
-
callback
Function(error, probeProxy)- Called when connected
connectInternal
-
monitorJSON
-
callback
Connect to an internal probe implementation
This connects with a probe running in this process. It will instantiate the probe if it isn't currently running.
connectMonitor
-
monitor
-
callback
Connect a Monitor object to a remote Probe
This accepts an instance of a Monitor and figures out how to connect it to a running Probe.
Upon callback the probe data is set into the monitor (unless an error occurred)
Parameters:
-
monitor
Monitor- The monitor requesting to connect with the probe
-
callback
Function(error)- (optional) Called when connected
determineConnection
-
monitorJSON
-
makeNewConnections
-
callback
Determine the connection to use for a probe
This uses the connection parameters of the specified monitor to determine (or create) the connection to use for the probe.
If the probe can be instantiated internally, a null is returned as the connection.
This attempts to use an existing connection if available. If not, a connection attempt will be made with the host. If the host cannot be reached directly, it returns a connection with the gateway.
Parameters:
-
monitorJSON
Object- The connection attributes of the monitor
-
makeNewConnections
Boolean- Establish a new connection if one doesn't exist?
-
callback
Function(error, connection)- Called when the connection is known
- error - Set if any errors
- connection - The connection object, or null to run in this process
- Called when the connection is known
disconnectExternal
-
connection
-
probeId
-
callback
Disconnect with an external probe implementation.
Parameters:
-
connection
Connection- The connection to use
-
probeId
String- Probe ID
-
callback
Function(error)- Called when disconnected
disconnectInternal
-
probeId
-
callback
Disconnect with an internal probe implementation.
Parameters:
-
probeId
String- The probe implementation ID to disconnect
-
callback
Function(error, probeImpl)- Called when disconnected
disconnectMonitor
-
monitor
-
reason
-
callback
Disconnect a monitor
This accepts an instance of a connected monitor, and disconnects it from the remote probe.
The probe implementation will be released if this is the only monitor object watching it.
findConnection
-
hostName
-
appName
-
appInstance
Find an existing connection to use
This method looks into the existing known connections to find one that matches the specified parameters.
Firewalled connections are not returned.
Parameters:
Returns:
findConnections
-
hostName
-
appName
Find all connections matching the selection criteria
This method looks into the existing known connections to find all that match the specified parameters.
Firewalled connections are not returned.
Parameters:
Returns:
getHostName
()
String
protected
Return a stable host name.
Returns:
removeConnection
-
connection
Remove a connection from the router.
This is called to remove the connection and associated routes from the router.
Parameters:
-
connection
Connection- The connection to remove
setFirewall
-
firewall
Firewall new connections from inbound probe requests
When two monitor processes connect, they become peers. By default each process can request probe connections with the other.
If you want to connect with a remote probe, but don't want those servers to connect with probes in this process, call this method to firewall those inbound probe requests.
Setting this will change the firewall value for all new connections. Any existing connections will still accept incoming probe requests.
Parameters:
-
firewall
Boolean- Firewall new connections?
setGateway
-
options
Set the default gateway server
The gateway server is used if a monitor cannot connect directly with the server hosting the probe.
When a monitor is requested to connect with a probe on a specific server, a direct connection is attempted. If that direct connection fails, usually due to a firewall or browser restriction, the monitor will attempt the connection to the probe through the gateway server.
The server specified in this method must have been started as a gateway like this:
// Start a monitor server and act as a gateway
var server = new Monitor.Server({gateway:true});
Parameters:
Returns:
setHostName
-
hostName
Set the current host name.
This sets the host name that this router publishes to new connections. It's only useful if the os hostname isn't the name you want to publish.
Parameters:
-
hostName
String- The host name to publish to new connections
Events
connection:add
A new connection has been established
Event Payload:
-
connection
ConnectionThe added connection
connection:remove
A connection has been terminated
Event Payload:
-
connection
ConnectionThe removed connection