Search in sources :

Example 1 with Scheduler

use of org.eclipse.jetty.util.thread.Scheduler in project dropwizard by dropwizard.

the class HttpConnectorFactory method build.

@Override
public Connector build(Server server, MetricRegistry metrics, String name, ThreadPool threadPool) {
    final HttpConfiguration httpConfig = buildHttpConfiguration();
    final HttpConnectionFactory httpConnectionFactory = buildHttpConnectionFactory(httpConfig);
    final Scheduler scheduler = new ScheduledExecutorScheduler();
    final ByteBufferPool bufferPool = buildBufferPool();
    return buildConnector(server, scheduler, bufferPool, name, threadPool, new Jetty93InstrumentedConnectionFactory(httpConnectionFactory, metrics.timer(httpConnections())));
}
Also used : ArrayByteBufferPool(org.eclipse.jetty.io.ArrayByteBufferPool) ByteBufferPool(org.eclipse.jetty.io.ByteBufferPool) HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) Scheduler(org.eclipse.jetty.util.thread.Scheduler) ScheduledExecutorScheduler(org.eclipse.jetty.util.thread.ScheduledExecutorScheduler) ScheduledExecutorScheduler(org.eclipse.jetty.util.thread.ScheduledExecutorScheduler) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration)

Example 2 with Scheduler

use of org.eclipse.jetty.util.thread.Scheduler in project jetty.project by eclipse.

the class HTTP2ClientConnectionFactory method newConnection.

@Override
public Connection newConnection(EndPoint endPoint, Map<String, Object> context) throws IOException {
    HTTP2Client client = (HTTP2Client) context.get(CLIENT_CONTEXT_KEY);
    ByteBufferPool byteBufferPool = (ByteBufferPool) context.get(BYTE_BUFFER_POOL_CONTEXT_KEY);
    Executor executor = (Executor) context.get(EXECUTOR_CONTEXT_KEY);
    Scheduler scheduler = (Scheduler) context.get(SCHEDULER_CONTEXT_KEY);
    Session.Listener listener = (Session.Listener) context.get(SESSION_LISTENER_CONTEXT_KEY);
    @SuppressWarnings("unchecked") Promise<Session> promise = (Promise<Session>) context.get(SESSION_PROMISE_CONTEXT_KEY);
    Generator generator = new Generator(byteBufferPool);
    FlowControlStrategy flowControl = client.getFlowControlStrategyFactory().newFlowControlStrategy();
    HTTP2ClientSession session = new HTTP2ClientSession(scheduler, endPoint, generator, listener, flowControl);
    Parser parser = new Parser(byteBufferPool, session, 4096, 8192);
    HTTP2ClientConnection connection = new HTTP2ClientConnection(client, byteBufferPool, executor, endPoint, parser, session, client.getInputBufferSize(), promise, listener);
    connection.addListener(connectionListener);
    return customize(connection, context);
}
Also used : ByteBufferPool(org.eclipse.jetty.io.ByteBufferPool) Scheduler(org.eclipse.jetty.util.thread.Scheduler) Parser(org.eclipse.jetty.http2.parser.Parser) FlowControlStrategy(org.eclipse.jetty.http2.FlowControlStrategy) Promise(org.eclipse.jetty.util.Promise) Executor(java.util.concurrent.Executor) Session(org.eclipse.jetty.http2.api.Session) ISession(org.eclipse.jetty.http2.ISession) Generator(org.eclipse.jetty.http2.generator.Generator)

Example 3 with Scheduler

use of org.eclipse.jetty.util.thread.Scheduler in project jetty.project by eclipse.

the class HouseKeeper method findScheduler.

/**
     * Get a scheduler. First try a common scheduler, failing that
     * create our own.
     * 
     * @throws Exception
     */
protected void findScheduler() throws Exception {
    if (_scheduler == null) {
        if (_sessionIdManager instanceof DefaultSessionIdManager) {
            //try and use a common scheduler, fallback to own
            _scheduler = ((DefaultSessionIdManager) _sessionIdManager).getServer().getBean(Scheduler.class);
        }
        if (_scheduler == null) {
            _scheduler = new ScheduledExecutorScheduler();
            _ownScheduler = true;
            _scheduler.start();
            if (LOG.isDebugEnabled())
                LOG.debug("Using own scheduler for scavenging");
        } else if (!_scheduler.isStarted())
            throw new IllegalStateException("Shared scheduler not started");
    }
}
Also used : Scheduler(org.eclipse.jetty.util.thread.Scheduler) ScheduledExecutorScheduler(org.eclipse.jetty.util.thread.ScheduledExecutorScheduler) ScheduledExecutorScheduler(org.eclipse.jetty.util.thread.ScheduledExecutorScheduler)

