hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1784891 - in /httpcomponents/httpcore/trunk: httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/bootstrap/ httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/http/ httpcore5-testing/src/main/java/org/apache/hc/core5...
Date Wed, 01 Mar 2017 10:01:44 GMT
Author: olegk
Date: Wed Mar  1 10:01:43 2017
New Revision: 1784891

URL: http://svn.apache.org/viewvc?rev=1784891&view=rev
Log:
Separated test and prod bootstrap code

Added:
    httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/http/AsyncRequester.java
      - copied, changed from r1784890, httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/AsyncRequester.java
    httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/http/AsyncServer.java
      - copied, changed from r1784890, httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/AsyncServer.java
    httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/http/IOReactorExecutor.java
      - copied, changed from r1784890, httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/IOReactorExecutor.java
    httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/http/ThreadFactoryImpl.java   (with props)
Modified:
    httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/bootstrap/H2RequesterBootstrap.java
    httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/bootstrap/H2ServerBootstrap.java
    httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/http/Http1TestClient.java
    httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/http/Http1TestServer.java
    httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/http2/Http2TestClient.java
    httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/http2/Http2TestServer.java
    httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/AsyncRequester.java
    httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/AsyncRequesterBootstrap.java
    httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/AsyncServer.java
    httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/AsyncServerBootstrap.java
    httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/HttpAsyncRequester.java
    httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/HttpAsyncServer.java
    httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/IOReactorExecutor.java

Modified: httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/bootstrap/H2RequesterBootstrap.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/bootstrap/H2RequesterBootstrap.java?rev=1784891&r1=1784890&r2=1784891&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/bootstrap/H2RequesterBootstrap.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/bootstrap/H2RequesterBootstrap.java Wed Mar  1 10:01:43 2017
@@ -48,6 +48,7 @@ import org.apache.hc.core5.pool.ConnPool
 import org.apache.hc.core5.pool.ConnPoolPolicy;
 import org.apache.hc.core5.pool.StrictConnPool;
 import org.apache.hc.core5.reactor.IOReactorConfig;
+import org.apache.hc.core5.reactor.IOReactorException;
 import org.apache.hc.core5.reactor.IOSession;
 import org.apache.hc.core5.util.Args;
 
@@ -210,12 +211,16 @@ public class H2RequesterBootstrap {
                 h2Config != null ? h2Config : H2Config.DEFAULT,
                 connectionListener,
                 streamListener);
