Пример #1
0
  /* ------------------------------------------------------------ */
  protected void doStart() throws Exception {
    if (_server == null) throw new IllegalStateException("No server");

    // open listener port
    open();

    super.doStart();

    if (_threadPool == null) _threadPool = _server.getThreadPool();
    if (_threadPool != _server.getThreadPool() && (_threadPool instanceof LifeCycle))
      ((LifeCycle) _threadPool).start();

    // Start selector thread
    synchronized (this) {
      _acceptorThread = new Thread[getAcceptors()];

      for (int i = 0; i < _acceptorThread.length; i++) {
        if (!_threadPool.dispatch(new Acceptor(i))) {
          Log.warn("insufficient maxThreads configured for {}", this);
          break;
        }
      }
    }

    Log.info("Started {}", this);
  }
Пример #2
0
 /**
  * Set the threadpool. If the {@link ThreadPool} is a {@link LifeCycle}, then it is started by
  * this method.
  *
  * @param pool
  */
 public void setThreadPool(ThreadPool pool) {
   try {
     if (pool instanceof LifeCycle)
       if (!((LifeCycle) pool).isStarted()) ((LifeCycle) pool).start();
   } catch (Exception e) {
     throw new IllegalStateException(e);
   }
   _threadPool = pool;
 }
Пример #3
0
  /* ------------------------------------------------------------ */
  protected void doStop() throws Exception {
    try {
      close();
    } catch (IOException e) {
      Log.warn(e);
    }

    if (_threadPool == _server.getThreadPool()) _threadPool = null;
    else if (_threadPool instanceof LifeCycle) ((LifeCycle) _threadPool).stop();

    super.doStop();

    Thread[] acceptors = null;
    synchronized (this) {
      acceptors = _acceptorThread;
      _acceptorThread = null;
    }
    if (acceptors != null) {
      for (int i = 0; i < acceptors.length; i++) {
        Thread thread = acceptors[i];
        if (thread != null) thread.interrupt();
      }
    }
  }