dist/monitor-all.js
function(hostName, callback) {
      var t = this,
          errStr = '',
          connectedPorts = [],
          portStart = Config.Monitor.serviceBasePort,
          portEnd = Config.Monitor.serviceBasePort + Config.Monitor.portsToScan - 1;

      // Create an array to hold callbacks for this host
      if (!t.addHostCallbacks[hostName]) {
        t.addHostCallbacks[hostName] = [];
      }

      // Remember this callback and return if we're already adding connections for this host
      if (t.addHostCallbacks[hostName].push(callback) > 1) {
        return;
      }

      // Called when done
      var doneAdding = function(error) {
        t.addHostCallbacks[hostName].forEach(function(cb) {
          cb(error);
        });
        delete t.addHostCallbacks[hostName];
      };

      // Build the list of ports already connected
      t.connections.each(function(connection){
        var host = connection.get('hostName').toLowerCase();
        var port = connection.get('hostPort');
        if (host === hostName && port >= portStart && port <= portEnd) {
          connectedPorts.push(port);
        }
      });

      // Scan non-connected ports
      var portsToScan = Config.Monitor.portsToScan - connectedPorts.length;
      if (portsToScan === 0) {
        errStr = 'All monitor ports in use.  Increase the Config.Monitor.portsToScan configuration';
        log.error('addHostConnections', errStr);
        return doneAdding(errStr);
      }
      var doneScanning = function() {
        var conn = this; // called in the context of the connection
        conn.off('connect disconnect error', doneScanning);
        if (--portsToScan === 0) {
          return doneAdding();
        }
      };
      for (var i = portStart; i <= portEnd; i++) {
        if (connectedPorts.indexOf(i) < 0) {
          var connection = t.addConnection({hostName:hostName, hostPort:i});
          connection.on('connect disconnect error', doneScanning, connection);
        }
      }
    }
function(hostName, callback) {
      var t = this,
          errStr = '',
          connectedPorts = [],
          portStart = Config.Monitor.serviceBasePort,
          portEnd = Config.Monitor.serviceBasePort + Config.Monitor.portsToScan - 1;

      // Create an array to hold callbacks for this host
      if (!t.addHostCallbacks[hostName]) {
        t.addHostCallbacks[hostName] = [];
      }

      // Remember this callback and return if we're already adding connections for this host
      if (t.addHostCallbacks[hostName].push(callback) > 1) {
        return;
      }

      // Called when done
      var doneAdding = function(error) {
        t.addHostCallbacks[hostName].forEach(function(cb) {
          cb(error);
        });
        delete t.addHostCallbacks[hostName];
      };

      // Build the list of ports already connected
      t.connections.each(function(connection){
        var host = connection.get('hostName').toLowerCase();
        var port = connection.get('hostPort');
        if (host === hostName && port >= portStart && port <= portEnd) {
          connectedPorts.push(port);
        }
      });

      // Scan non-connected ports
      var portsToScan = Config.Monitor.portsToScan - connectedPorts.length;
      if (portsToScan === 0) {
        errStr = 'All monitor ports in use.  Increase the Config.Monitor.portsToScan configuration';
        log.error('addHostConnections', errStr);
        return doneAdding(errStr);
      }
      var doneScanning = function() {
        var conn = this; // called in the context of the connection
        conn.off('connect disconnect error', doneScanning);
        if (--portsToScan === 0) {
          return doneAdding();
        }
      };
      for (var i = portStart; i <= portEnd; i++) {
        if (connectedPorts.indexOf(i) < 0) {
          var connection = t.addConnection({hostName:hostName, hostPort:i});
          connection.on('connect disconnect error', doneScanning, connection);
        }
      }
    }
function ( hostName , callback ) { var t = this , errStr = '' , connectedPorts = [ ] , portStart = Config . Monitor . serviceBasePort , portEnd = Config . Monitor . serviceBasePort + Config . Monitor . portsToScan - 1 ; // Create an array to hold callbacks for this host if ( ! t . addHostCallbacks [ hostName ] ) { t . addHostCallbacks [ hostName ] = [ ] ; } // Remember this callback and return if we're already adding connections for this host if ( t . addHostCallbacks [ hostName ] . push ( callback ) > 1 ) { return ; } // Called when done var doneAdding = function ( error ) { t . addHostCallbacks [ hostName ] . forEach ( function ( cb ) { cb ( error ) ; } ) ; delete t . addHostCallbacks [ hostName ] ; } ; // Build the list of ports already connected t . connections . each ( function ( connection ) { var host = connection . get ( 'hostName' ) . toLowerCase ( ) ; var port = connection . get ( 'hostPort' ) ; if ( host === hostName && port >= portStart && port <= portEnd ) { connectedPorts . push ( port ) ; } } ) ; // Scan non-connected ports var portsToScan = Config . Monitor . portsToScan - connectedPorts . length ; if ( portsToScan === 0 ) { errStr = 'All monitor ports in use.  Increase the Config.Monitor.portsToScan configuration' ; log . error ( 'addHostConnections' , errStr ) ; return doneAdding ( errStr ) ; } var doneScanning = function ( ) { var conn = this ; // called in the context of the connection conn . off ( 'connect disconnect error' , doneScanning ) ; if ( -- portsToScan === 0 ) { return doneAdding ( ) ; } } ; for ( var i = portStart ; i <= portEnd ; i ++ ) { if ( connectedPorts . indexOf ( i ) < 0 ) { var connection = t . addConnection ( { hostName : hostName , hostPort : i } ) ; connection . on ( 'connect disconnect error' , doneScanning , connection ) ; } } }
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.

@method addHostConnections
@protected
@param hostName {String} - The host to add connections with
@param callback {Function(error)} - Called when complete
Add connections for the specified host