Example 4 with Scheduler

use of org.eclipse.jetty.util.thread.Scheduler in project jetty.project by eclipse.

the class ThreadStarvationTest method params.

@Parameterized.Parameters(name = "{0}")
public static List<Object[]> params() {
    List<Object[]> params = new ArrayList<>();
    // HTTP
    ConnectorProvider http = (server, acceptors, selectors) -> new ServerConnector(server, acceptors, selectors);
    ClientSocketProvider httpClient = (host, port) -> new Socket(host, port);
    params.add(new Object[] { "http", http, httpClient });
    // HTTPS/SSL/TLS
    ConnectorProvider https = (server, acceptors, selectors) -> {
        Path keystorePath = MavenTestingUtils.getTestResourcePath("keystore");
        SslContextFactory sslContextFactory = new SslContextFactory();
        sslContextFactory.setKeyStorePath(keystorePath.toString());
        sslContextFactory.setKeyStorePassword("storepwd");
        sslContextFactory.setKeyManagerPassword("keypwd");
        sslContextFactory.setTrustStorePath(keystorePath.toString());
        sslContextFactory.setTrustStorePassword("storepwd");
        ByteBufferPool pool = new LeakTrackingByteBufferPool(new MappedByteBufferPool.Tagged());
        HttpConnectionFactory httpConnectionFactory = new HttpConnectionFactory();
        ServerConnector connector = new ServerConnector(server, (Executor) null, (Scheduler) null, pool, acceptors, selectors, AbstractConnectionFactory.getFactories(sslContextFactory, httpConnectionFactory));
        SecureRequestCustomizer secureRequestCustomer = new SecureRequestCustomizer();
        secureRequestCustomer.setSslSessionAttribute("SSL_SESSION");
        httpConnectionFactory.getHttpConfiguration().addCustomizer(secureRequestCustomer);
        return connector;
    };
    ClientSocketProvider httpsClient = new ClientSocketProvider() {

        private SSLContext sslContext;

        {
            try {
                HttpsURLConnection.setDefaultHostnameVerifier((hostname, session) -> true);
                sslContext = SSLContext.getInstance("TLS");
                sslContext.init(null, SslContextFactory.TRUST_ALL_CERTS, new java.security.SecureRandom());
                HttpsURLConnection.setDefaultSSLSocketFactory(sslContext.getSocketFactory());
            } catch (Exception e) {
                e.printStackTrace();
                throw new RuntimeException(e);
            }
        }

        @Override
        public Socket newSocket(String host, int port) throws IOException {
            return sslContext.getSocketFactory().createSocket(host, port);
        }
    };
    params.add(new Object[] { "https/ssl/tls", https, httpsClient });
    return params;
}
Also used : Socket(java.net.Socket) Arrays(java.util.Arrays) SSLContext(javax.net.ssl.SSLContext) ServletException(javax.servlet.ServletException) AbstractHandler(org.eclipse.jetty.server.handler.AbstractHandler) MavenTestingUtils(org.eclipse.jetty.toolchain.test.MavenTestingUtils) SslContextFactory(org.eclipse.jetty.util.ssl.SslContextFactory) Scheduler(org.eclipse.jetty.util.thread.Scheduler) RunWith(org.junit.runner.RunWith) Callable(java.util.concurrent.Callable) ArrayList(java.util.ArrayList) LeakTrackingByteBufferPool(org.eclipse.jetty.io.LeakTrackingByteBufferPool) Assert.assertThat(org.junit.Assert.assertThat) Future(java.util.concurrent.Future) HttpServletRequest(javax.servlet.http.HttpServletRequest) QueuedThreadPool(org.eclipse.jetty.util.thread.QueuedThreadPool) After(org.junit.After) HttpStatus(org.eclipse.jetty.http.HttpStatus) Path(java.nio.file.Path) ExecutorService(java.util.concurrent.ExecutorService) Parameterized(org.junit.runners.Parameterized) OutputStream(java.io.OutputStream) HttpsURLConnection(javax.net.ssl.HttpsURLConnection) Executor(java.util.concurrent.Executor) HttpServletResponse(javax.servlet.http.HttpServletResponse) IOException(java.io.IOException) TestTracker(org.eclipse.jetty.toolchain.test.TestTracker) Test(org.junit.Test) ByteBufferPool(org.eclipse.jetty.io.ByteBufferPool) IO(org.eclipse.jetty.util.IO) StandardCharsets(java.nio.charset.StandardCharsets) Executors(java.util.concurrent.Executors) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) Rule(org.junit.Rule) DispatcherType(javax.servlet.DispatcherType) MappedByteBufferPool(org.eclipse.jetty.io.MappedByteBufferPool) Matchers.is(org.hamcrest.Matchers.is) Matchers.containsString(org.hamcrest.Matchers.containsString) Assert.assertEquals(org.junit.Assert.assertEquals) InputStream(java.io.InputStream) Path(java.nio.file.Path) LeakTrackingByteBufferPool(org.eclipse.jetty.io.LeakTrackingByteBufferPool) ByteBufferPool(org.eclipse.jetty.io.ByteBufferPool) MappedByteBufferPool(org.eclipse.jetty.io.MappedByteBufferPool) Scheduler(org.eclipse.jetty.util.thread.Scheduler) LeakTrackingByteBufferPool(org.eclipse.jetty.io.LeakTrackingByteBufferPool) ArrayList(java.util.ArrayList) SSLContext(javax.net.ssl.SSLContext) Matchers.containsString(org.hamcrest.Matchers.containsString) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) SslContextFactory(org.eclipse.jetty.util.ssl.SslContextFactory) Executor(java.util.concurrent.Executor) Socket(java.net.Socket)

Example 5 with Scheduler

use of org.eclipse.jetty.util.thread.Scheduler in project jetty.project by eclipse.

the class ResponseTest method init.

@Before
public void init() throws Exception {
    _server = new Server();
    Scheduler _scheduler = new TimerScheduler();
    HttpConfiguration config = new HttpConfiguration();
    LocalConnector connector = new LocalConnector(_server, null, _scheduler, null, 1, new HttpConnectionFactory(config));
    _server.addConnector(connector);
    _server.setHandler(new DumpHandler());
    _server.start();
    AbstractEndPoint endp = new ByteArrayEndPoint(_scheduler, 5000) {

        @Override
        public InetSocketAddress getLocalAddress() {
            return LOCALADDRESS;
        }
    };
    _channel = new HttpChannel(connector, new HttpConfiguration(), endp, new HttpTransport() {

        private Throwable _channelError;

        @Override
        public void send(MetaData.Response info, boolean head, ByteBuffer content, boolean lastContent, Callback callback) {
            if (_channelError == null)
                callback.succeeded();
            else
                callback.failed(_channelError);
        }

        @Override
        public boolean isPushSupported() {
            return false;
        }

        @Override
        public void push(org.eclipse.jetty.http.MetaData.Request request) {
        }

        @Override
        public void onCompleted() {
        }

        @Override
        public void abort(Throwable failure) {
            _channelError = failure;
        }

        @Override
        public boolean isOptimizedForDirectBuffers() {
            return false;
        }
    });
}
Also used : TimerScheduler(org.eclipse.jetty.util.thread.TimerScheduler) AbstractEndPoint(org.eclipse.jetty.io.AbstractEndPoint) Scheduler(org.eclipse.jetty.util.thread.Scheduler) TimerScheduler(org.eclipse.jetty.util.thread.TimerScheduler) HttpServletRequest(javax.servlet.http.HttpServletRequest) ByteArrayEndPoint(org.eclipse.jetty.io.ByteArrayEndPoint) ByteBuffer(java.nio.ByteBuffer) HttpServletResponse(javax.servlet.http.HttpServletResponse) Callback(org.eclipse.jetty.util.Callback) Before(org.junit.Before)

Aggregations

Scheduler (org.eclipse.jetty.util.thread.Scheduler)8 ScheduledExecutorScheduler (org.eclipse.jetty.util.thread.ScheduledExecutorScheduler)5 ByteBufferPool (org.eclipse.jetty.io.ByteBufferPool)4 IOException (java.io.IOException)3 ServletException (javax.servlet.ServletException)3 HttpServletRequest (javax.servlet.http.HttpServletRequest)3 HttpServletResponse (javax.servlet.http.HttpServletResponse)3 HttpConfiguration (org.eclipse.jetty.server.HttpConfiguration)3 HttpConnectionFactory (org.eclipse.jetty.server.HttpConnectionFactory)3 SslContextFactory (org.eclipse.jetty.util.ssl.SslContextFactory)3 InputStream (java.io.InputStream)2 OutputStream (java.io.OutputStream)2 StandardCharsets (java.nio.charset.StandardCharsets)2 Executor (java.util.concurrent.Executor)2 TimeUnit (java.util.concurrent.TimeUnit)2 SSLContext (javax.net.ssl.SSLContext)2 HttpStatus (org.eclipse.jetty.http.HttpStatus)2 AbstractHandler (org.eclipse.jetty.server.handler.AbstractHandler)2 IO (org.eclipse.jetty.util.IO)2 After (org.junit.After)2