/*
Killbill server event handler
187958
@AllowConcurrentEvents
    @Subscribe
    public void handleSubscriptionEvents(final BusInternalEvent event) {
        final List<CompletionUserRequestNotifier> runningWaiters = new ArrayList<CompletionUserRequestNotifier>();
        synchronized (activeWaiters) {
            runningWaiters.addAll(activeWaiters);
        }
        if (runningWaiters.size() == 0) {
            return;
        }
        for (final CompletionUserRequestNotifier cur : runningWaiters) {
            cur.onBusEvent(event);
        }
    }
123443
public function killSoftDeletableListener()
    {
        foreach ($this->em->getEventManager()->getListeners() as $event => $listeners) {
            foreach ($listeners as $hash => $listener) {
                if ($listener instanceof SoftDeleteableListener) {
                    $listenerInst = $listener;
                    break 2;
                }
            }
        }

        $this->em->getEventManager()->removeEventListener(array('onFlush'), $listenerInst);
    }
702468
function() {
		var i = 0;
		while (i<_callbacks.length) {
			var deps = _callbacks[i][0],
				func = _callbacks[i][1],
				n = 0;
			while (n<deps.length) {
				if (areDeepDepsDefined(deps[n])) {
					deps.splice(n, 1);
				}
				else {
					n++;
				}
			}
			if (!deps.length) {
				_callbacks.splice(i, 1);
				if (func != null) {
					setTimeout(func, 0);
				}
			}
			else {
				i++;
			}
		}
	}
383759
function handleInternalRequest( $functionName, $params, $server=null )
    {
        if ( $server === null )
        {
            $server = $this;
        }
        switch( $functionName )
        {
            case 'system.listMethods':
                if ( count( $params ) != 0 )
                {
                    return new ggWebservicesFault( self::INVALIDPARAMSERROR, self::INVALIDPARAMSSTRING );
                }
                return $server->registeredMethods();

            case 'system.methodSignature':
                if ( count( $params ) != 1 || !is_string( $params[0] ) )
                {
                    return new ggWebservicesFault( self::INVALIDPARAMSERROR, self::INVALIDPARAMSSTRING );
                }
                if ( in_array( $params[0], $server->internalMethods ) )
                {
                    switch( $params[0] )
                    {
                        case 'system.listMethods':
                            return array( array( 'array' ) );
                        case 'system.methodSignature':
                            return array( array( 'array', 'string' ) );
                        case 'system.methodHelp':
                            return array( array( 'string', 'string' ) );
                        case 'system.multicall':
                            return array( array( 'array', 'array' ) );
                    }
                }
                if ( !array_key_exists( $params[0], $server->FunctionList ) )
                {
                    return new ggWebservicesFault( self::INVALIDINTROSPECTIONERROR, self::INVALIDINTROSPECTIONSTRING );
                }
                $results = array();
                foreach( $server->FunctionList[$params[0]] as $syntax )
                {
                    if ( $syntax['in'] !== null )
                    {
                        $syntax['in'] = array_values( $syntax['in'] );
                        array_unshift( $syntax['in'], $syntax['out'] );
                        $results[] = $syntax['in'];
                    }
                }
                return $results;

            case 'system.methodHelp':
                if ( count( $params ) != 1 || !is_string( $params[0] ) )
                {
                    return new ggWebservicesFault( self::INVALIDPARAMSERROR, self::INVALIDPARAMSSTRING );
                }
                if ( in_array( $params[0], $server->internalMethods ) )
                {
                    switch( $params[0] )
                    {
                        case 'system.listMethods':
                            return 'This method lists all the methods that the server knows how to dispatch';
                        case 'system.methodSignature':
                            return 'Returns an array of known signatures (an array of arrays) for the method name passed. First member of each array is the return type';
                        case 'system.methodHelp':
                            return 'Returns help text if defined for the method passed, otherwise returns an empty string';
                        case 'system.multicall':
                            return 'Boxcar multiple RPC calls in one request. See http://www.xmlrpc.com/discuss/msgReader$1208 for details';
                    }
                }
                if ( !array_key_exists( $params[0], $server->FunctionDescription ) )
                {
                    return new ggWebservicesFault( self::INVALIDINTROSPECTIONERROR, self::INVALIDINTROSPECTIONSTRING );
                }
                return $server->FunctionDescription[$params[0]];

            case 'system.multicall':
                // validate first the multicall syntax
                if ( count( $params ) != 1 || !is_array( $params[0] ) )
                {
                    return new ggWebservicesFault( self::INVALIDPARAMSERROR, self::INVALIDPARAMSSTRING );
                }
                foreach( $params[0] as $request )
                {
                    if ( !is_array( $request ) || //count( $request ) != 2 ||
                         !array_key_exists( 'methodName', $request) || !is_string( $request['methodName'] )||
                         !array_key_exists( 'params', $request ) || !is_array( $request['params'] ) )
                    {
                        return new ggWebservicesFault( self::INVALIDPARAMSERROR, self::INVALIDPARAMSSTRING );
                    }
                }
                // then execute all methods
                $results = array();
                foreach( $params[0] as $request)
                {
                    $resp = $server->handleRequest( $request['methodName'], $request['params'] );
                    if ( is_a( $resp, 'ggWebservicesFault' ) )
                    {
                        $results[] = array( 'faultCode' => $resp->faultCode(), 'faultString' => $resp->faultString() );
                    }
                    else
                    {
                        $results[] = $resp;
                    }
                }
                return $results;
            default:
                return parent::handleInternalRequest( $functionName, $params );
        }
    }
266671
function destroyServer(server, topology, callback) {
  LOCAL_SERVER_EVENTS.forEach(event => server.removeAllListeners(event));

  server.destroy(() => {
    topology.emit(
      'serverClosed',
      new monitoring.ServerClosedEvent(topology.s.id, server.description.address)
    );

    if (typeof callback === 'function') callback(null, null);
  });
}
1353794
@Override
  public boolean onKill(Scheduler.KillTopologyRequest request) {

    // get the topology name
    String topologyName = LocalContext.topologyName(config);
    LOG.info("Command to kill topology: " + topologyName);

    // set the flag that the topology being killed
    isTopologyKilled = true;

    synchronized (processToContainer) {
      // destroy/kill the process for each container
      for (Process p : processToContainer.keySet()) {

        // get the container index for the process
        int index = processToContainer.get(p);
        LOG.info("Killing executor for container: " + index);

        // destroy the process
        p.destroy();
        LOG.info("Killed executor for container: " + index);
      }

      // clear the mapping between process and container ids
      processToContainer.clear();
    }

    return true;
  }
1220223
function _delay(tag, ms, callback) {
		/*jshint -W040:true */
		var self = this;

		tag = "" + (tag || "default");
		if (timerMap[tag] != null) {
			clearTimeout(timerMap[tag]);
			delete timerMap[tag];
			// console.log("Cancel timer '" + tag + "'");
		}
		if (ms == null || callback == null) {
			return;
		}
		// console.log("Start timer '" + tag + "'");
		timerMap[tag] = setTimeout(function() {
			// console.log("Execute timer '" + tag + "'");
			callback.call(self);
		}, +ms);
	}
