Java Code Examples for org.eclipse.jetty.server.ServerConnector#setAcceptQueueSize()

The following examples show how to use org.eclipse.jetty.server.ServerConnector#setAcceptQueueSize() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WebServer.java    From hop with Apache License 2.0 6 votes vote down vote up
/**
 * Set up jetty options to the connector
 *
 * @param connector
 */
protected void setupJettyOptions( ServerConnector connector ) {
  LowResourceMonitor lowResourceMonitor = new LowResourceMonitor( server );
  if ( validProperty( Const.HOP_SERVER_JETTY_ACCEPTORS ) ) {
    server.addBean( new ConnectionLimit( Integer.parseInt( System.getProperty( Const.HOP_SERVER_JETTY_ACCEPTORS ) ) ) );
    log.logBasic(
      BaseMessages.getString( PKG, "WebServer.Log.ConfigOptions", "acceptors", connector.getAcceptors() ) );
  }

  if ( validProperty( Const.HOP_SERVER_JETTY_ACCEPT_QUEUE_SIZE ) ) {
    connector
      .setAcceptQueueSize( Integer.parseInt( System.getProperty( Const.HOP_SERVER_JETTY_ACCEPT_QUEUE_SIZE ) ) );
    log.logBasic( BaseMessages
      .getString( PKG, "WebServer.Log.ConfigOptions", "acceptQueueSize", connector.getAcceptQueueSize() ) );
  }

  if ( validProperty( Const.HOP_SERVER_JETTY_RES_MAX_IDLE_TIME ) ) {
    connector.setIdleTimeout( Integer.parseInt( System.getProperty( Const.HOP_SERVER_JETTY_RES_MAX_IDLE_TIME ) ) );
    log.logBasic( BaseMessages.getString( PKG, "WebServer.Log.ConfigOptions", "lowResourcesMaxIdleTime",
      connector.getIdleTimeout() ) );
  }
}
 
Example 2
Source File: LivenessService.java    From dremio-oss with Apache License 2.0 6 votes vote down vote up
@Override
public void start() throws Exception {
  if (!livenessEnabled) {
    logger.info("Liveness service disabled");
    return;
  }
  final ServerConnector serverConnector = new ServerConnector(embeddedLivenessJetty, NUM_ACCEPTORS, NUM_SELECTORS);
  serverConnector.setPort(config.getInt(DremioConfig.LIVENESS_PORT));
  serverConnector.setHost(LOOPBACK_INTERFACE);
  serverConnector.setAcceptQueueSize(ACCEPT_QUEUE_BACKLOG);
  embeddedLivenessJetty.addConnector(serverConnector);

  ServletHandler handler = new ServletHandler();
  embeddedLivenessJetty.setHandler(handler);

  handler.addServletWithMapping(new ServletHolder(new LivenessServlet()), "/live");
  handler.addServletWithMapping(new ServletHolder(createMetricsServlet()), "/metrics");

  embeddedLivenessJetty.start();
  livenessPort = serverConnector.getLocalPort();
  logger.info("Started liveness service on port {}", livenessPort);
}
 
Example 3
Source File: ServersUtil.java    From joynr with Apache License 2.0 6 votes vote down vote up
private static Server startServer(ContextHandlerCollection contexts, int port) throws Exception {
    System.setProperty(MessagingPropertyKeys.PROPERTY_SERVLET_HOST_PATH, "http://localhost:" + port);
    setBounceProxyUrl();
    setDirectoriesUrl();
    logger.info("HOST PATH: {}", System.getProperty(MessagingPropertyKeys.PROPERTY_SERVLET_HOST_PATH));

    final Server jettyServer = new Server();
    ServerConnector connector = new ServerConnector(jettyServer,
                                                    new HttpConnectionFactory(new HttpConfiguration()));
    connector.setPort(port);
    connector.setAcceptQueueSize(1);
    jettyServer.setConnectors(new Connector[]{ connector });

    jettyServer.setHandler(contexts);
    jettyServer.start();

    logger.trace("Started jetty server: {}", jettyServer.dump());

    return jettyServer;
}
 
Example 4
Source File: JettyWebServer.java    From oxygen with Apache License 2.0 5 votes vote down vote up
private void configConnector(ServerConnector connector, JettyConf jettyConf) {
  connector.setPort(this.port);
  connector.setIdleTimeout(jettyConf.getIdleTimeout());
  connector.setAcceptQueueSize(jettyConf.getAcceptQueueSize());
  connector.setStopTimeout(jettyConf.getStopTimeout());
  connector.setReuseAddress(jettyConf.isReuseAddress());
}
 
