/////////////////////////////////////////////////////////// event, signal handlers ///////////////////////////////////////////////////////////
548914
function shutdown(code, wait) {
  var wait  = wait || 10000;

  var die   = function(graceful) {
    var msg = graceful ? 'Shutdown complete.' : "Time's up, shutdown forced.";
    logger.info(msg + ' Have a jolly good day sir.\n');
    process.exit(code);
  };

  // we should only remove the pidfile if the agent is really running
  // otherwise a second instance would remove the pidfile of the first one
  if (agent.running()) {
    logger.info('Gracefully shutting down. Will self-destruct in ' + wait/1000 + ' secs.');

    var timer = setTimeout(die, wait);
    if (pidfile) pid.remove(pidfile);

    agent.shutdown(function() {
      clearTimeout(timer);
      // wait a tad so that everything gets flushed.
      setTimeout(function() { die(true) }, 50);
    });
  }
}
431846
private void handleEvent(PrimitiveEvent event) {
    log.trace("Received {}", event);
    Set<Consumer<PrimitiveEvent>> listeners = eventListeners.get(event.type());
    if (listeners != null) {
      listeners.forEach(l -> l.accept(event));
    }
  }
657543
function globalEventHandler(event) {
    if (listeners[event.type]) {
      listeners[event.type].forEach(function(currentHandler) {
        currentHandler.call(this, event);
      }, this);
    }
  }
1026535
public function signal_handler_sigint($signal_number)
	{
		// log that we received an exit request
		$this->received_exit_request(true);

		// kill child processes
		if (self::$parent_pid == getmypid())
		{
			foreach ($this->forked_children as $pid => &$pid_info)
			{
				if ($pid_info['status'] == self::STOPPED)
				{
					continue;
				}

				// tell helpers not to respawn
				if ($pid_info['status'] == self::HELPER)
				{
					$pid_info['respawn'] = false;
				}

				$this->safe_kill($pid, SIGINT, 'requesting child exit for pid: ' . $pid, self::LOG_LEVEL_INFO);
			}

			sleep(1);

			// checking for missed sigchild
			$this->signal_handler_sigchild(SIGCHLD);

			$start_time = time();

			// wait for child processes to go away
			while ($this->forked_children_count > 0)
			{
				if (time() > ($start_time + $this->children_max_timeout))
				{
					foreach ($this->forked_children as $pid => $child)
					{
						if ($child['status'] == self::STOPPED)
						{
							continue;
						}

						$this->safe_kill($pid, SIGKILL, 'force killing child pid: ' . $pid, self::LOG_LEVEL_INFO);

						// stop the child
						$this->forked_children[$pid]['status'] = self::STOPPED;
						$this->forked_children_count--;
					}
				}
				else
				{
					$this->log('waiting ' . ($start_time + $this->children_max_timeout - time()) . ' seconds for ' . $this->forked_children_count . ' children to clean up', self::LOG_LEVEL_INFO);
					sleep(1);
					$this->housekeeping_check();
				}
			}

			// make call back to parent exit function if it exists
			$this->invoke_callback($this->parent_function_exit, $parameters = array(self::$parent_pid, $signal_number), true);
		}
		else
		{
			// invoke child cleanup callback
			if (isset($this->child_bucket))
			{
				$this->invoke_callback($this->child_function_exit[$this->child_bucket], $parameters = array($this->child_bucket), true);
			}
		}

		exit(-1);
	}
378232
function(element, type, handler) {
    var types = type.split(' ');
    Hammer.utils.each(types, function(type){
      element.addEventListener(type, handler, false);
    });
  }
614755
function onevent(event) {
        // Event should have the following properties:
        // * `id: string`: an event identifier.
        // * `type: string`: an event type.
        // * `data: any`: an event data.
        // * `reply: boolean`: true if this event requires the reply.

        // If the client sends a plain event, dispatch it.
        if (!event.reply) {
          self.emit(event.type, event.data);
        } else {
          var latch;
          // A function to create a function.
          function reply(success) {
            // A controller function.
            return function(value) {
              // This latch prevents double reply.
              if (!latch) {
                latch = true;
                self.send("reply", {id: event.id, data: value, exception: !success});
              }
            };
          }

          // Here, the controller is passed to the event handler as 2nd argument and allows
          // to call the server's `resolved` or `rejected` callback by sending `reply` event.
          self.emit(event.type, event.data, {resolve: reply(true), reject: reply(false)});
        }
      }
408323
function(event, args) {
      var wire = args[0];
      var index = WireIt.indexOf(wire, this.wires);
      if( index != -1 ) {
         this.wires[index] = null;
         this.wires = WireIt.compact(this.wires);
         this.eventRemoveWire.fire(wire);
			this.eventChanged.fire(this);
      }
   }
56130
func (h *Handler) signal(s os.Signal) {
	h.once.Do(func() {
		for _, fn := range h.notify {
			fn()
		}
		if h.final == nil {
			os.Exit(2)
		}
		h.final(s)
	})
}
347151
function dispatchEvent(event, handlers) {
    for (var i = (handlers.length - 1); i >= 0; i--) {
        if (event.isPropagationStopped()) {
            break;
        }
        var returnValue = handlers[i](event);
        if (returnValue === false) {
            event.stopPropagation();
            event.preventDefault();
        }
    }
}
133761
function(event) {
            var args = Array.prototype.slice.call(arguments);
            (this.emitter || (this.emitter = new emitter())).emit.apply(this, args);
        }
