Node Monitor v0.6.5

Show:

Router Class

Extends Backbone.Model
Defined in: lib/Router.js:22
Module: Monitor

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

Router

()

Methods

addConnection

(
  • options
)
Connection protected

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 Boolean

      Firewall inbound probe requests on this connection?

Returns:

Connection: connection - The added connection

addHostConnections

(
  • hostName
  • callback
)
protected

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
)
String protected

Build a probe key from the probe data

Parameters:

  • probeJSON Object
    • An object containing:
    • probeClass String
      • The probe class name (required)
    • initParams Object
      • Probe initialization parameters (if any)

Returns:

String: probeKey - A string identifying the probe

connectExternal

(
  • monitorJSON
  • connection
  • callback
)
protected

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:
    • probeClass String
      • The probe class name (required)
    • initParams Object
      • Probe initialization parameters (if any)
  • connection Connection
    • The connection to use
  • callback Function(error, probeProxy)
    • Called when connected

connectInternal

(
  • monitorJSON
  • callback
)
protected

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.

Parameters:

  • monitorJSON Object
    • The monitor toJSON data. Containing:
    • probeClass String
      • The probe class name to connect with (required)
    • initParams Object
      • Probe initialization parameters.
  • callback Function(error, probeImpl)
    • Called when connected

connectMonitor

(
  • monitor
  • callback
)
protected

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
)
protected

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

disconnectExternal

(
  • connection
  • probeId
  • callback
)
protected

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
)
protected

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
)
protected

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.

Parameters:

  • monitor Monitor
    • The connected monitor
  • reason String
    • Reason for the disconnect
  • callback Function(error)
    • (optional) Called when connected

findConnection

(
  • hostName
  • appName
  • appInstance
)
Connection protected

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:

  • hostName String
    • Host name to find a connection for (null = any host)
  • appName String
    • App name to find a connection with (null = any app)
  • appInstance Any
    • Application instance running on this host (null = any instance)

Returns:

Connection: connection - A Connection object if found, otherwise null

findConnections

(
  • hostName
  • appName
)
Array of Connection protected

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:

  • hostName String
    • Host name to search for (null = any host)
  • appName String
    • App name to search for (null = any app)

Returns:

Array of Connection: connections - An array of Connection objects matching the criteria

getHostName

() String protected

Return a stable host name.

Returns:

String: hostName - The platform's host name, or an otherwise stable ID

removeConnection

(
  • connection
)
protected

Remove a connection from the router.

This is called to remove the connection and associated routes from the router.

Parameters:

setFirewall

(
  • firewall
)
static

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
)
Connection

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:

  • options Object
    • Connection parameters
    • hostName String
      • Name of the gateway host
    • 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 the gateway server.

Returns:

Connection: connection - The connection with the gateway server

setHostName

(
  • hostName
)
protected

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:remove

A connection has been terminated

Event Payload: