org.eclipse.jetty.server.AbstractConnector Java Examples

The following examples show how to use org.eclipse.jetty.server.AbstractConnector. 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: ConnectionThrottler.java    From vespa with Apache License 2.0 6 votes vote down vote up
ConnectionThrottler(Runtime runtime,
                    RateStatistic rateStatistic,
                    Scheduler scheduler,
                    AbstractConnector connector,
                    ConnectorConfig.Throttling config) {
    this.connector = connector;
    if (config.maxHeapUtilization() != -1) {
        this.resourceLimits.add(new HeapResourceLimit(runtime, config.maxHeapUtilization()));
    }
    if (config.maxConnections() != -1) {
        this.resourceLimits.add(new ConnectionLimitThreshold(config.maxConnections()));
    }
    if (config.maxAcceptRate() != -1) {
        this.resourceLimits.add(new AcceptRateLimit(rateStatistic, config.maxAcceptRate()));
    }
    this.idleTimeout = config.idleTimeout() != -1 ? Duration.ofMillis((long) (config.idleTimeout()*1000)) : null;
    this.scheduler = scheduler;
}
 
Example #2
Source File: HttpResponseStatisticsCollectorTest.java    From vespa with Apache License 2.0 6 votes vote down vote up
@Before
public void initializeCollector() throws Exception {
    Server server = new Server();
    connector = new AbstractConnector(server, null, null, null, 0) {
        @Override
        protected void accept(int acceptorID) throws IOException, InterruptedException {
        }

        @Override
        public Object getTransport() {
            return null;
        }
    };
    collector.setHandler(new AbstractHandler() {
        @Override
        public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response)
                throws IOException, ServletException {
            baseRequest.setHandled(true);
            baseRequest.getResponse().setStatus(httpResponseCode);
        }
    });
    server.setHandler(collector);
    server.start();
}
 
Example #3
Source File: VarOneServer.java    From varOne with MIT License 6 votes vote down vote up
private static Server setupJettyServer(VarOneConfiguration conf) {
	AbstractConnector connector = new SelectChannelConnector();
    

    // Set some timeout options to make debugging easier.
    int timeout = 1000 * 30;
    connector.setMaxIdleTime(timeout);
    connector.setSoLingerTime(-1);
    connector.setHost(conf.getServerAddress());
    connector.setPort(conf.getServerPort());

    final Server server = new Server();
    server.addConnector(connector);

    return server;
}
 
Example #4
Source File: JettyHTTPServerEngine.java    From cxf with Apache License 2.0 5 votes vote down vote up
AbstractConnector createConnectorJetty(SslContextFactory sslcf, String hosto, int porto, int major, int minor) {
    AbstractConnector result = null;
    try {
        HttpConfiguration httpConfig = new HttpConfiguration();
        httpConfig.setSendServerVersion(getSendServerVersion());
        HttpConnectionFactory httpFactory = new HttpConnectionFactory(httpConfig);

        Collection<ConnectionFactory> connectionFactories = new ArrayList<>();

        result = new org.eclipse.jetty.server.ServerConnector(server);

        if (tlsServerParameters != null) {
            httpConfig.addCustomizer(new org.eclipse.jetty.server.SecureRequestCustomizer());
            SslConnectionFactory scf = new SslConnectionFactory(sslcf, "HTTP/1.1");
            connectionFactories.add(scf);
            String proto = (major > 9 || (major == 9 && minor >= 3)) ? "SSL" : "SSL-HTTP/1.1";
            result.setDefaultProtocol(proto);
        }
        connectionFactories.add(httpFactory);
        result.setConnectionFactories(connectionFactories);

        if (getMaxIdleTime() > 0) {
            result.setIdleTimeout(Long.valueOf(getMaxIdleTime()));
        }

    } catch (RuntimeException rex) {
        throw rex;
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }
    return result;
}
 
Example #5
Source File: JettyHTTPServerEngine.java    From cxf with Apache License 2.0 5 votes vote down vote up
protected void setupThreadPool() {
    if (isSetThreadingParameters()) {

        ThreadPool pl = getThreadPool();
        //threads for the acceptors and selectors are taken from
        //the pool so we need to have room for those
        AbstractConnector aconn = (AbstractConnector) connector;
        int acc = aconn.getAcceptors() * 2;
        if (getThreadingParameters().isSetMaxThreads()
            && getThreadingParameters().getMaxThreads() <= acc) {
            throw new Fault(new Message("NOT_ENOUGH_THREADS", LOG,
                                        port,
                                        acc + 1,
                                        getThreadingParameters().getMaxThreads(),
                                        acc));
        }
        if (!(pl instanceof QueuedThreadPool)) {
            throw new Fault(new Message("NOT_A_QUEUED_THREAD_POOL", LOG, pl.getClass()));
        }
        if (getThreadingParameters().isThreadNamePrefixSet()) {
            ((QueuedThreadPool) pl).setName(getThreadingParameters().getThreadNamePrefix());
        }
        if (getThreadingParameters().isSetMinThreads()) {
            ((QueuedThreadPool) pl).setMinThreads(getThreadingParameters().getMinThreads());
        }
        if (getThreadingParameters().isSetMaxThreads()) {
            ((QueuedThreadPool) pl).setMaxThreads(getThreadingParameters().getMaxThreads());
        }
    }
}
 
Example #6
Source File: ConnectionThrottler.java    From vespa with Apache License 2.0 4 votes vote down vote up
ConnectionThrottler(AbstractConnector connector, ConnectorConfig.Throttling config) {
    this(Runtime.getRuntime(), new RateStatistic(1, TimeUnit.SECONDS), connector.getScheduler(), connector, config);
}
 
Example #7
Source File: ConnectionThrottlerTest.java    From vespa with Apache License 2.0 4 votes vote down vote up
@Test
public void throttles_when_any_resource_check_exceeds_configured_threshold() {
    Runtime runtime = mock(Runtime.class);
    when(runtime.maxMemory()).thenReturn(100l);
    RateStatistic rateStatistic = new RateStatistic(1, TimeUnit.HOURS);
    MockScheduler scheduler = new MockScheduler();
    ConnectorConfig.Throttling config = new ConnectorConfig.Throttling(new ConnectorConfig.Throttling.Builder()
                                                                               .maxHeapUtilization(0.8)
                                                                               .maxAcceptRate(1));

    AbstractConnector connector = mock(AbstractConnector.class);

    ConnectionThrottler throttler = new ConnectionThrottler(runtime, rateStatistic, scheduler, connector, config);

    // Heap utilization above configured threshold, but connection rate below threshold.
    when(runtime.freeMemory()).thenReturn(10l);
    when(connector.isAccepting()).thenReturn(true);
    throttler.onAccepting(null);
    assertNotNull(scheduler.task);
    verify(connector).setAccepting(false);

    // Heap utilization below threshold, but connection rate above threshold.
    when(runtime.freeMemory()).thenReturn(80l);
    rateStatistic.record();
    rateStatistic.record(); // above accept rate limit (2 > 1)
    scheduler.task.run(); // run unthrottleIfBelowThresholds()
    verify(connector, times(1)).setAccepting(anyBoolean()); // verify setAccepting has not been called any mores times

    // Both heap utilization and accept rate below threshold
    when(runtime.freeMemory()).thenReturn(80l);
    when(connector.isAccepting()).thenReturn(false);
    rateStatistic.reset();
    scheduler.task.run(); // run unthrottleIfBelowThresholds()
    verify(connector).setAccepting(true);

    // Both heap utilization and accept rate below threshold
    when(connector.isAccepting()).thenReturn(true);
    when(runtime.freeMemory()).thenReturn(80l);
    rateStatistic.record();
    throttler.onAccepting(null);
    verify(connector, times(2)).setAccepting(anyBoolean()); // verify setAccepting has not been called any mores times
}