Node Monitor v0.6.5

Show:

Connection Class

Extends Backbone.Model
Defined in: lib/Connection.js:25
Module: Monitor

Connection with a remote process

Instances of this class represent a connection with a remote monitor process. The remote process is a peer of this process - it may produce and/or consume probe information.

This is an internal class created when a connection to a server is requested from a monitor, or when an external connection is made from a Server instance.

Constructor

Connection

(
  • model
)

Parameters:

  • model Object
    • Initial data model. Can be a JS object or another Model.
    • [hostName] String optional

      The host name to connect with. Used if url isn't present.

    • [hostPort] Number optional

      The host port to connect using. Used if url isn't present.

    • [url] String optional

      The URL used to connect. Built if hostName is supplied.

    • [socket] Io.socket optional

      Use this pre-connected socket instead of creating a new one.

    • [gateway=false] Boolean optional

      Allow this connection to use me as a gateway? See Router.setGateway()

    • [firewall=false] Boolean optional

      Firewall inbound probe requests on this connection?

    • [remoteHostName] String READONLY optional

      Host name given by the remote server.

    • [remoteAppName] String READONLY optional

      App name given by the remote server.

    • [remoteAppInstance] Integer READONLY optional

      The remote application instance ID running on the host.

    • [remotePID] String READONLY optional

      Remote process ID.

    • [remoteProbeClasses] Array of String READONLY optional

      Array of probe classes available to the remote server.

    • [remoteGateway] Boolean READONLY optional

      Can the remote process act as a gateway?

    • [remoteFirewall] Boolean READONLY optional

      Is the remote side firewalled from inbound probe requests?

Methods

addEvent

(
  • eventName
  • handler
)
protected

Bind the specified handler to the remote socket message.

Only a single handler (per message name) can be bound using this method.

Parameters:

  • eventName String

    The event name to handle

  • handler Function (args..., callback)

    Called when the message is received.

    • args... {Mixed} Arguments sent in by the remote client
    • callback {Function} Final arg if the client specified a callback

disconnect

(
  • reason
)

Disconnect from the remote process

This can be called from the underlying transport if it detects a disconnect, or it can be manually called to force a disconnect.

Parameters:

  • reason String

    Reason for the disconnect

emit

(
  • name
  • args...
  • callback
)
protected

Emit the specified message to the socket.

The other side of the connection can handle and respond to the message using the 'on' method.

Parameters:

  • name String

    The message name to send

  • args... Mixed

    Variable number of arguments to send with the message

  • callback Function

    Called when remote sends a reply

isThisHost

(
  • hostName
)
Boolean protected

Is this connection with the specified host?

Parameters:

  • hostName String

    The host name to check

Returns:

Boolean: withHost True if the connection is with this host

List

(
  • [items]
)
Backbone.Collection static

Constructor for a list of Connection objects

var myList = new Connection.List(initialElements);

Parameters:

  • [items] Array optional

    Initial list items. These can be raw JS objects or Connection data model objects.

Returns:

Backbone.Collection: Collection of Connection data model objects

ping

(
  • callback
)

Ping a remote connection

Parameters:

  • callback Function(error)

    Callback when response is returned

probeConnect

(
  • monitorJSON
  • callback
)
protected

Process an inbound request to connect with a probe

This will fail if this connection was created as a firewall.

Parameters:

  • monitorJSON Object

    Probe connection parameters, including:

    • probeClass String

      The probe class

    • initParams Object

      Probe initialization parameters

    • hostName String

      Connect with this host (if called as a gateway)

    • appName String

      Connect with this app (if called as a gateway)

  • callback Function(error, probeJSON)

    Callback function

probeControl

(
  • params
  • callback
)
protected

Process an inbound control request to a probe

Parameters:

  • params Object

    Control parameters, including: probeId {String} The unique probe id name {String} The control message name params {Object} Any control message parameters

  • callback Function(error, returnParams)

    Callback function

probeDisconnect

(
  • params
  • callback
)
protected

Process an inbound request to disconnect with a probe

Parameters:

  • params Object

    Disconnect parameters, including: probeId {String} The unique probe id

  • callback Function(error)

    Callback function

Events

connect

Connected to remote monitor process

This event is emitted after the two sides of the connection have exchanged information about themselves.

disconnect

Disconnected from a remote monitor process

This event is emitted after the remote connection is disconnected and resources released.

Event Payload:

  • reason String

    Reason for the disconnect

error

An error has occurred on the connection

This event is triggered when an error occurs on the connection. Errors may occur when network is unstable, and can be an indication of impending disconnection.

Event Payload:

  • err Object

    Reason for the error (from underlying transport)