Search in sources :

Example 26 with Executor

use of java.util.concurrent.Executor 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 27 with Executor

use of java.util.concurrent.Executor in project jetty.project by eclipse.

the class HttpClientTransportOverHTTP2Test method testExternalServer.

@Ignore
@Test
public void testExternalServer() throws Exception {
    HTTP2Client http2Client = new HTTP2Client();
    SslContextFactory sslContextFactory = new SslContextFactory();
    HttpClient httpClient = new HttpClient(new HttpClientTransportOverHTTP2(http2Client), sslContextFactory);
    Executor executor = new QueuedThreadPool();
    httpClient.setExecutor(executor);
    httpClient.start();
    //        ContentResponse response = httpClient.GET("https://http2.akamai.com/");
    ContentResponse response = httpClient.GET("https://webtide.com/");
    Assert.assertEquals(HttpStatus.OK_200, response.getStatus());
    httpClient.stop();
}
Also used : SslContextFactory(org.eclipse.jetty.util.ssl.SslContextFactory) Executor(java.util.concurrent.Executor) QueuedThreadPool(org.eclipse.jetty.util.thread.QueuedThreadPool) ContentResponse(org.eclipse.jetty.client.api.ContentResponse) HttpClient(org.eclipse.jetty.client.HttpClient) HTTP2Client(org.eclipse.jetty.http2.client.HTTP2Client) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 28 with Executor

use of java.util.concurrent.Executor in project jetty.project by eclipse.

the class ProxyServlet method onContinue.

@Override
protected void onContinue(HttpServletRequest clientRequest, Request proxyRequest) {
    super.onContinue(clientRequest, proxyRequest);
    Runnable action = (Runnable) proxyRequest.getAttributes().get(CONTINUE_ACTION_ATTRIBUTE);
    Executor executor = getHttpClient().getExecutor();
    executor.execute(action);
}
Also used : Executor(java.util.concurrent.Executor)

Example 29 with Executor

use of java.util.concurrent.Executor in project elasticsearch by elastic.

the class MockTcpTransport method connectToChannels.

@Override
protected NodeChannels connectToChannels(DiscoveryNode node, ConnectionProfile profile) throws IOException {
    final MockChannel[] mockChannels = new MockChannel[1];
    // we always use light here
    final NodeChannels nodeChannels = new NodeChannels(node, mockChannels, LIGHT_PROFILE);
    boolean success = false;
    final MockSocket socket = new MockSocket();
    try {
        Consumer<MockChannel> onClose = (channel) -> {
            final NodeChannels connected = connectedNodes.get(node);
            if (connected != null && connected.hasChannel(channel)) {
                try {
                    executor.execute(() -> {
                        disconnectFromNode(node, channel, "channel closed event");
                    });
                } catch (RejectedExecutionException ex) {
                    logger.debug("failed to run disconnectFromNode - node is shutting down");
                }
            }
        };
        final InetSocketAddress address = node.getAddress().address();
        // we just use a single connections
        configureSocket(socket);
        final TimeValue connectTimeout = profile.getConnectTimeout();
        try {
            socket.connect(address, Math.toIntExact(connectTimeout.millis()));
        } catch (SocketTimeoutException ex) {
            throw new ConnectTransportException(node, "connect_timeout[" + connectTimeout + "]", ex);
        }
        MockChannel channel = new MockChannel(socket, address, "none", onClose);
        channel.loopRead(executor);
        mockChannels[0] = channel;
        success = true;
    } finally {
        if (success == false) {
            IOUtils.close(nodeChannels, socket);
        }
    }
    return nodeChannels;
}
Also used : CancellableThreads(org.elasticsearch.common.util.CancellableThreads) Socket(java.net.Socket) BufferedInputStream(java.io.BufferedInputStream) BigArrays(org.elasticsearch.common.util.BigArrays) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) BytesStreamOutput(org.elasticsearch.common.io.stream.BytesStreamOutput) CircuitBreakerService(org.elasticsearch.indices.breaker.CircuitBreakerService) BufferedOutputStream(java.io.BufferedOutputStream) ServerSocket(java.net.ServerSocket) HashSet(java.util.HashSet) InputStreamStreamInput(org.elasticsearch.common.io.stream.InputStreamStreamInput) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) NetworkService(org.elasticsearch.common.network.NetworkService) SocketException(java.net.SocketException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) Settings(org.elasticsearch.common.settings.Settings) NamedWriteableRegistry(org.elasticsearch.common.io.stream.NamedWriteableRegistry) TimeValue(org.elasticsearch.common.unit.TimeValue) SocketTimeoutException(java.net.SocketTimeoutException) Map(java.util.Map) ThreadPool(org.elasticsearch.threadpool.ThreadPool) ExecutorService(java.util.concurrent.ExecutorService) ByteSizeValue(org.elasticsearch.common.unit.ByteSizeValue) OutputStream(java.io.OutputStream) EsExecutors(org.elasticsearch.common.util.concurrent.EsExecutors) MockSocket(org.elasticsearch.mocksocket.MockSocket) Executor(java.util.concurrent.Executor) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) IOUtils(org.apache.lucene.util.IOUtils) Set(java.util.Set) IOException(java.io.IOException) BytesReference(org.elasticsearch.common.bytes.BytesReference) InetSocketAddress(java.net.InetSocketAddress) Executors(java.util.concurrent.Executors) MockServerSocket(org.elasticsearch.mocksocket.MockServerSocket) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) CountDownLatch(java.util.concurrent.CountDownLatch) AbstractRunnable(org.elasticsearch.common.util.concurrent.AbstractRunnable) List(java.util.List) Version(org.elasticsearch.Version) StreamInput(org.elasticsearch.common.io.stream.StreamInput) Closeable(java.io.Closeable) Collections(java.util.Collections) MockSocket(org.elasticsearch.mocksocket.MockSocket) SocketTimeoutException(java.net.SocketTimeoutException) InetSocketAddress(java.net.InetSocketAddress) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) TimeValue(org.elasticsearch.common.unit.TimeValue)