-        return new HttpAsyncRequester(
-                ioReactorConfig,
-                ioEventHandlerFactory,
-                connPool,
-                tlsStrategy != null ? tlsStrategy : new H2ClientTlsStrategy(),
-                exceptionListener);
+        try {
+            return new HttpAsyncRequester(
+                    ioReactorConfig,
+                    ioEventHandlerFactory,
+                    connPool,
+                    tlsStrategy != null ? tlsStrategy : new H2ClientTlsStrategy(),
+                    exceptionListener);
+        } catch (IOReactorException ex) {
+            throw new IllegalStateException(ex);
+        }
     }
 
     private static class PushConsumerEntry {

Modified: httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/bootstrap/H2ServerBootstrap.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/bootstrap/H2ServerBootstrap.java?rev=1784891&r1=1784890&r2=1784891&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/bootstrap/H2ServerBootstrap.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/bootstrap/H2ServerBootstrap.java Wed Mar  1 10:01:43 2017
@@ -48,6 +48,7 @@ import org.apache.hc.core5.http2.impl.ni
 import org.apache.hc.core5.http2.ssl.H2ServerTlsStrategy;
 import org.apache.hc.core5.net.InetAddressUtils;
 import org.apache.hc.core5.reactor.IOReactorConfig;
+import org.apache.hc.core5.reactor.IOReactorException;
 import org.apache.hc.core5.util.Args;
 
 /**
@@ -208,10 +209,14 @@ public class H2ServerBootstrap {
                 tlsStrategy != null ? tlsStrategy : new H2ServerTlsStrategy(new int[] {443, 8443}),
                 connectionListener,
                 streamListener);
-        return new HttpAsyncServer(
-                ioEventHandlerFactory,
-                ioReactorConfig,
-                exceptionListener);
+        try {
+            return new HttpAsyncServer(
+                    ioEventHandlerFactory,
+                    ioReactorConfig,
+                    exceptionListener);
+        } catch (IOReactorException ex) {
+            throw new IllegalStateException(ex);
+        }
     }
 
     private static class HandlerEntry {

Copied: httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/http/AsyncRequester.java (from r1784890, httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/AsyncRequester.java)
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/http/AsyncRequester.java?p2=httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/http/AsyncRequester.java&p1=httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/AsyncRequester.java&r1=1784890&r2=1784891&rev=1784891&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/AsyncRequester.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/http/AsyncRequester.java Wed Mar  1 10:01:43 2017
@@ -25,7 +25,7 @@
  *
  */
 
-package org.apache.hc.core5.http.impl.bootstrap;
+package org.apache.hc.core5.testing.nio.http;
 
 import java.io.IOException;
 import java.net.InetSocketAddress;
@@ -34,7 +34,6 @@ import java.util.concurrent.ThreadFactor
 import java.util.concurrent.TimeUnit;
 
 import org.apache.hc.core5.function.Callback;
-import org.apache.hc.core5.http.ExceptionListener;
 import org.apache.hc.core5.http.HttpHost;
 import org.apache.hc.core5.net.NamedEndpoint;
 import org.apache.hc.core5.reactor.ConnectionInitiator;
@@ -48,21 +47,10 @@ import org.apache.hc.core5.util.Args;
 
 public class AsyncRequester extends IOReactorExecutor<DefaultConnectingIOReactor> implements ConnectionInitiator {
 
-    public AsyncRequester(
-            final IOReactorConfig ioReactorConfig,
-            final ExceptionListener exceptionListener,
-            final Callback<IOSession> sessionShutdownCallback) {
+    public AsyncRequester(final IOReactorConfig ioReactorConfig) {
         super(ioReactorConfig,
-                exceptionListener,
                 new ThreadFactoryImpl("connector", true),
-                new ThreadFactoryImpl("requester-dispatch", true),
-                sessionShutdownCallback);
-    }
-
-    public AsyncRequester(
-            final IOReactorConfig ioReactorConfig,
-            final ExceptionListener exceptionListener) {
-        this(ioReactorConfig, exceptionListener, null);
+                new ThreadFactoryImpl("requester-dispatch", true));
     }
 
     @Override
@@ -89,7 +77,7 @@ public class AsyncRequester extends IORe
         return new InetSocketAddress(hostName, port);
     }
 
-    protected SessionRequest requestSession(
+    public SessionRequest requestSession(
             final HttpHost host,
             final long timeout,
             final TimeUnit timeUnit,

Copied: httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/http/AsyncServer.java (from r1784890, httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/AsyncServer.java)
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/http/AsyncServer.java?p2=httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/http/AsyncServer.java&p1=httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/AsyncServer.java&r1=1784890&r2=1784891&rev=1784891&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/AsyncServer.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/http/AsyncServer.java Wed Mar  1 10:01:43 2017
@@ -25,7 +25,7 @@
  *
  */
 
-package org.apache.hc.core5.http.impl.bootstrap;
+package org.apache.hc.core5.testing.nio.http;
 
 import java.io.IOException;
 import java.net.InetSocketAddress;
@@ -33,7 +33,6 @@ import java.util.Set;
 import java.util.concurrent.ThreadFactory;
 
 import org.apache.hc.core5.function.Callback;
-import org.apache.hc.core5.http.ExceptionListener;
 import org.apache.hc.core5.reactor.DefaultListeningIOReactor;
 import org.apache.hc.core5.reactor.IOEventHandlerFactory;
 import org.apache.hc.core5.reactor.IOReactorConfig;
@@ -42,15 +41,8 @@ import org.apache.hc.core5.reactor.Liste
 
 public class AsyncServer extends IOReactorExecutor<DefaultListeningIOReactor> {
 
-    public AsyncServer(
-            final IOReactorConfig ioReactorConfig,
-            final ExceptionListener exceptionListener,
-            final Callback<IOSession> sessionShutdownCallback) {
-        super(ioReactorConfig,
-                exceptionListener,
-                new ThreadFactoryImpl("listener", true),
-                new ThreadFactoryImpl("server-dispatch", true),
-                sessionShutdownCallback);
+    public AsyncServer(final IOReactorConfig ioReactorConfig) {
+        super(ioReactorConfig, new ThreadFactoryImpl("listener", true), new ThreadFactoryImpl("server-dispatch", true));
     }
 
     @Override

Modified: httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/http/Http1TestClient.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/http/Http1TestClient.java?rev=1784891&r1=1784890&r2=1784891&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/http/Http1TestClient.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/http/Http1TestClient.java Wed Mar  1 10:01:43 2017
@@ -36,44 +36,23 @@ import javax.net.ssl.SSLContext;
 
 import org.apache.hc.core5.concurrent.BasicFuture;
 import org.apache.hc.core5.concurrent.FutureCallback;
-import org.apache.hc.core5.function.Callback;
-import org.apache.hc.core5.http.ExceptionListener;
 import org.apache.hc.core5.http.HttpHost;
 import org.apache.hc.core5.http.config.CharCodingConfig;
 import org.apache.hc.core5.http.config.H1Config;
 import org.apache.hc.core5.http.impl.DefaultConnectionReuseStrategy;
 import org.apache.hc.core5.http.impl.HttpProcessors;
-import org.apache.hc.core5.http.impl.bootstrap.AsyncRequester;
-import org.apache.hc.core5.http.nio.command.ShutdownCommand;
-import org.apache.hc.core5.http.nio.command.ShutdownType;
 import org.apache.hc.core5.http.protocol.HttpProcessor;
 import org.apache.hc.core5.reactor.IOReactorConfig;
 import org.apache.hc.core5.reactor.IOSession;
 import org.apache.hc.core5.reactor.SessionRequest;
 import org.apache.hc.core5.reactor.SessionRequestCallback;
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.Logger;
 
-public class Http1TestClient extends AsyncRequester {
+public class Http1TestClient extends AsyncRequester  {
 
     private final SSLContext sslContext;
 
     public Http1TestClient(final IOReactorConfig ioReactorConfig, final SSLContext sslContext) throws IOException {
-        super(ioReactorConfig, new ExceptionListener() {
-
-            private final Logger log = LogManager.getLogger(Http1TestClient.class);
-
-            @Override
-            public void onError(final Exception ex) {
-                log.error(ex.getMessage(), ex);
-            }
-
-        }, new Callback<IOSession>() {
-            @Override
-            public void execute(final IOSession session) {
-                session.addFirst(new ShutdownCommand(ShutdownType.GRACEFUL));
-            }
-        });
+        super(ioReactorConfig);
         this.sslContext = sslContext;
     }
 
@@ -100,15 +79,6 @@ public class Http1TestClient extends Asy
         start(H1Config.DEFAULT);
     }
 
-    @Override
-    public SessionRequest requestSession(
-            final HttpHost host,
-            final long timeout,
-            final TimeUnit timeUnit,
-            final SessionRequestCallback callback) {
-        return super.requestSession(host, timeout, timeUnit, callback);
-    }
-
     public Future<ClientSessionEndpoint> connect(
             final HttpHost host,
             final long timeout,

Modified: httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/http/Http1TestServer.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/http/Http1TestServer.java?rev=1784891&r1=1784890&r2=1784891&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/http/Http1TestServer.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/http/Http1TestServer.java Wed Mar  1 10:01:43 2017
@@ -32,51 +32,28 @@ import java.net.InetSocketAddress;
 
 import javax.net.ssl.SSLContext;
 
-import org.apache.hc.core5.function.Callback;
 import org.apache.hc.core5.function.Supplier;
-import org.apache.hc.core5.http.ExceptionListener;
 import org.apache.hc.core5.http.config.CharCodingConfig;
 import org.apache.hc.core5.http.config.H1Config;
 import org.apache.hc.core5.http.impl.DefaultConnectionReuseStrategy;
 import org.apache.hc.core5.http.impl.HttpProcessors;
-import org.apache.hc.core5.http.impl.bootstrap.AsyncServer;
 import org.apache.hc.core5.http.impl.bootstrap.AsyncServerExchangeHandlerRegistry;
 import org.apache.hc.core5.http.nio.AsyncServerExchangeHandler;
-import org.apache.hc.core5.http.nio.command.ShutdownCommand;
-import org.apache.hc.core5.http.nio.command.ShutdownType;
 import org.apache.hc.core5.http.nio.support.BasicServerExchangeHandler;
 import org.apache.hc.core5.http.nio.support.RequestConsumerSupplier;
 import org.apache.hc.core5.http.nio.support.ResponseHandler;
 import org.apache.hc.core5.http.protocol.HttpProcessor;
 import org.apache.hc.core5.reactor.IOEventHandlerFactory;
 import org.apache.hc.core5.reactor.IOReactorConfig;
-import org.apache.hc.core5.reactor.IOSession;
 import org.apache.hc.core5.reactor.ListenerEndpoint;
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.Logger;
+
 public class Http1TestServer extends AsyncServer {
 
     private final AsyncServerExchangeHandlerRegistry handlerRegistry;
     private final SSLContext sslContext;
 
     public Http1TestServer(final IOReactorConfig ioReactorConfig, final SSLContext sslContext) throws IOException {
-        super(ioReactorConfig, new ExceptionListener() {
-
-            private final Logger log = LogManager.getLogger(Http1TestServer.class);
-
-            @Override
-            public void onError(final Exception ex) {
-                log.error(ex.getMessage(), ex);
-            }
-
-        }, new Callback<IOSession>() {
-
-            @Override
-            public void execute(final IOSession session) {
-                session.addFirst(new ShutdownCommand(ShutdownType.GRACEFUL));
-            }
-
-        });
+        super(ioReactorConfig);
         this.handlerRegistry = new AsyncServerExchangeHandlerRegistry("localhost");
         this.sslContext = sslContext;
     }

Copied: httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/http/IOReactorExecutor.java (from r1784890, httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/IOReactorExecutor.java)
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/http/IOReactorExecutor.java?p2=httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/http/IOReactorExecutor.java&p1=httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/IOReactorExecutor.java&r1=1784890&r2=1784891&rev=1784891&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/IOReactorExecutor.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/http/IOReactorExecutor.java Wed Mar  1 10:01:43 2017
@@ -25,7 +25,7 @@
  *
  */
 
-package org.apache.hc.core5.http.impl.bootstrap;
+package org.apache.hc.core5.testing.nio.http;
 
 import java.io.IOException;
 import java.util.List;
@@ -37,6 +37,8 @@ import java.util.concurrent.atomic.Atomi
 
 import org.apache.hc.core5.function.Callback;
 import org.apache.hc.core5.http.ExceptionListener;
+import org.apache.hc.core5.http.nio.command.ShutdownCommand;
+import org.apache.hc.core5.http.nio.command.ShutdownType;
 import org.apache.hc.core5.reactor.AbstractMultiworkerIOReactor;
 import org.apache.hc.core5.reactor.ExceptionEvent;
 import org.apache.hc.core5.reactor.IOEventHandlerFactory;
@@ -45,31 +47,38 @@ import org.apache.hc.core5.reactor.IORea
 import org.apache.hc.core5.reactor.IOSession;
 import org.apache.hc.core5.util.Args;
 import org.apache.hc.core5.util.Asserts;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
 
 abstract class IOReactorExecutor<T extends AbstractMultiworkerIOReactor> implements AutoCloseable {
 
     enum Status { READY, RUNNING, TERMINATED }
 
+    private final Logger log = LogManager.getLogger(Http1TestClient.class);
+
     private final IOReactorConfig ioReactorConfig;
     private final ExceptionListener exceptionListener;
     private final ExecutorService executorService;
     private final ThreadFactory workerThreadFactory;
-    private final Callback<IOSession> sessionShutdownCallback;
     private final AtomicReference<T> ioReactorRef;
     private final AtomicReference<Status> status;
 
     IOReactorExecutor(
             final IOReactorConfig ioReactorConfig,
-            final ExceptionListener exceptionListener,
             final ThreadFactory threadFactory,
-            final ThreadFactory workerThreadFactory,
-            final Callback<IOSession> sessionShutdownCallback) {
+            final ThreadFactory workerThreadFactory) {
         super();
         this.ioReactorConfig = ioReactorConfig != null ? ioReactorConfig : IOReactorConfig.DEFAULT;
-        this.exceptionListener = exceptionListener;
+        this.exceptionListener = new ExceptionListener() {
+
+            @Override
+            public void onError(final Exception ex) {
+                log.error(ex.getMessage(), ex);
+            }
+
+        };
         this.executorService = Executors.newSingleThreadExecutor(threadFactory);
         this.workerThreadFactory = workerThreadFactory;
-        this.sessionShutdownCallback = sessionShutdownCallback;
         this.ioReactorRef = new AtomicReference<>(null);
         this.status = new AtomicReference<>(Status.READY);
     }
@@ -86,7 +95,14 @@ abstract class IOReactorExecutor<T exten
                 ioEventHandlerFactory,
                 ioReactorConfig,
                 workerThreadFactory != null ? workerThreadFactory : new ThreadFactoryImpl("i/o dispatch"),
-                sessionShutdownCallback))) {
+                new Callback<IOSession>() {
+
+                    @Override
+                    public void execute(final IOSession session) {
+                        session.addFirst(new ShutdownCommand(ShutdownType.GRACEFUL));
+                    }
+
+                }))) {
             if (status.compareAndSet(Status.READY, Status.RUNNING)) {
                 executorService.execute(new Runnable() {
 

Added: httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/http/ThreadFactoryImpl.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/http/ThreadFactoryImpl.java?rev=1784891&view=auto
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/http/ThreadFactoryImpl.java (added)
+++ httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/http/ThreadFactoryImpl.java Wed Mar  1 10:01:43 2017
@@ -0,0 +1,61 @@
+/*
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+package org.apache.hc.core5.testing.nio.http;
+
+import java.util.concurrent.ThreadFactory;
+import java.util.concurrent.atomic.AtomicLong;
+
+class ThreadFactoryImpl implements ThreadFactory {
+
+    private final String namePrefix;
+    private final ThreadGroup group;
+    private final AtomicLong count;
+    private final boolean daemon;
+
+    ThreadFactoryImpl(final String namePrefix, final ThreadGroup group, final boolean daemon) {
+        this.namePrefix = namePrefix;
+        this.group = group;
+        this.daemon = daemon;
+        this.count = new AtomicLong();
+    }
+
+    ThreadFactoryImpl(final String namePrefix, final boolean daemon) {
+        this(namePrefix, null, daemon);
+    }
+
+    ThreadFactoryImpl(final String namePrefix) {
+        this(namePrefix, null, false);
+    }
+
+    @Override
+    public Thread newThread(final Runnable target) {
+        final Thread thread = new Thread(this.group, target, this.namePrefix + "-"  + this.count.incrementAndGet());
+        thread.setDaemon(daemon);
+        return thread;
+    }
+
+}

Propchange: httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/http/ThreadFactoryImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/http/ThreadFactoryImpl.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/http/ThreadFactoryImpl.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/http2/Http2TestClient.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/http2/Http2TestClient.java?rev=1784891&r1=1784890&r2=1784891&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/http2/Http2TestClient.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/http2/Http2TestClient.java Wed Mar  1 10:01:43 2017
@@ -36,16 +36,10 @@ import javax.net.ssl.SSLContext;
 
 import org.apache.hc.core5.concurrent.BasicFuture;
 import org.apache.hc.core5.concurrent.FutureCallback;
-import org.apache.hc.core5.function.Callback;
 import org.apache.hc.core5.function.Supplier;
-import org.apache.hc.core5.http.ExceptionListener;
 import org.apache.hc.core5.http.HttpHost;
 import org.apache.hc.core5.http.config.CharCodingConfig;
-import org.apache.hc.core5.http.impl.bootstrap.AsyncRequester;
-import org.apache.hc.core5.testing.nio.http.ClientSessionEndpoint;
 import org.apache.hc.core5.http.nio.AsyncPushConsumer;
-import org.apache.hc.core5.http.nio.command.ShutdownCommand;
-import org.apache.hc.core5.http.nio.command.ShutdownType;
 import org.apache.hc.core5.http.protocol.HttpProcessor;
 import org.apache.hc.core5.http2.config.H2Config;
 import org.apache.hc.core5.http2.impl.Http2Processors;
@@ -55,9 +49,9 @@ import org.apache.hc.core5.reactor.IORea
 import org.apache.hc.core5.reactor.IOSession;
 import org.apache.hc.core5.reactor.SessionRequest;
 import org.apache.hc.core5.reactor.SessionRequestCallback;
+import org.apache.hc.core5.testing.nio.http.AsyncRequester;
+import org.apache.hc.core5.testing.nio.http.ClientSessionEndpoint;
 import org.apache.hc.core5.util.Args;
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.Logger;
 
 public class Http2TestClient extends AsyncRequester {
 
@@ -65,23 +59,7 @@ public class Http2TestClient extends Asy
     private final AsyncPushConsumerRegistry pushConsumerRegistry;
 
     public Http2TestClient(final IOReactorConfig ioReactorConfig, final SSLContext sslContext) throws IOException {
-        super(ioReactorConfig, new ExceptionListener() {
-
-            private final Logger log = LogManager.getLogger(Http2TestClient.class);
-
-            @Override
-            public void onError(final Exception ex) {
-                log.error(ex.getMessage(), ex);
-            }
-
-        }, new Callback<IOSession>() {
-
-            @Override
-            public void execute(final IOSession session) {
-                session.addFirst(new ShutdownCommand(ShutdownType.GRACEFUL));
-            }
-
-        });
+        super(ioReactorConfig);
         this.sslContext = sslContext;
         this.pushConsumerRegistry = new AsyncPushConsumerRegistry();
     }

Modified: httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/http2/Http2TestServer.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/http2/Http2TestServer.java?rev=1784891&r1=1784890&r2=1784891&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/http2/Http2TestServer.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/http2/Http2TestServer.java Wed Mar  1 10:01:43 2017
@@ -32,15 +32,10 @@ import java.net.InetSocketAddress;
 
 import javax.net.ssl.SSLContext;
 
-import org.apache.hc.core5.function.Callback;
 import org.apache.hc.core5.function.Supplier;
-import org.apache.hc.core5.http.ExceptionListener;
 import org.apache.hc.core5.http.config.CharCodingConfig;
-import org.apache.hc.core5.http.impl.bootstrap.AsyncServer;
 import org.apache.hc.core5.http.impl.bootstrap.AsyncServerExchangeHandlerRegistry;
 import org.apache.hc.core5.http.nio.AsyncServerExchangeHandler;
-import org.apache.hc.core5.http.nio.command.ShutdownCommand;
-import org.apache.hc.core5.http.nio.command.ShutdownType;
 import org.apache.hc.core5.http.nio.support.BasicServerExchangeHandler;
 import org.apache.hc.core5.http.nio.support.RequestConsumerSupplier;
 import org.apache.hc.core5.http.nio.support.ResponseHandler;
@@ -49,33 +44,16 @@ import org.apache.hc.core5.http2.config.
 import org.apache.hc.core5.http2.impl.Http2Processors;
 import org.apache.hc.core5.reactor.IOEventHandlerFactory;
 import org.apache.hc.core5.reactor.IOReactorConfig;
-import org.apache.hc.core5.reactor.IOSession;
 import org.apache.hc.core5.reactor.ListenerEndpoint;
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.Logger;
+import org.apache.hc.core5.testing.nio.http.AsyncServer;
+
 public class Http2TestServer extends AsyncServer {
 
     private final SSLContext sslContext;
     private final AsyncServerExchangeHandlerRegistry handlerRegistry;
 
     public Http2TestServer(final IOReactorConfig ioReactorConfig, final SSLContext sslContext) throws IOException {
-        super(ioReactorConfig, new ExceptionListener() {
-
-            private final Logger log = LogManager.getLogger(Http2TestServer.class);
-
-            @Override
-            public void onError(final Exception ex) {
-                log.error(ex.getMessage(), ex);
-            }
-
-        }, new Callback<IOSession>() {
-
-            @Override
-            public void execute(final IOSession session) {
-                session.addFirst(new ShutdownCommand(ShutdownType.GRACEFUL));
-            }
-
-        });
+        super(ioReactorConfig);
         this.sslContext = sslContext;
         this.handlerRegistry = new AsyncServerExchangeHandlerRegistry("localhost");
     }

Modified: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/AsyncRequester.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/AsyncRequester.java?rev=1784891&r1=1784890&r2=1784891&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/AsyncRequester.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/AsyncRequester.java Wed Mar  1 10:01:43 2017
@@ -27,10 +27,8 @@
 
 package org.apache.hc.core5.http.impl.bootstrap;
 
-import java.io.IOException;
 import java.net.InetSocketAddress;
 import java.net.SocketAddress;
-import java.util.concurrent.ThreadFactory;
 import java.util.concurrent.TimeUnit;
 
 import org.apache.hc.core5.function.Callback;
@@ -41,6 +39,7 @@ import org.apache.hc.core5.reactor.Conne
 import org.apache.hc.core5.reactor.DefaultConnectingIOReactor;
 import org.apache.hc.core5.reactor.IOEventHandlerFactory;
 import org.apache.hc.core5.reactor.IOReactorConfig;
+import org.apache.hc.core5.reactor.IOReactorException;
 import org.apache.hc.core5.reactor.IOSession;
 import org.apache.hc.core5.reactor.SessionRequest;
 import org.apache.hc.core5.reactor.SessionRequestCallback;
@@ -49,30 +48,14 @@ import org.apache.hc.core5.util.Args;
 public class AsyncRequester extends IOReactorExecutor<DefaultConnectingIOReactor> implements ConnectionInitiator {
 
     public AsyncRequester(
+            final IOEventHandlerFactory eventHandlerFactory,
             final IOReactorConfig ioReactorConfig,
             final ExceptionListener exceptionListener,
-            final Callback<IOSession> sessionShutdownCallback) {
-        super(ioReactorConfig,
+            final Callback<IOSession> sessionShutdownCallback) throws IOReactorException {
+        super(new DefaultConnectingIOReactor(
+                        eventHandlerFactory, ioReactorConfig, new ThreadFactoryImpl("requester-dispatch", true), sessionShutdownCallback),
                 exceptionListener,
-                new ThreadFactoryImpl("connector", true),
-                new ThreadFactoryImpl("requester-dispatch", true),
-                sessionShutdownCallback);
-    }
-
-    public AsyncRequester(
-            final IOReactorConfig ioReactorConfig,
-            final ExceptionListener exceptionListener) {
-        this(ioReactorConfig, exceptionListener, null);
-    }
-
-    @Override
-    DefaultConnectingIOReactor createIOReactor(
-            final IOEventHandlerFactory ioEventHandlerFactory,
-            final IOReactorConfig ioReactorConfig,
-            final ThreadFactory threadFactory,
-            final Callback<IOSession> sessionShutdownCallback) throws IOException {
-        return new DefaultConnectingIOReactor(
-                ioEventHandlerFactory, ioReactorConfig, threadFactory, sessionShutdownCallback);
+                new ThreadFactoryImpl("connector", true));
     }
 
     private InetSocketAddress toSocketAddress(final HttpHost host) {

Modified: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/AsyncRequesterBootstrap.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/AsyncRequesterBootstrap.java?rev=1784891&r1=1784890&r2=1784891&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/AsyncRequesterBootstrap.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/AsyncRequesterBootstrap.java Wed Mar  1 10:01:43 2017
@@ -47,6 +47,7 @@ import org.apache.hc.core5.pool.ConnPool
 import org.apache.hc.core5.pool.ConnPoolPolicy;
 import org.apache.hc.core5.pool.StrictConnPool;
 import org.apache.hc.core5.reactor.IOReactorConfig;
+import org.apache.hc.core5.reactor.IOReactorException;
 import org.apache.hc.core5.reactor.IOSession;
 
 /**
@@ -189,12 +190,16 @@ public class AsyncRequesterBootstrap {
                 DefaultContentLengthStrategy.INSTANCE,
                 connectionListener,
                 streamListener);
-        return new HttpAsyncRequester(
-                ioReactorConfig,
-                ioEventHandlerFactory,
-                connPool,
-                tlsStrategy != null ? tlsStrategy : new BasicClientTlsStrategy(),
-                exceptionListener);
+        try {
+            return new HttpAsyncRequester(
+                    ioReactorConfig,
+                    ioEventHandlerFactory,
+                    connPool,
+                    tlsStrategy != null ? tlsStrategy : new BasicClientTlsStrategy(),
+                    exceptionListener);
+        } catch (IOReactorException ex) {
+            throw new IllegalStateException(ex);
+        }
     }
 
 }

Modified: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/AsyncServer.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/AsyncServer.java?rev=1784891&r1=1784890&r2=1784891&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/AsyncServer.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/AsyncServer.java Wed Mar  1 10:01:43 2017
@@ -27,40 +27,29 @@
 
 package org.apache.hc.core5.http.impl.bootstrap;
 
-import java.io.IOException;
 import java.net.InetSocketAddress;
 import java.util.Set;
-import java.util.concurrent.ThreadFactory;
 
 import org.apache.hc.core5.function.Callback;
 import org.apache.hc.core5.http.ExceptionListener;
 import org.apache.hc.core5.reactor.DefaultListeningIOReactor;
 import org.apache.hc.core5.reactor.IOEventHandlerFactory;
 import org.apache.hc.core5.reactor.IOReactorConfig;
+import org.apache.hc.core5.reactor.IOReactorException;
 import org.apache.hc.core5.reactor.IOSession;
 import org.apache.hc.core5.reactor.ListenerEndpoint;
 
 public class AsyncServer extends IOReactorExecutor<DefaultListeningIOReactor> {
 
     public AsyncServer(
+            final IOEventHandlerFactory eventHandlerFactory,
             final IOReactorConfig ioReactorConfig,
             final ExceptionListener exceptionListener,
-            final Callback<IOSession> sessionShutdownCallback) {
-        super(ioReactorConfig,
+            final Callback<IOSession> sessionShutdownCallback) throws IOReactorException {
+        super(new DefaultListeningIOReactor(
+                    eventHandlerFactory, ioReactorConfig, new ThreadFactoryImpl("server-dispatch", true), sessionShutdownCallback),
                 exceptionListener,
-                new ThreadFactoryImpl("listener", true),
-                new ThreadFactoryImpl("server-dispatch", true),
-                sessionShutdownCallback);
-    }
-
-    @Override
-    DefaultListeningIOReactor createIOReactor(
-            final IOEventHandlerFactory ioEventHandlerFactory,
-            final IOReactorConfig ioReactorConfig,
-            final ThreadFactory threadFactory,
-            final Callback<IOSession> sessionShutdownCallback) throws IOException {
-        return new DefaultListeningIOReactor(
-                ioEventHandlerFactory, ioReactorConfig, threadFactory, sessionShutdownCallback);
+                new ThreadFactoryImpl("listener", true));
     }
 
     public ListenerEndpoint listen(final InetSocketAddress address) {

Modified: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/AsyncServerBootstrap.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/AsyncServerBootstrap.java?rev=1784891&r1=1784890&r2=1784891&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/AsyncServerBootstrap.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/AsyncServerBootstrap.java Wed Mar  1 10:01:43 2017
@@ -50,6 +50,7 @@ import org.apache.hc.core5.http.nio.supp
 import org.apache.hc.core5.http.protocol.HttpProcessor;
 import org.apache.hc.core5.net.InetAddressUtils;
 import org.apache.hc.core5.reactor.IOReactorConfig;
+import org.apache.hc.core5.reactor.IOReactorException;
 import org.apache.hc.core5.util.Args;
 
 /**
@@ -216,10 +217,14 @@ public class AsyncServerBootstrap {
                 tlsStrategy != null ? tlsStrategy : new BasicServerTlsStrategy(new int[] {443, 8443}),
                 connectionListener,
                 streamListener);
-        return new HttpAsyncServer(
-                ioEventHandlerFactory,
-                ioReactorConfig,
-                exceptionListener);
+        try {
+            return new HttpAsyncServer(
+                    ioEventHandlerFactory,
+                    ioReactorConfig,
+                    exceptionListener);
+        } catch (IOReactorException ex) {
+            throw new IllegalStateException(ex);
+        }
     }
 
     private static class HandlerEntry {

Modified: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/HttpAsyncRequester.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/HttpAsyncRequester.java?rev=1784891&r1=1784890&r2=1784891&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/HttpAsyncRequester.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/HttpAsyncRequester.java Wed Mar  1 10:01:43 2017
@@ -47,6 +47,7 @@ import org.apache.hc.core5.pool.Controll
 import org.apache.hc.core5.pool.PoolEntry;
 import org.apache.hc.core5.reactor.IOEventHandlerFactory;
 import org.apache.hc.core5.reactor.IOReactorConfig;
+import org.apache.hc.core5.reactor.IOReactorException;
 import org.apache.hc.core5.reactor.IOSession;
 import org.apache.hc.core5.reactor.SessionRequest;
 import org.apache.hc.core5.reactor.SessionRequestCallback;
@@ -58,17 +59,16 @@ import org.apache.hc.core5.util.Args;
  */
 public class HttpAsyncRequester extends AsyncRequester {
 
-    private final IOEventHandlerFactory handlerFactory;
     private final ControlledConnPool<HttpHost, IOSession> connPool;
     private final TlsStrategy tlsStrategy;
 
     public HttpAsyncRequester(
             final IOReactorConfig ioReactorConfig,
-            final IOEventHandlerFactory handlerFactory,
+            final IOEventHandlerFactory eventHandlerFactory,
             final ControlledConnPool<HttpHost, IOSession> connPool,
             final TlsStrategy tlsStrategy,
-            final ExceptionListener exceptionListener) {
-        super(ioReactorConfig, exceptionListener, new Callback<IOSession>() {
+            final ExceptionListener exceptionListener) throws IOReactorException {
+        super(eventHandlerFactory, ioReactorConfig, exceptionListener, new Callback<IOSession>() {
 
             @Override
             public void execute(final IOSession session) {
@@ -76,13 +76,12 @@ public class HttpAsyncRequester extends
             }
 
         });
-        this.handlerFactory = Args.notNull(handlerFactory, "Handler factory");
         this.connPool = Args.notNull(connPool, "Connection pool");
         this.tlsStrategy = tlsStrategy;
     }
 
     public void start() throws IOException {
-        execute(handlerFactory);
+        execute();
     }
 
     public Future<AsyncClientEndpoint> connect(

Modified: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/HttpAsyncServer.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/HttpAsyncServer.java?rev=1784891&r1=1784890&r2=1784891&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/HttpAsyncServer.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/HttpAsyncServer.java Wed Mar  1 10:01:43 2017
@@ -34,21 +34,19 @@ import org.apache.hc.core5.http.nio.comm
 import org.apache.hc.core5.http.nio.command.ShutdownType;
 import org.apache.hc.core5.reactor.IOEventHandlerFactory;
 import org.apache.hc.core5.reactor.IOReactorConfig;
+import org.apache.hc.core5.reactor.IOReactorException;
 import org.apache.hc.core5.reactor.IOSession;
-import org.apache.hc.core5.util.Args;
 
 /**
  * @since 5.0
  */
 public class HttpAsyncServer extends AsyncServer {
 
-    private final IOEventHandlerFactory handlerFactory;
-
     public HttpAsyncServer(
-            final IOEventHandlerFactory handlerFactory,
+            final IOEventHandlerFactory eventHandlerFactory,
             final IOReactorConfig ioReactorConfig,
-            final ExceptionListener exceptionListener) {
-        super(ioReactorConfig, exceptionListener, new Callback<IOSession>() {
+            final ExceptionListener exceptionListener) throws IOReactorException {
+        super(eventHandlerFactory, ioReactorConfig, exceptionListener, new Callback<IOSession>() {
 
             @Override
             public void execute(final IOSession session) {
@@ -56,11 +54,10 @@ public class HttpAsyncServer extends Asy
             }
 
         });
-        this.handlerFactory = Args.notNull(handlerFactory, "Handler factory");
     }
 
     public void start() throws IOException {
-        execute(handlerFactory);
+        execute();
     }
 
 }

Modified: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/IOReactorExecutor.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/IOReactorExecutor.java?rev=1784891&r1=1784890&r2=1784891&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/IOReactorExecutor.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/IOReactorExecutor.java Wed Mar  1 10:01:43 2017
@@ -27,7 +27,6 @@
 
 package org.apache.hc.core5.http.impl.bootstrap;
 
-import java.io.IOException;
 import java.util.List;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
@@ -35,124 +34,72 @@ import java.util.concurrent.ThreadFactor
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicReference;
 
-import org.apache.hc.core5.function.Callback;
 import org.apache.hc.core5.http.ExceptionListener;
 import org.apache.hc.core5.reactor.AbstractMultiworkerIOReactor;
 import org.apache.hc.core5.reactor.ExceptionEvent;
-import org.apache.hc.core5.reactor.IOEventHandlerFactory;
-import org.apache.hc.core5.reactor.IOReactorConfig;
 import org.apache.hc.core5.reactor.IOReactorStatus;
-import org.apache.hc.core5.reactor.IOSession;
-import org.apache.hc.core5.util.Args;
-import org.apache.hc.core5.util.Asserts;
 
 abstract class IOReactorExecutor<T extends AbstractMultiworkerIOReactor> implements AutoCloseable {
 
     enum Status { READY, RUNNING, TERMINATED }
 
-    private final IOReactorConfig ioReactorConfig;
+    private final T ioReactor;
     private final ExceptionListener exceptionListener;
     private final ExecutorService executorService;
-    private final ThreadFactory workerThreadFactory;
-    private final Callback<IOSession> sessionShutdownCallback;
-    private final AtomicReference<T> ioReactorRef;
     private final AtomicReference<Status> status;
 
     IOReactorExecutor(
-            final IOReactorConfig ioReactorConfig,
+            final T ioReactor,
             final ExceptionListener exceptionListener,
-            final ThreadFactory threadFactory,
-            final ThreadFactory workerThreadFactory,
-            final Callback<IOSession> sessionShutdownCallback) {
+            final ThreadFactory threadFactory) {
         super();
-        this.ioReactorConfig = ioReactorConfig != null ? ioReactorConfig : IOReactorConfig.DEFAULT;
+        this.ioReactor = ioReactor;
         this.exceptionListener = exceptionListener;
         this.executorService = Executors.newSingleThreadExecutor(threadFactory);
-        this.workerThreadFactory = workerThreadFactory;
-        this.sessionShutdownCallback = sessionShutdownCallback;
-        this.ioReactorRef = new AtomicReference<>(null);
         this.status = new AtomicReference<>(Status.READY);
     }
 
-    abstract T createIOReactor(
-            IOEventHandlerFactory ioEventHandlerFactory,
-            IOReactorConfig ioReactorConfig,
-            ThreadFactory threadFactory,
-            Callback<IOSession> sessionShutdownCallback) throws IOException;
-
-    protected void execute(final IOEventHandlerFactory ioEventHandlerFactory) throws IOException {
-        Args.notNull(ioEventHandlerFactory, "Handler factory");
-        if (ioReactorRef.compareAndSet(null, createIOReactor(
-                ioEventHandlerFactory,
-                ioReactorConfig,
-                workerThreadFactory != null ? workerThreadFactory : new ThreadFactoryImpl("i/o dispatch"),
-                sessionShutdownCallback))) {
-            if (status.compareAndSet(Status.READY, Status.RUNNING)) {
-                executorService.execute(new Runnable() {
-
-                    @Override
-                    public void run() {
-                        try {
-                            ioReactorRef.get().execute();
-                        } catch (Exception ex) {
-                            if (exceptionListener != null) {
-                                exceptionListener.onError(ex);
-                            }
+    protected void execute() {
+        if (status.compareAndSet(Status.READY, Status.RUNNING)) {
+            executorService.execute(new Runnable() {
+
+                @Override
+                public void run() {
+                    try {
+                        ioReactor.execute();
+                    } catch (Exception ex) {
+                        if (exceptionListener != null) {
+                            exceptionListener.onError(ex);
                         }
                     }
-                });
-            }
-        } else {
-            throw new IllegalStateException("I/O reactor has already been started");
+                }
+            });
         }
     }
 
-    private T ensureRunning() {
-        final T ioReactor = ioReactorRef.get();
-        Asserts.check(ioReactor != null, "I/O reactor has not been started");
-        return ioReactor;
-    }
-
     T reactor() {
-        return ensureRunning();
+        return ioReactor;
     }
 
     public IOReactorStatus getStatus() {
-        final T ioReactor = ioReactorRef.get();
-        return ioReactor != null ? ioReactor.getStatus() : IOReactorStatus.INACTIVE;
+        return ioReactor.getStatus();
     }
 
     public List<ExceptionEvent> getAuditLog() {
-        final T ioReactor = ensureRunning();
         return ioReactor.getAuditLog();
     }
 
     public void awaitShutdown(final long deadline, final TimeUnit timeUnit) throws InterruptedException {
-        final T ioReactor = ioReactorRef.get();
-        if (ioReactor != null) {
-            ioReactor.awaitShutdown(deadline, timeUnit);
-        }
-    }
-
-    private void initiateShutdown(final T ioReactor) {
-        if (status.compareAndSet(Status.RUNNING, Status.TERMINATED)) {
-            ioReactor.initiateShutdown();
-        }
+        ioReactor.awaitShutdown(deadline, timeUnit);
     }
 
     public void initiateShutdown() {
-        final T ioReactor = ioReactorRef.get();
-        if (ioReactor != null) {
-            initiateShutdown(ioReactor);
-        }
+        ioReactor.initiateShutdown();
     }
 
     public void shutdown(final long graceTime, final TimeUnit timeUnit) {
-        final T ioReactor = ioReactorRef.get();
-        if (ioReactor != null) {
-            initiateShutdown(ioReactor);
-            ioReactor.shutdown(graceTime, timeUnit);
-        }
+        ioReactor.initiateShutdown();
+        ioReactor.shutdown(graceTime, timeUnit);
     }
 
     @Override



Mime
View raw message