Injector component. Emits 'connect' when at least one server is connected.
969269
function Injector(conf) {
  component.Component.call(this, 'injector', conf);
  var that = this;
  this._default_controller = defaults.controllerfuncname(conf);
  this._dbconn = conf.dbconn;
  this.registerGearman(conf.servers, {
    worker: {
      func_name: 'submitJobDelayed',
      func: function(payload, worker) {
        var task;
        try {
          task = JSON.parse(payload);
        } catch (err) {
          that._err('Error:', err.message);
          worker.done(that.component_name + ': ' + err.message);
          return;
        }

        that._info('Received a task for',
            (task.controller || that._default_controller) +
            '/' + task.func_name);
        // TODO: Properly abstract date handling into lib/gearsloth.js and handle
        // invalid dates etc.
        if ('at' in task) {
          task.at = new Date(task.at);
          if (isNaN(task.at.getTime())) {
            worker.done(that.component_name + ': invalid date format.');
            return;
          }
        }
        if ('after' in task && isNaN(task.after)) {
          worker.done(that.component_name + ': invalid \'after\' format.');
          return;
        }
        if (! ('func_name' in task)) {
          worker.done(that.component_name +
              ': no function name (func_name) defined in task.');
          return;
        }
        that.inject(task, worker);
      }
    }
  });
}
1053015
public void init (Injector injector)
        throws Exception
    {
        // output general system information
        SystemInfo si = new SystemInfo();
        log.info("Starting up", "server", getClass().getSimpleName(), "os", si.osToString(),
            "jvm", si.jvmToString());

        registerSignalHandlers(injector);

        // initialize our deprecated legacy static references
        omgr = _omgr;
        invmgr = _invmgr;

        // configure the dobject manager with our access controller
        _omgr.setDefaultAccessController(createDefaultObjectAccessController());

        // start the main and auth invoker threads
        ((PresentsInvoker)_invoker).start(this);
        _authInvoker.start();
        ((PresentsInvoker)_invoker).addInterdependentInvoker(_authInvoker);

        // provide our client manager with the injector it needs
        _clmgr.setInjector(injector);

        // Create our socket opening objects now that we know what ports we're using.
        _lifecycle.addComponent(_socketAcceptor = createSocketAcceptor());
        _datagramReader =
            new DatagramChannelReader(getDatagramHostname(), getDatagramPorts(), _conmgr);
        _lifecycle.addComponent(_datagramReader);

        // initialize the time base services
        TimeBaseProvider.init(_invmgr, _omgr);

        // make the client manager shut down before the invoker and dobj threads; this helps
        // application code to avoid long chains of shutdown constraints
        _lifecycle.addShutdownConstraint(
            _clmgr, Lifecycle.Constraint.RUNS_BEFORE, (PresentsInvoker)_invoker);

        // initialize all of our registered components
        _lifecycle.init();
    }
1307741
function Server(server, options)
{
	events.EventEmitter.call(this);
	
	this.listen = function(options, callback) {
		server.listen(options, callback);
	};
	
	server.on('connection', (socket) => {
		options = options || {};
		options.isServer = true;
		this.emit('client', new Client(socket, options));
	});
}
1366074
function injectBefore(replServer, method, beforeFn) {
  var _orig = replServer[method];
  replServer[method] = function() {
    var args = Array.prototype.slice.call(arguments);
    var callback = args.pop();
    beforeFn.apply(null, args.concat(function(err, res) {
      if (err || res) {
        callback(err, res);
      } else {
        _orig.apply(replServer, args.concat(callback));
      }
    }));
  };
  return replServer;
}
1108546
function(id, socket) {
  EventEmitter.call(this);
  this.id = id;
  this.socket = socket;
  this.remoteAddress = {
    ip: socket.handshake.address.address,
    port: socket.handshake.address.port
  };

  var self = this;

  socket.on('disconnect', this.emit.bind(this, 'disconnect'));

  socket.on('error', this.emit.bind(this, 'error'));

  socket.on('message', function(msg) {
    self.emit('message', msg);
  });

  this.state = ST_INITED;

  // TODO: any other events?
}
153870
def on_connect(self, client, userdata, flags, result_code):
        
        self.log_info("Connected with result code {}".format(result_code))
        self.state_handler.set_state(State.welcome)
955608
function scheduleServerConnectivityChecks() {
        if (connectivityIntervalId === null) {
            connectivityIntervalId = asyncExecService.setInterval(function () {
                updateRegistrations();
                connectToServers();
            }, INTERVAL_BETWEEN_SERVER_CONNECTIVITY_CHECKS);
        }
        else {
            throw new Error("BUG ::: Attempt was made to start connectivity checks twice");
        }
    }
748957
def _connected(self, sock):
        """"""
        logger.debug('socket connected, building protocol')
        self.protocol = self.factory.build(self.loop)
        self.connection = Connection(self.loop, self.sock, self.addr,
            self.protocol, self) 
        self.connector = None
        self.connect_deferred.callback(self.protocol)
80019
@Ready
    public void onReady(/* In you don't want injection AtmosphereResource r */) {
        logger.info("Browser {} connected", r.uuid());
        logger.info("BroadcasterFactory used {}", factory.getClass().getName());
        logger.info("Broadcaster injected {}", broadcaster.getID());

    }