1248607
function form(bind, el, param, value) {
  var node = element('input');

  for (var key in param) {
    if (key !== 'signal' && key !== 'element') {
      node.setAttribute(key === 'input' ? 'type' : key, param[key]);
    }
  }
  node.setAttribute('name', param.signal);
  node.value = value;

  el.appendChild(node);

  node.addEventListener('input', function() {
    bind.update(node.value);
  });

  bind.elements = [node];
  bind.set = function(value) { node.value = value; };
}
268908
function _gpfDispatchEvent (event, params) {
    /*jshint validthis:true*/ // will be invoked as an object method
    var listeners = this._eventDispatcherListeners,
        eventObj,
        type,
        eventListeners;
    if (!listeners) {
        return this; // No listeners at all
    }
    if (event instanceof _GpfEvent) {
        eventObj = event;
        type = event.type;
    } else {
        type = event;
    }
    eventListeners = this._eventDispatcherListeners[type];
    if (undefined === eventListeners) {
        return this; // Nothing listeners for this event
    }
    if (!eventObj) {
        eventObj = new _GpfEvent(type, params, this);
    }
    _gpfTriggerListeners(eventObj, eventListeners);
    return eventObj;
}
815383
function onEvent(event) {
    if (event.eventType == nuimotion.Events.GESTURE) {
        console.log("Gesture: " + event.gestureType + " Hand: " + event.hand + " State: " + event.step);
    } else {
        console.log("Event: " + event.eventType);
    }
    for (var c in connections) {
        connections[c].sendUTF(JSON.stringify(event));
    }
}
645325
function handleControlConnection(connection) {
		connection.on('data', function (data) {
			console.log('Got command:', data.toString().trim());
			var request = data.toString().trim().split(' '),
				cmd = request[0],
				target = request[1],
				newline = '\r\n',
				response;
			console.log('Command is:', cmd);
			switch (cmd) {
				case 'start':
					console.log('got here');
					self.store.broadcast('worker:start', target);
					response = lib.format('Starting {0} servers.', (target || 'all'));
					break;
				case 'pause':
					self.store.broadcast('worker:pause', target);
					response = lib.format('Pausing {0} servers.', (target || 'all'));
					break;
				case 'stop':
					self.store.broadcast('worker:stop', target);
					response = lib.format('Stopping {0} servers.', (target || 'all'));
					break;
				case 'resume':
					self.store.broadcast('worker:resume', target);
					response = lib.format('Resuming {0} servers.', (target || 'all'));
					break;
				case 'heartbeat':
					var id = lib.guid();
					self.store.broadcast('worker:heartbeat', id);
					wait(id, function () {
						var args = Array.prototype.slice.call(arguments),
							response = {};
						lib.each(args, function (data) {
							var message = data[0],
								worker = data[1];
							response[worker] = message;
						});
						connection.write(JSON.stringify(response));
						connection.end(newline);
					});
					break;
				case 'stats':
					var id = lib.guid();
					self.store.broadcast('worker:stats', id);
					wait(id, function () {
						var args = Array.prototype.slice.call(arguments),
							response = {};
						lib.each(args, function (data) {
							var message = data[0],
								worker = data[1];
							response[worker] = message;
						});
						connection.write(JSON.stringify(response));
						connection.end(newline);
					});
					break;
				default:
					response = lib.format('Unknown command: {0}.', cmd);
					break;
			}
			if (response) {
				connection.write(response);
				connection.end(newline);
			}
		});
	}
842255
function signals() {

  /**
   *  Signal handler.
   */
  function interrupt(signal) {
    this.log.notice('received %s, scheduling shutdown', signal);
    this.shutdown(0, process.exit);
  }

  interrupt = interrupt.bind(this);

  function iterate(signal) {

    /* test environment listener leak */
    if(process.listeners(signal).length) return;

    process.once(signal, function() {
      interrupt(signal);
    })
  }

  ['SIGINT', 'SIGTERM'].forEach(iterate.bind(this));
}
661504
private void dispatchEvent(XoaEvent event) {
        LOG.entering(CLASS_NAME, "dispatchEvent", event);
        
        try {
            Integer handlerId = event.getHandlerId();
            
            XoaEventKind eventKind = event.getEvent();
            if (LOG.isLoggable(Level.FINEST)) {
                LOG.finest("XOA --> SOA: " + handlerId  + " event: " + eventKind.name());
            }
            
            BridgeDelegate handler = xoaObjectMap.get(handlerId);
            if (handler == null) {
                if (LOG.isLoggable(Level.FINEST)) {
                    LOG.finest("No handler for handler id: " + handlerId);
                }
                return;
            }
            
            /* Allow only one bridge crossing per handler at a time */
            synchronized (handler) {
                // dispatch to SOA
                Object[] args = { handlerId, eventKind.toString(), event.getParams() };
                firePropertyChange(XOP_MESSAGE, null, args);
            }

        } catch (Exception e) {
            LOG.log(Level.FINE, "While dispatching event: "+e.getMessage(), e);
            throw new IllegalStateException("Unable to dispatch an event from the cross origin proxy", e);
        }

    }
1258150
public <E> void dispatchEvent (Signal<E> signal, E event) {
    try {
      signal.emit(event);
    } catch (Throwable cause) {
      reportError("Event dispatch failure", cause);
    }
  }