Send an SSH Event to each registered listener
431213
public synchronized void fireEvent(Event evt) {
		if (evt == null) {
			return;
		}

		// Process global listeners
		for (Enumeration<EventListener> keys = globalListeners.elements(); keys
				.hasMoreElements();) {
			EventListener mListener = keys.nextElement();
			try {
				mListener.processEvent(evt);
			} catch (Throwable t) {
			}
		}

		String sourceThread = Thread.currentThread().getName();

		for (Enumeration<String> keys = keyedListeners.keys(); keys
				.hasMoreElements();) {
			String key = (String) keys.nextElement();
			// We don't want badly behaved listeners to throw uncaught
			// exceptions and upset other listeners
			try {
				String prefix = "";
				if (sourceThread.indexOf('-') > -1) {
					prefix = sourceThread.substring(0,
							sourceThread.indexOf('-'));

					if (key.startsWith(prefix)) {
						EventListener mListener = keyedListeners.get(key);
						mListener.processEvent(evt);
					}
				}

			} catch (Throwable thr) {
				// log.error("Event failed.", thr);
			}
		}
	}
1017590
def listen(self, address, ssl=False, family=0, flags=0, ipc=False, backlog=128):
        
        handles = []
        handle_args = ()
        if isinstance(address, six.string_types):
            handle_type = pyuv.Pipe
            handle_args = (ipc,)
            addresses = [address]
        elif isinstance(address, tuple):
            handle_type = pyuv.TCP
            result = getaddrinfo(address[0], address[1], family, socket.SOCK_STREAM,
                                 socket.IPPROTO_TCP, flags)
            addresses = [res[4] for res in result]
        elif isinstance(address, pyuv.Stream):
            handles.append(address)
            addresses = []
        else:
            raise TypeError('expecting a string, tuple or pyuv.Stream')
        for addr in addresses:
            handle = handle_type(self._hub.loop, *handle_args)
            try:
                if compat.pyuv_pipe_helper(handle, handle_args, 'bind', addr):
                    handles.append(handle)
                    break
                handle.bind(addr)
            except pyuv.error.UVError as e:
                self._log.warning('bind error {!r}, skipping {}', e[0], saddr(addr))
                continue
            handles.append(handle)
        addresses = []
        for handle in handles:
            if backlog is not None:
                callback = functools.partial(self._on_new_connection, ssl=ssl)
                handle.listen(callback, backlog)
                addr = handle.getsockname()
                self._log.debug('listen on {}', saddr(addr))
            addresses.append(addr)
        self._handles += handles
        self._addresses += addresses
599337
function listener (event, done) {
  return function onevent (arg1) {
    var args = new Array(arguments.length)
    var ee = this
    var err = event === 'error'
      ? arg1
      : null

    // copy args to prevent arguments escaping scope
    for (var i = 0; i < args.length; i++) {
      args[i] = arguments[i]
    }

    done(err, ee, event, args)
  }
}
620947
def emit(event, *args, &block)
      listeners(event).delete_if do |cb|
        cb.call(*args, &block) == :delete
      end
    end
1213393
def start_event_stream(self):
        
        if not self._stream:
            self._stream = GerritStream(self, ssh_client=self._ssh_client)
            self._stream.start()
538034
def execute_ssh_command(self, client, command):
        """"""
        try:
            out = ipa_utils.execute_ssh_command(client, command)
        except Exception as error:
            raise IpaCloudException(
                'Command: "{0}", failed execution: {1}.'.format(
                    command, error
                )
            )
        else:
            self._write_to_log(out)
805271
def emit(type, sender=nil, *args)
      listeners[type].each { |l| l.fire(sender, *args) } if listeners.has_key? type
    end
526499
def dispatchEvent(self, event, *args):
        
        for callback in self.listeners[event]:
            yield callback(event, self, *args)
