Search in sources :

Example 1 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 2 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 3 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 4 with Executor

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

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

the class HttpClientTimeoutTest method testIdleTimeout.

@Test
public void testIdleTimeout() throws Throwable {
    long timeout = 1000;
    start(new TimeoutHandler(2 * timeout));
    client.stop();
    final AtomicBoolean sslIdle = new AtomicBoolean();
    client = new HttpClient(new HttpClientTransportOverHTTP() {

        @Override
        public HttpDestination newHttpDestination(Origin origin) {
            return new HttpDestinationOverHTTP(getHttpClient(), origin) {

                @Override
                protected ClientConnectionFactory newSslClientConnectionFactory(ClientConnectionFactory connectionFactory) {
                    HttpClient client = getHttpClient();
                    return new SslClientConnectionFactory(client.getSslContextFactory(), client.getByteBufferPool(), client.getExecutor(), connectionFactory) {

                        @Override
                        protected SslConnection newSslConnection(ByteBufferPool byteBufferPool, Executor executor, EndPoint endPoint, SSLEngine engine) {
                            return new SslConnection(byteBufferPool, executor, endPoint, engine) {

                                @Override
                                protected boolean onReadTimeout() {
                                    sslIdle.set(true);
                                    return super.onReadTimeout();
                                }
                            };
                        }
                    };
                }
            };
        }
    }, sslContextFactory);
    client.setIdleTimeout(timeout);
    client.start();
    try {
        client.newRequest("localhost", connector.getLocalPort()).scheme(scheme).send();
        Assert.fail();
    } catch (Exception x) {
        Assert.assertFalse(sslIdle.get());
        Assert.assertThat(x.getCause(), Matchers.instanceOf(TimeoutException.class));
    }
}
Also used : ByteBufferPool(org.eclipse.jetty.io.ByteBufferPool) SSLEngine(javax.net.ssl.SSLEngine) SslClientConnectionFactory(org.eclipse.jetty.io.ssl.SslClientConnectionFactory) HttpClientTransportOverHTTP(org.eclipse.jetty.client.http.HttpClientTransportOverHTTP) ClientConnectionFactory(org.eclipse.jetty.io.ClientConnectionFactory) SslClientConnectionFactory(org.eclipse.jetty.io.ssl.SslClientConnectionFactory) EndPoint(org.eclipse.jetty.io.EndPoint) ServletException(javax.servlet.ServletException) TimeoutException(java.util.concurrent.TimeoutException) SocketTimeoutException(java.net.SocketTimeoutException) IOException(java.io.IOException) SslConnection(org.eclipse.jetty.io.ssl.SslConnection) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Executor(java.util.concurrent.Executor) HttpDestinationOverHTTP(org.eclipse.jetty.client.http.HttpDestinationOverHTTP) Test(org.junit.Test)

Aggregations

Executor (java.util.concurrent.Executor)629 Test (org.junit.Test)253 ArrayList (java.util.ArrayList)69 List (java.util.List)68 IOException (java.io.IOException)64 CountDownLatch (java.util.concurrent.CountDownLatch)63 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)61 Map (java.util.Map)46 CompletableFuture (java.util.concurrent.CompletableFuture)45 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)43 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)34 TimeUnit (java.util.concurrent.TimeUnit)33 File (java.io.File)32 Collection (java.util.Collection)29 ExecutorService (java.util.concurrent.ExecutorService)29 Nullable (javax.annotation.Nullable)28 Set (java.util.Set)27 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)26 JobID (org.apache.flink.api.common.JobID)26 Collections (java.util.Collections)25