Example 5
Source File: SSLUtils.java    From warp10-platform with Apache License 2.0 5 votes vote down vote up
public static ServerConnector getConnector(Server server, String prefix) {
  int sslAcceptors = Integer.parseInt(WarpConfig.getProperty(prefix + Configuration._SSL_ACCEPTORS, DEFAULT_SSL_ACCEPTORS));
  int sslSelectors = Integer.parseInt(WarpConfig.getProperty(prefix + Configuration._SSL_SELECTORS, DEFAULT_SSL_SELECTORS));

  int sslPort = Integer.parseInt(WarpConfig.getProperty(prefix + Configuration._SSL_PORT));
  String sslHost = WarpConfig.getProperty(prefix + Configuration._SSL_HOST);
  int sslTcpBacklog = Integer.parseInt(WarpConfig.getProperty(prefix + Configuration._SSL_TCP_BACKLOG, "0"));

  SslContextFactory sslContextFactory = new SslContextFactory();
  sslContextFactory.setKeyStorePath(WarpConfig.getProperty(prefix + Configuration._SSL_KEYSTORE_PATH));
  sslContextFactory.setCertAlias(WarpConfig.getProperty(prefix + Configuration._SSL_CERT_ALIAS));
  
  if (null != WarpConfig.getProperty(prefix + Configuration._SSL_KEYSTORE_PASSWORD)) {
    sslContextFactory.setKeyStorePassword(WarpConfig.getProperty(prefix + Configuration._SSL_KEYSTORE_PASSWORD));
  }
  if (null != WarpConfig.getProperty(prefix + Configuration._SSL_KEYMANAGER_PASSWORD)) {
    sslContextFactory.setKeyManagerPassword(WarpConfig.getProperty(prefix + Configuration._SSL_KEYMANAGER_PASSWORD));
  }

  ServerConnector connector = new ServerConnector(server, sslAcceptors, sslSelectors, sslContextFactory);
  
  connector.setPort(sslPort);
  connector.setAcceptQueueSize(sslTcpBacklog);
  
  if (null != sslHost) {
    connector.setHost(sslHost);
  }
  
  String idle = WarpConfig.getProperty(prefix + Configuration._SSL_IDLE_TIMEOUT);
  
  if (null != idle) {
    connector.setIdleTimeout(Long.parseLong(idle));
  }

  return connector;
}
 
Example 6
Source File: ConnectorFactory.java    From vespa with Apache License 2.0 5 votes vote down vote up
public ServerConnector createConnector(final Metric metric, final Server server) {
    ServerConnector connector = new JDiscServerConnector(
            connectorConfig, metric, server, createConnectionFactories(metric).toArray(ConnectionFactory[]::new));
    connector.setPort(connectorConfig.listenPort());
    connector.setName(connectorConfig.name());
    connector.setAcceptQueueSize(connectorConfig.acceptQueueSize());
    connector.setReuseAddress(connectorConfig.reuseAddress());
    connector.setIdleTimeout((long)(connectorConfig.idleTimeout() * 1000.0));
    return connector;
}
 
Example 7
Source File: JettyServer.java    From FrameworkBenchmarks with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public final void run() throws Exception {
    final org.eclipse.jetty.server.Server s = new org.eclipse.jetty.server.Server(new QueuedThreadPool(200, Runtime.getRuntime().availableProcessors()));

    final ServerConnector http = new ServerConnector(s);
    http.setReuseAddress(true);
    http.setAcceptQueueSize(100000);
    http.setPort(8080);
    s.addConnector(http);

    final ServletContextHandler context = new ServletContextHandler();
    context.setContextPath("/");

    final ServletHolder holder1 = new ServletHolder(new PlaintextServlet());
    context.addServlet(holder1, "/plaintext");
    holder1.setAsyncSupported(true);
    final ServletHolder holder2 = new ServletHolder(new JsonServlet());
    context.addServlet(holder2, "/json");
    holder2.setAsyncSupported(true);

    s.setHandler(context);

    s.start();
    System.err.println("Server is up.");

    AbstractEmbeddedServer.waitUrlAvailable("http://localhost:8080/plaintext");
    AbstractEmbeddedServer.waitUrlAvailable("http://localhost:8080/json");
    System.err.println("Server test cases are instrumented and bootstrapped.");

    s.join();
}
 
Example 8
Source File: ServersUtil.java    From joynr with Apache License 2.0 5 votes vote down vote up
private static Server startSSLServer(ContextHandlerCollection contexts,
                                     SSLSettings settings,
                                     int port) throws IOException, Exception {

    System.setProperty(MessagingPropertyKeys.PROPERTY_SERVLET_HOST_PATH, "http://localhost:" + port);
    logger.info("PORT: {}", System.getProperty(MessagingPropertyKeys.PROPERTY_SERVLET_HOST_PATH));
    final Server jettyServer = new Server();

    HttpConfiguration https_config = new HttpConfiguration();
    https_config.setSecureScheme("https");
    https_config.setSecurePort(port);
    https_config.setOutputBufferSize(32768);
    https_config.addCustomizer(new SecureRequestCustomizer());

    // Configure SSL
    final SslContextFactory contextFactory = new SslContextFactory();
    contextFactory.setKeyStorePath(settings.getKeyStorePath());
    contextFactory.setTrustStorePath(settings.getTrustStorePath());
    contextFactory.setKeyStorePassword(settings.getKeyStorePassword());
    contextFactory.setTrustStorePassword(settings.getKeyStorePassword());
    contextFactory.setNeedClientAuth(true);

    // Create and use an SSL connector
    ServerConnector connector = new ServerConnector(jettyServer,
                                                    new SslConnectionFactory(contextFactory, "http/1.1"),
                                                    new HttpConnectionFactory(https_config));
    connector.setPort(port);
    connector.setAcceptQueueSize(1);
    jettyServer.setConnectors(new Connector[]{ connector });

    String serverUrl = "https://localhost:" + port;
    System.getProperties().setProperty(MessagingPropertyKeys.PROPERTY_SERVLET_HOST_PATH, serverUrl);

    jettyServer.setHandler(contexts);
    jettyServer.start();

    return jettyServer;
}