643114
function handleEvent(dom, handler, e) {
  var ptag = this.__.parent,
    item = this.__.item;

  if (!item)
    { while (ptag && !item) {
      item = ptag.__.item;
      ptag = ptag.__.parent;
    } }

  // override the event properties
  /* istanbul ignore next */
  if (isWritable(e, 'currentTarget')) { e.currentTarget = dom; }
  /* istanbul ignore next */
  if (isWritable(e, 'target')) { e.target = e.srcElement; }
  /* istanbul ignore next */
  if (isWritable(e, 'which')) { e.which = e.charCode || e.keyCode; }

  e.item = item;

  handler.call(this, e);

  // avoid auto updates
  if (!settings$1.autoUpdate) { return }

  if (!e.preventUpdate) {
    var p = getImmediateCustomParentTag(this);
    // fixes #2083
    if (p.isMounted) { p.update(); }
  }
}
521814
@Handler(priority = -1000)
    public void onStop(Stop event) {
        if (closing || !serverSocketChannel.isOpen()) {
            return;
        }
        newSyncEventPipeline().fire(new Close(), this);
    }
482165
public function handleGhost(ServerEvent $event, Queue $queue)
    {
        if ($this->ghostNick === null) {
            return;
        }

        // Attempt to kill the ghost connection
        $queue->ircPrivmsg($this->botNick, 'GHOST ' . $this->ghostNick . ' ' . $this->password);
    }
626219
function gracefulShutdown(){
  console.log('About to exit, closing servers.');

  servers.forEach(function(server, index){
    server.close();
  });

  process.exit();
}
945252
async function kill(pid) {
  try {
    process.kill(pid, 'SIGTERM')
  } catch (err) {
    if (err.code !== 'ESRCH') throw err
  }
}
1373826
function(event) {
        sendPingTimeout && clearTimeout(sendPingTimeout);
        socketCloseTimeout && clearTimeout(socketCloseTimeout);
        forceCloseTimeout && clearTimeout(forceCloseTimeout);
        eventCallback["close"](event);
      }
892242
void kill(UUID queryId) {
      DocumentExtractor extractor = queries.remove(queryId);
      if (extractor != null) {
         extractor.close();
      }
   }
447672
function() {
      workers = [];
      netBinding = process.binding('net');
      if (server_socket) {
        netBinding.close(server_socket);
      }
      if (the_server) {
        the_server.watcher.stop();
        the_server = null;
      }
      server_socket = null;
      if (master_server) {
        master_server.close();
      }
      if (master_socket_path) {
        // try to remove the
        try {
          require('fs').unlinkSync(master_socket_path);
        } catch(excp) {
          // do nothing
        }
        master_socket_path = null;
      }
      master_server = null;
      process.removeListener('SIGINT', killer);
      process.removeListener('SIGHUP', killer);
      process.removeListener('SIGTERM', killer);
      process.removeListener('SIGUSR2', respawner); 
      
      try {
        process.stdout.end();
      } catch(exxcpe) {
        // do nothing
      }
    }
403343
function(app) {

  try {
    // make sure we close down within N seconds
    const killtimer = setTimeout(() => {
      process.exit(1);
    }, 3000);
    // But don't keep the process open just for that!
    killtimer.unref();

    // stop taking new requests.
    app.server.close();

  } catch (err) {
    // oh well, not much we can do at this point.
    console.error('Error shutting down gracefully!', err.stack);
  }
}
1278971
public void stopListenting() {
        if (channel != null) {
            log.info("closing server channel");
            channel.close().syncUninterruptibly();
            channel = null;
        }
    }