Example 30 with Executor

use of java.util.concurrent.Executor in project elasticsearch by elastic.

the class TransportSearchAction method searchAsyncAction.

private AbstractSearchAsyncAction searchAsyncAction(SearchTask task, SearchRequest searchRequest, GroupShardsIterator shardIterators, long startTime, Function<String, Transport.Connection> connectionLookup, long clusterStateVersion, Map<String, AliasFilter> aliasFilter, Map<String, Float> concreteIndexBoosts, ActionListener<SearchResponse> listener) {
    Executor executor = threadPool.executor(ThreadPool.Names.SEARCH);
    AbstractSearchAsyncAction searchAsyncAction;
    switch(searchRequest.searchType()) {
        case DFS_QUERY_THEN_FETCH:
            searchAsyncAction = new SearchDfsQueryThenFetchAsyncAction(logger, searchTransportService, connectionLookup, aliasFilter, concreteIndexBoosts, searchPhaseController, executor, searchRequest, listener, shardIterators, startTime, clusterStateVersion, task);
            break;
        case QUERY_THEN_FETCH:
            searchAsyncAction = new SearchQueryThenFetchAsyncAction(logger, searchTransportService, connectionLookup, aliasFilter, concreteIndexBoosts, searchPhaseController, executor, searchRequest, listener, shardIterators, startTime, clusterStateVersion, task);
            break;
        default:
            throw new IllegalStateException("Unknown search type: [" + searchRequest.searchType() + "]");
    }
    return searchAsyncAction;
}
Also used : Executor(java.util.concurrent.Executor)

Aggregations

Executor (java.util.concurrent.Executor)267 Test (org.junit.Test)114 CountDownLatch (java.util.concurrent.CountDownLatch)31 ArrayList (java.util.ArrayList)30 IOException (java.io.IOException)28 List (java.util.List)22 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)21 Timeouts (org.neo4j.cluster.timeout.Timeouts)15 Map (java.util.Map)13 ExecutorService (java.util.concurrent.ExecutorService)13 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)13 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)13 InstanceId (org.neo4j.cluster.InstanceId)13 Config (org.neo4j.kernel.configuration.Config)13 File (java.io.File)12 HashMap (java.util.HashMap)12 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)12 ObjectInputStreamFactory (org.neo4j.cluster.protocol.atomicbroadcast.ObjectInputStreamFactory)12 ObjectOutputStreamFactory (org.neo4j.cluster.protocol.atomicbroadcast.ObjectOutputStreamFactory)12 HeartbeatContext (org.neo4j.cluster.protocol.heartbeat.HeartbeatContext)12