@Override
 public Executor getExecutor() {
   ThreadPool threadPool = _server.getThreadPool();
   if (threadPool instanceof DelegatingThreadPool)
     return ((DelegatingThreadPool) _server.getThreadPool()).getExecutor();
   return threadPool;
 }
 @Override
 public void setExecutor(Executor executor) {
   if (executor == null)
     throw new IllegalArgumentException("missing required 'executor' argument");
   ThreadPool threadPool = _server.getThreadPool();
   if (threadPool instanceof DelegatingThreadPool)
     ((DelegatingThreadPool) _server.getThreadPool()).setExecutor(executor);
   else throw new UnsupportedOperationException("!DelegatingThreadPool");
 }
  /**
   * @param server The server this connector will be added to. Must not be null.
   * @param executor An executor for this connector or null to use the servers executor
   * @param scheduler A scheduler for this connector or null to either a {@link Scheduler} set as a
   *     server bean or if none set, then a new {@link TimerScheduler} instance.
   * @param pool A buffer pool for this connector or null to either a {@link ByteBufferPool} set as
   *     a server bean or none set, the new {@link ArrayByteBufferPool} instance.
   * @param acceptors the number of acceptor threads to use, or 0 for a default value.
   * @param factories The Connection Factories to use.
   */
  public AbstractConnector(
      Server server,
      Executor executor,
      Scheduler scheduler,
      ByteBufferPool pool,
      int acceptors,
      ConnectionFactory... factories) {
    _server = server;
    _executor = executor != null ? executor : _server.getThreadPool();
    if (scheduler == null) scheduler = _server.getBean(Scheduler.class);
    _scheduler = scheduler != null ? scheduler : new TimerScheduler();
    if (pool == null) pool = _server.getBean(ByteBufferPool.class);
    _byteBufferPool = pool != null ? pool : new ArrayByteBufferPool();

    addBean(_server, false);
    addBean(_executor);
    if (executor == null) unmanage(_executor); // inherited from server
    addBean(_scheduler);
    addBean(_byteBufferPool);

    for (ConnectionFactory factory : factories) addConnectionFactory(factory);

    if (acceptors <= 0) acceptors = Math.max(1, (Runtime.getRuntime().availableProcessors()) / 2);
    if (acceptors > 2 * Runtime.getRuntime().availableProcessors())
      LOG.warn("Acceptors should be <= 2*availableProcessors: " + this);
    _acceptors = new Thread[acceptors];
  }
Example #4
0
  @PostConstruct
  public void start() throws Exception {
    server.start();
    checkState(server.isStarted(), "server is not started");

    // The combination of an NIO connector and an insufficient number of threads results
    // in a server that hangs after accepting connections. Jetty scales the number of
    // required threads based on the number of available processors in a non-trivial way,
    // so a config that works on one machine might fail on a larger machine without an
    // obvious reason why. Thus, we need this runtime check after startup as a safeguard.
    checkSufficientThreads(httpConnector, "HTTP");
    checkSufficientThreads(httpsConnector, "HTTPS");
    checkSufficientThreads(adminConnector, "admin");
    checkState(
        !server.getThreadPool().isLowOnThreads(),
        "insufficient threads configured for server connector");
  }