202908
function setupListener (host_port, listenerDone) {

            const hp = /^\[?([^\]]+)\]?:(\d+)$/.exec(host_port);
            if (!hp) return listenerDone(
                new Error('Invalid "listen" format in smtp.ini'));

            const host = hp[1];
            const port = parseInt(hp[2], 10);

            Server.get_smtp_server(host, port, inactivity_timeout, (server) => {
                if (!server) return listenerDone();

                server.notes = Server.notes;
                if (Server.cluster) server.cluster = Server.cluster;

                server
                    .on('listening', function () {
                        const addr = this.address();
                        logger.lognotice(`Listening on ${addr.address}:${addr.port}`);
                        listenerDone();
                    })
                    .on('close', () => {
                        logger.loginfo(`Listener ${host}:${port} stopped`);
                    })
                    .on('error', e => {
                        if (e.code !== 'EAFNOSUPPORT') return listenerDone(e);
                        // Fallback from IPv6 to IPv4 if not supported
                        // But only if we supplied the default of [::0]:25
                        if (/^::0/.test(host) && Server.default_host) {
                            server.listen(port, '0.0.0.0', 0);
                            return;
                        }
                        // Pass error to callback
                        listenerDone(e);
                    })
                    .listen(port, host, 0);
            });
        }
865301
def send(x, inter=0, loop=0, count=None, verbose=None, realtime=None, *args, **kargs):
    """"""
    __gen_send(conf.L3socket(*args, **kargs), x, inter=inter, loop=loop, count=count,verbose=verbose, realtime=realtime)
996457
function onListening() {
    var addr = server.address();
    var bind = typeof addr === 'string'
        ? 'pipe ' + addr
        : 'port ' + addr.port;
    console.error('Listening on ' + bind);
}
27106
def _send_event_to_project(self, project_id, action, event):
        
        try:
            project_listeners = self._listeners[project_id]
        except KeyError:
            return
        for listener in project_listeners:
            listener.put_nowait((action, event, {}))
328937
def ssh_exec_in_new_loop(server, cmd, timeout=10, **ssh_kwargs):
    
    task = ssh_exec(server, cmd, timeout=timeout, **ssh_kwargs)
    loop = asyncio.new_event_loop()
    asyncio.set_event_loop(loop)
    return loop.run_until_complete(task)
535081
def emit_event(self, event):
        """"""
        with self._lock:
            listeners = list(self._event_listeners)

        for cb in list(self._event_listeners):
            # noinspection PyBroadException
            try:
                cb(event)
            except:
                # Don't let exceptions from callbacks kill our thread of execution
                logger.exception("Event callback resulted in unhandled exception")
1144633
def _send_signal(self, unique_id, signalno, configs):
    
    pids = self.get_pid(unique_id, configs)
    if pids != constants.PROCESS_NOT_RUNNING_PID:
      pid_str = ' '.join(str(pid) for pid in pids)
      hostname = self.processes[unique_id].hostname
      msg=  Deployer._signalnames.get(signalno,"SENDING SIGNAL %s TO"%signalno)
      with get_ssh_client(hostname, username=runtime.get_username(), password=runtime.get_password()) as ssh:
        better_exec_command(ssh, "kill -{0} {1}".format(signalno, pid_str), "{0} PROCESS {1}".format(msg, unique_id))
1144339
function registerListeners() {
  const exit = function exit(signal) {
    console.log(chalk.bgBlack.yellow(`Received ${signal} => Exiting`))
    process.exit()
  }
  const SIGABRT = 'SIGABRT'
  const SIGHUP = 'SIGHUP'
  const SIGINT = 'SIGINT'
  const SIGQUIT = 'SIGQUIT'
  const SIGTERM = 'SIGTERM'

  process.on(SIGABRT, () => exit(SIGABRT))
  process.on(SIGHUP, () => exit(SIGHUP))
  process.on(SIGINT, () => exit(SIGINT))
  process.on(SIGQUIT, () => exit(SIGQUIT))
  process.on(SIGTERM, () => exit(SIGTERM))
}
918081
def run(self):
        
        listener = EventServer(self.address, EventNotifyHandler)
        log.info("Event listener running on %s", listener.server_address)
        # Listen for events until told to stop
        while not self.stop_flag.is_set():
            listener.handle_request()