1223580
function(connect, callback) {
      callback = callback || function(){};
      var t = this,
          needsConnecting = false,
          logMethod = (connect ? 'connectMonitor' : 'disconnectMonitor'),
          originalParams = null,
          monitor = t.model.get('monitor'),
          isConnected = monitor.isConnected();

      // Determine if we need to connect/disconnect
      if (
          (connect && !isConnected && monitor.get('probeClass')) ||
          (!connect && isConnected)) {
        needsConnecting = true;
      }

      // If no need to connect, callback on next tick.  This makes the
      // call stack consistent regardless of the presence of monitors.
      if (!needsConnecting) {
        log.info(logMethod + '.alreadyConnected', t.logCtxt);
        setTimeout(function(){
          callback(null);
        },0);
        return;
      }

      // If connecting, override the init params with url params
      if (connect) {
        originalParams = monitor.get('initParams');
        monitor.set(
          {initParams: _.extend({}, originalParams, initOverrides)},
          {silent: true}
        );
      }
      else {
        // If disconnecting, remove all change listeners
        monitor.off('change');
      }

      // Connect or disconnect, calling the callback when done
      var connectFn = connect ? 'connect' : 'disconnect';
      log.info(logMethod, t.logCtxt);
      monitor[connectFn](function(error) {

        // Replace original initParams (so the page isn't dirty)
        // Acutal init params will become attributes of the monitor object
        if (originalParams) {
          monitor.set(
            {initParams: originalParams},
            {silent: true}
          );
        }

        // If disconnecting, clear the probe data
        if (!connect) {
          var probeElems = monitor.toProbeJSON();
          delete probeElems.id;
          monitor.set(probeElems, {unset:true});
        }

        // Callback passing error if set
        return callback(error);
      });
    }
346819
function ServiceFactory(injector) {
    this.cache = {};
    this.injector = injector || {};

    // if we are in debug mode, then add the debug handler
    var pattern = this.injector.debugPattern || '*.*.*.*.*';
    var handler = this.injector.debugHandler || debugHandler;
    if (this.injector.debug) {
        eventBus.on(pattern, handler);
    }
}
288821
function Connector(src, onconnect) {
  events.EventEmitter.call(this);

  this.src = src;

  this.once('result', function (err, socket) {
    socket.removeAllListeners('error');
    if (err) {
      this.emit('prefailed', err);
      this.emit('failed', err);
    } else {
      this.emit('preready', socket);
      this.emit('ready', socket);
    }
  }).on('ready', function (socket) {
    onconnect(socket);
  }).on('failed', function (err) {
    src.emit('error', err);
  });
}
187741
void onConnect(BootstrapServer server) {
        // store selected server
        new BootstrapServerStore().storeSelection(server);

        if (dialog != null) {
            dialog.hide();
            LoadingPanel.get().on();
        }
        String serverUrl = getServerUrl(server);
        context.setSameOrigin(serverUrl.equals(getBaseUrl()));
        if (!serverUrl.endsWith("/")) {
            serverUrl += "/";
        }

        // Trigger authentication using a hidden iframe. This way also Safari will show the login dialog
        setUrls(serverUrl);
        andThen.execute();
    }
678310
private void signalConnected() {
        if (alternate != null) {
            LOGGER.info("Connected to Node {} ({})",
                system(hostname.nameAndAddress()), system(alternate.nameAndAddress()));
        } else {
            LOGGER.info("Connected to Node {}", system(hostname.nameAndAddress()));
        }
        if (eventBus != null && eventBus.hasSubscribers()) {
            eventBus.publish(new NodeConnectedEvent(hostname));
        }
    }
1372658
def onConnect(self, client, userdata, flags, rc):
        
        for sub in self.subsciption:
            (result, mid) = self.client.subscribe(sub)
239095
function Remote(server, socket, version, maxFrameSize, encoder, decoder, delay) {

    // Events
    Emitter.call(this);

    // Internals
    this._server = server;
    this._socket = socket;
    this._isPending = true;

    // Public properties
    this.id = socket.remoteAddress + ':' + socket.remotePort;
    this.address = socket.remoteAddress;
    this.port = socket.remotePort;
    this.bytesSend = 0;
    this.bytesReceived = 0;
    this.version = version;
    this.delay = delay || 0;

    // Protocol
    this._encoder = encoder;
    this._decoder = decoder;
    this._protocol = Protocol(this, socket, version, maxFrameSize);
    Protocol.bind(this._protocol, this, socket, this.delay);
    this._protocol.init();

}
926352
function(port, host, opts) {
  if (!(this instanceof Connector)) {
    return new Connector(port, host, opts);
  }

  EventEmitter.call(this);

  this.opts = opts || {};
  this.port = port;
  this.host = host;
  this.useDict = opts.useDict;
  this.useProtobuf = opts.useProtobuf;
  this.handshake = new Handshake(opts);
  this.heartbeat = new Heartbeat(opts);
  this.distinctHost = opts.distinctHost;
  this.ssl = opts.ssl;

  this.switcher = null;
}