hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1792526 - in /httpcomponents/httpcore/trunk: httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/ httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/ httpcore5/src/main/java/org/apache/hc/core5/concurrent/ httpcore...
Date Mon, 24 Apr 2017 18:10:55 GMT
Author: olegk
Date: Mon Apr 24 18:10:55 2017
New Revision: 1792526

URL: http://svn.apache.org/viewvc?rev=1792526&view=rev
Log:
Minor refactoring of I/O reactor code

Added:
    httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/concurrent/DefaultThreadFactory.java
  (contents, props changed)
      - copied, changed from r1792525, httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/ThreadFactoryImpl.java
Removed:
    httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/ThreadFactoryImpl.java
    httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/ThreadFactoryImpl.java
Modified:
    httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/AsyncRequester.java
    httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/AsyncServer.java
    httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/IOReactorExecutor.java
    httpcomponents/httpcore/trunk/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/TestDefaultListeningIOReactor.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/AsyncServer.java
    httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/HttpServer.java
    httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/reactor/AbstractMultiworkerIOReactor.java
    httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/reactor/DefaultConnectingIOReactor.java
    httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/reactor/DefaultListeningIOReactor.java
    httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/reactor/IOReactorExceptionHandler.java
    httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/reactor/IOReactorImpl.java

Modified: httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/AsyncRequester.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/AsyncRequester.java?rev=1792526&r1=1792525&r2=1792526&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/AsyncRequester.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/AsyncRequester.java
Mon Apr 24 18:10:55 2017
@@ -32,6 +32,7 @@ import java.net.InetSocketAddress;
 import java.net.SocketAddress;
 import java.util.concurrent.ThreadFactory;
 
+import org.apache.hc.core5.concurrent.DefaultThreadFactory;
 import org.apache.hc.core5.function.Callback;
 import org.apache.hc.core5.http.HttpHost;
 import org.apache.hc.core5.net.NamedEndpoint;
@@ -49,8 +50,8 @@ public class AsyncRequester extends IORe
 
     public AsyncRequester(final IOReactorConfig ioReactorConfig) {
         super(ioReactorConfig,
-                new ThreadFactoryImpl("connector", true),
-                new ThreadFactoryImpl("requester-dispatch", true));
+                new DefaultThreadFactory("connector", true),
+                new DefaultThreadFactory("requester-dispatch", true));
     }
 
     @Override

Modified: httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/AsyncServer.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/AsyncServer.java?rev=1792526&r1=1792525&r2=1792526&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/AsyncServer.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/AsyncServer.java
Mon Apr 24 18:10:55 2017
@@ -32,6 +32,7 @@ import java.net.InetSocketAddress;
 import java.util.Set;
 import java.util.concurrent.ThreadFactory;
 
+import org.apache.hc.core5.concurrent.DefaultThreadFactory;
 import org.apache.hc.core5.function.Callback;
 import org.apache.hc.core5.reactor.DefaultListeningIOReactor;
 import org.apache.hc.core5.reactor.IOEventHandlerFactory;
@@ -42,7 +43,7 @@ import org.apache.hc.core5.reactor.Liste
 public class AsyncServer extends IOReactorExecutor<DefaultListeningIOReactor> {
 
     public AsyncServer(final IOReactorConfig ioReactorConfig) {
-        super(ioReactorConfig, new ThreadFactoryImpl("listener", true), new ThreadFactoryImpl("server-dispatch",
true));
+        super(ioReactorConfig, new DefaultThreadFactory("listener", true), new DefaultThreadFactory("server-dispatch",
true));
     }
 
     @Override
@@ -52,7 +53,7 @@ public class AsyncServer extends IOReact
             final ThreadFactory threadFactory,
             final Callback<IOSession> sessionShutdownCallback) throws IOException {
         return new DefaultListeningIOReactor(
-                ioEventHandlerFactory, ioReactorConfig, threadFactory, sessionShutdownCallback);
+                ioEventHandlerFactory, ioReactorConfig, threadFactory, null, sessionShutdownCallback);
     }
 
     public ListenerEndpoint listen(final InetSocketAddress address) {

Modified: httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/IOReactorExecutor.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/IOReactorExecutor.java?rev=1792526&r1=1792525&r2=1792526&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/IOReactorExecutor.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/IOReactorExecutor.java
Mon Apr 24 18:10:55 2017
@@ -34,6 +34,7 @@ import java.util.concurrent.Executors;
 import java.util.concurrent.ThreadFactory;
 import java.util.concurrent.atomic.AtomicReference;
 
+import org.apache.hc.core5.concurrent.DefaultThreadFactory;
 import org.apache.hc.core5.function.Callback;
 import org.apache.hc.core5.http.ExceptionListener;
 import org.apache.hc.core5.http.nio.command.ShutdownCommand;
@@ -94,7 +95,7 @@ abstract class IOReactorExecutor<T exten
         if (ioReactorRef.compareAndSet(null, createIOReactor(
                 ioEventHandlerFactory,
                 ioReactorConfig,
-                workerThreadFactory != null ? workerThreadFactory : new ThreadFactoryImpl("i/o
dispatch"),
+                workerThreadFactory != null ? workerThreadFactory : new DefaultThreadFactory("i/o
dispatch"),
                 new Callback<IOSession>() {
 
                     @Override

Modified: httpcomponents/httpcore/trunk/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/TestDefaultListeningIOReactor.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/TestDefaultListeningIOReactor.java?rev=1792526&r1=1792525&r2=1792526&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/TestDefaultListeningIOReactor.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/TestDefaultListeningIOReactor.java
Mon Apr 24 18:10:55 2017
@@ -54,45 +54,47 @@ import org.junit.Test;
  */
 public class TestDefaultListeningIOReactor {
 
-    protected DefaultListeningIOReactor ioreactor;
+    private DefaultListeningIOReactor ioreactor;
 
-    @Before
-    public void setup() throws Exception {
-        final IOReactorConfig reactorConfig = IOReactorConfig.custom()
-                .setIoThreadCount(1)
-                .build();
-        this.ioreactor = new DefaultListeningIOReactor(new IOEventHandlerFactory() {
+    private static class NoopIOEventHandlerFactory implements IOEventHandlerFactory {
 
-            @Override
-            public IOEventHandler createHandler(final TlsCapableIOSession ioSession, final
Object attachment) {
-                return new IOEventHandler() {
+        @Override
+        public IOEventHandler createHandler(final TlsCapableIOSession ioSession, final Object
attachment) {
+            return new IOEventHandler() {
 
-                    @Override
-                    public void connected(final IOSession session) {
-                    }
+                @Override
+                public void connected(final IOSession session) {
+                }
 
-                    @Override
-                    public void inputReady(final IOSession session) {
-                    }
+                @Override
+                public void inputReady(final IOSession session) {
+                }
 
-                    @Override
-                    public void outputReady(final IOSession session) {
-                    }
+                @Override
+                public void outputReady(final IOSession session) {
+                }
 
-                    @Override
-                    public void timeout(final IOSession session) {
-                    }
+                @Override
+                public void timeout(final IOSession session) {
+                }
 
-                    @Override
-                    public void exception(final IOSession session, final Exception cause)
{
-                    }
+                @Override
+                public void exception(final IOSession session, final Exception cause) {
+                }
 
-                    @Override
-                    public void disconnected(final IOSession session) {
-                    }
-                };
-            }
-        }, reactorConfig, null);
+                @Override
+                public void disconnected(final IOSession session) {
+                }
+            };
+        }
+    }
+
+    @Before
+    public void setup() throws Exception {
+        final IOReactorConfig reactorConfig = IOReactorConfig.custom()
+                .setIoThreadCount(1)
+                .build();
+        this.ioreactor = new DefaultListeningIOReactor(new NoopIOEventHandlerFactory(), reactorConfig,
null, null);
     }
 
     @After
@@ -194,20 +196,20 @@ public class TestDefaultListeningIOReact
 
     @Test
     public void testEndpointAlreadyBoundNonFatal() throws Exception {
-        ioreactor.setExceptionHandler(new IOReactorExceptionHandler() {
-
-            @Override
-            public boolean handle(final IOException ex) {
-                return (ex instanceof BindException);
-            }
-
-            @Override
-            public boolean handle(final RuntimeException ex) {
-                return false;
-            }
+        final IOReactorConfig reactorConfig = IOReactorConfig.custom()
+                .setIoThreadCount(1)
+                .build();
+        ioreactor = new DefaultListeningIOReactor(
+                new NoopIOEventHandlerFactory(),
+                reactorConfig,
+                new IOReactorExceptionHandler() {
 
-        });
+                    @Override
+                    public boolean handle(final IOException ex) {
+                        return (ex instanceof BindException);
+                    }
 
+                }, null);
         final Thread t = new Thread(new Runnable() {
 
             @Override

Copied: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/concurrent/DefaultThreadFactory.java
(from r1792525, httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/ThreadFactoryImpl.java)
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/concurrent/DefaultThreadFactory.java?p2=httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/concurrent/DefaultThreadFactory.java&p1=httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/ThreadFactoryImpl.java&r1=1792525&r2=1792526&rev=1792526&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/ThreadFactoryImpl.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/concurrent/DefaultThreadFactory.java
Mon Apr 24 18:10:55 2017
@@ -24,33 +24,33 @@
  * <http://www.apache.org/>.
  *
  */
-package org.apache.hc.core5.http.impl.bootstrap;
+package org.apache.hc.core5.concurrent;
 
 import java.util.concurrent.ThreadFactory;
 import java.util.concurrent.atomic.AtomicLong;
 
 /**
- * @since 4.4
+ * @since 5.0
  */
-class ThreadFactoryImpl implements ThreadFactory {
+public class DefaultThreadFactory 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)
{
+    public DefaultThreadFactory(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) {
+    public DefaultThreadFactory(final String namePrefix, final boolean daemon) {
         this(namePrefix, null, daemon);
     }
 
-    ThreadFactoryImpl(final String namePrefix) {
+    public DefaultThreadFactory(final String namePrefix) {
         this(namePrefix, null, false);
     }
 

Propchange: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/concurrent/DefaultThreadFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/concurrent/DefaultThreadFactory.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/concurrent/DefaultThreadFactory.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

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=1792526&r1=1792525&r2=1792526&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
Mon Apr 24 18:10:55 2017
@@ -30,6 +30,7 @@ package org.apache.hc.core5.http.impl.bo
 import java.net.InetSocketAddress;
 import java.net.SocketAddress;
 
+import org.apache.hc.core5.concurrent.DefaultThreadFactory;
 import org.apache.hc.core5.function.Callback;
 import org.apache.hc.core5.http.ExceptionListener;
 import org.apache.hc.core5.http.HttpHost;
@@ -53,9 +54,9 @@ public class AsyncRequester extends IORe
             final ExceptionListener exceptionListener,
             final Callback<IOSession> sessionShutdownCallback) throws IOReactorException
{
         super(new DefaultConnectingIOReactor(
-                        eventHandlerFactory, ioReactorConfig, new ThreadFactoryImpl("requester-dispatch",
true), sessionShutdownCallback),
+                        eventHandlerFactory, ioReactorConfig, new DefaultThreadFactory("requester-dispatch",
true), sessionShutdownCallback),
                 exceptionListener,
-                new ThreadFactoryImpl("connector", true));
+                new DefaultThreadFactory("connector", true));
     }
 
     private InetSocketAddress toSocketAddress(final HttpHost host) {

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=1792526&r1=1792525&r2=1792526&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
Mon Apr 24 18:10:55 2017
@@ -30,6 +30,7 @@ package org.apache.hc.core5.http.impl.bo
 import java.net.InetSocketAddress;
 import java.util.Set;
 
+import org.apache.hc.core5.concurrent.DefaultThreadFactory;
 import org.apache.hc.core5.function.Callback;
 import org.apache.hc.core5.http.ExceptionListener;
 import org.apache.hc.core5.reactor.DefaultListeningIOReactor;
@@ -47,9 +48,9 @@ public class AsyncServer extends IOReact
             final ExceptionListener exceptionListener,
             final Callback<IOSession> sessionShutdownCallback) throws IOReactorException
{
         super(new DefaultListeningIOReactor(
-                    eventHandlerFactory, ioReactorConfig, new ThreadFactoryImpl("server-dispatch",
true), sessionShutdownCallback),
+                    eventHandlerFactory, ioReactorConfig, new DefaultThreadFactory("server-dispatch",
true), null, sessionShutdownCallback),
                 exceptionListener,
-                new ThreadFactoryImpl("listener", true));
+                new DefaultThreadFactory("listener", true));
     }
 
     public ListenerEndpoint listen(final InetSocketAddress address) {

Modified: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/HttpServer.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/HttpServer.java?rev=1792526&r1=1792525&r2=1792526&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/HttpServer.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/HttpServer.java
Mon Apr 24 18:10:55 2017
@@ -38,6 +38,7 @@ import java.util.concurrent.atomic.Atomi
 import javax.net.ServerSocketFactory;
 import javax.net.ssl.SSLServerSocket;
 
+import org.apache.hc.core5.concurrent.DefaultThreadFactory;
 import org.apache.hc.core5.http.ExceptionListener;
 import org.apache.hc.core5.http.config.SocketConfig;
 import org.apache.hc.core5.http.impl.io.DefaultBHttpServerConnection;
@@ -93,12 +94,12 @@ public class HttpServer implements Grace
         this.listenerExecutorService = new ThreadPoolExecutor(
                 1, 1, 0L, TimeUnit.MILLISECONDS,
                 new SynchronousQueue<Runnable>(),
-                new ThreadFactoryImpl("HTTP-listener-" + this.port));
+                new DefaultThreadFactory("HTTP-listener-" + this.port));
         this.workerThreads = new ThreadGroup("HTTP-workers");
         this.workerExecutorService = new WorkerPoolExecutor(
                 0, Integer.MAX_VALUE, 1L, TimeUnit.SECONDS,
                 new SynchronousQueue<Runnable>(),
-                new ThreadFactoryImpl("HTTP-worker", this.workerThreads, false));
+                new DefaultThreadFactory("HTTP-worker", this.workerThreads, false));
         this.status = new AtomicReference<>(Status.READY);
     }
 

Modified: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/reactor/AbstractMultiworkerIOReactor.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/reactor/AbstractMultiworkerIOReactor.java?rev=1792526&r1=1792525&r2=1792526&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/reactor/AbstractMultiworkerIOReactor.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/reactor/AbstractMultiworkerIOReactor.java
Mon Apr 24 18:10:55 2017
@@ -42,9 +42,9 @@ import java.util.Date;
 import java.util.List;
 import java.util.concurrent.ThreadFactory;
 import java.util.concurrent.TimeUnit;
-import java.util.concurrent.atomic.AtomicLong;
 import java.util.concurrent.atomic.AtomicReference;
 
+import org.apache.hc.core5.concurrent.DefaultThreadFactory;
 import org.apache.hc.core5.function.Callback;
 import org.apache.hc.core5.io.ShutdownType;
 import org.apache.hc.core5.util.Args;
@@ -92,22 +92,19 @@ import org.apache.hc.core5.util.TimeValu
  */
 public abstract class AbstractMultiworkerIOReactor implements IOReactor {
 
-    protected final IOReactorConfig reactorConfig;
-    protected final Selector selector;
+    private final IOReactorConfig reactorConfig;
+    private final Selector selector;
     private final int workerCount;
     private final IOEventHandlerFactory eventHandlerFactory;
     private final ThreadFactory threadFactory;
     private final Callback<IOSession> sessionShutdownCallback;
     private final IOReactorImpl[] dispatchers;
-    private final Worker[] workers;
+    private final IODispatchWorker[] workers;
     private final Thread[] threads;
+    private final List<ExceptionEvent> auditLog;
     private final AtomicReference<IOReactorStatus> status;
     private final Object shutdownMutex;
 
-    //TODO: make final
-    protected IOReactorExceptionHandler exceptionHandler;
-    protected List<ExceptionEvent> auditLog;
-
     private int currentWorker = 0;
 
     /**
@@ -134,12 +131,12 @@ public abstract class AbstractMultiworke
         } catch (final IOException ex) {
             throw new IOReactorException("Failure opening selector", ex);
         }
-        this.threadFactory = threadFactory != null ? threadFactory : new DefaultThreadFactory();
+        this.threadFactory = threadFactory != null ? threadFactory : new DefaultThreadFactory("I/O
dispatcher", true);
         this.sessionShutdownCallback = sessionShutdownCallback;
         this.auditLog = new ArrayList<>();
         this.workerCount = this.reactorConfig.getIoThreadCount();
         this.dispatchers = new IOReactorImpl[workerCount];
-        this.workers = new Worker[workerCount];
+        this.workers = new IODispatchWorker[workerCount];
         this.threads = new Thread[workerCount];
         this.status = new AtomicReference<>(IOReactorStatus.INACTIVE);
         this.shutdownMutex = new Object();
@@ -151,6 +148,10 @@ public abstract class AbstractMultiworke
         this(eventHandlerFactory, null, null, sessionShutdownCallback);
     }
 
+    Selector selector() {
+        return selector;
+    }
+
     @Override
     public IOReactorStatus getStatus() {
         return this.status.get();
@@ -176,7 +177,7 @@ public abstract class AbstractMultiworke
      * @param timestamp the time stamp of the exception. Can be
      * {@code null} in which case the current date / time will be used.
      */
-    protected synchronized void addExceptionEvent(final Throwable ex, final Date timestamp)
{
+    void addExceptionEvent(final Throwable ex, final Date timestamp) {
         if (ex == null) {
             return;
         }
@@ -190,20 +191,11 @@ public abstract class AbstractMultiworke
      *
      * @param ex the exception thrown by the I/O reactor.
      */
-    protected void addExceptionEvent(final Throwable ex) {
+    void addExceptionEvent(final Throwable ex) {
         addExceptionEvent(ex, null);
     }
 
     /**
-     * Sets exception handler for this I/O reactor.
-     *
-     * @param exceptionHandler the exception handler.
-     */
-    public void setExceptionHandler(final IOReactorExceptionHandler exceptionHandler) {
-        this.exceptionHandler = exceptionHandler;
-    }
-
-    /**
      * Triggered to process I/O events registered by the main {@link Selector}.
      * <p>
      * Super-classes can implement this method to react to the event.
@@ -256,13 +248,12 @@ public abstract class AbstractMultiworke
                 final IOReactorImpl dispatcher = new IOReactorImpl(
                         this.eventHandlerFactory,
                         this.reactorConfig,
-                        this.exceptionHandler,
                         this.sessionShutdownCallback);
                 this.dispatchers[i] = dispatcher;
             }
             for (int i = 0; i < this.workerCount; i++) {
                 final IOReactorImpl dispatcher = this.dispatchers[i];
-                this.workers[i] = new Worker(dispatcher);
+                this.workers[i] = new IODispatchWorker(dispatcher);
                 this.threads[i] = this.threadFactory.newThread(this.workers[i]);
             }
 
@@ -296,7 +287,7 @@ public abstract class AbstractMultiworke
 
                 // Verify I/O dispatchers
                 for (int i = 0; i < this.workerCount; i++) {
-                    final Worker worker = this.workers[i];
+                    final IODispatchWorker worker = this.workers[i];
                     final Throwable ex = worker.getThrowable();
                     if (ex != null) {
                         throw new IOReactorException("I/O dispatch worker terminated abnormally",
ex);
@@ -487,13 +478,13 @@ public abstract class AbstractMultiworke
         }
     }
 
-    static class Worker implements Runnable {
+    static class IODispatchWorker implements Runnable {
 
         final IOReactorImpl dispatcher;
 
         private volatile Throwable throwable;
 
-        public Worker(final IOReactorImpl dispatcher) {
+        public IODispatchWorker(final IOReactorImpl dispatcher) {
             super();
             this.dispatcher = dispatcher;
         }
@@ -515,16 +506,5 @@ public abstract class AbstractMultiworke
         }
 
     }
-
-    static class DefaultThreadFactory implements ThreadFactory {
-
-        private final static AtomicLong COUNT = new AtomicLong(1);
-
-        @Override
-        public Thread newThread(final Runnable r) {
-            return new Thread(r, "I/O dispatcher " + COUNT.getAndIncrement());
-        }
-
-    }
 
 }

Modified: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/reactor/DefaultConnectingIOReactor.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/reactor/DefaultConnectingIOReactor.java?rev=1792526&r1=1792525&r2=1792526&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/reactor/DefaultConnectingIOReactor.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/reactor/DefaultConnectingIOReactor.java
Mon Apr 24 18:10:55 2017
@@ -55,17 +55,18 @@ import org.apache.hc.core5.util.Asserts;
 public class DefaultConnectingIOReactor extends AbstractMultiworkerIOReactor
         implements ConnectingIOReactor {
 
+    private final IOReactorConfig reactorConfig;
     private final Queue<SessionRequestImpl> requestQueue;
-
     private final long selectInterval;
     private long lastTimeoutCheck;
 
     public DefaultConnectingIOReactor(
             final IOEventHandlerFactory eventHandlerFactory,
-            final IOReactorConfig reactorConfig,
+            final IOReactorConfig ioReactorConfig,
             final ThreadFactory threadFactory,
             final Callback<IOSession> sessionShutdownCallback) throws IOReactorException
{
-        super(eventHandlerFactory, reactorConfig, threadFactory, sessionShutdownCallback);
+        super(eventHandlerFactory, ioReactorConfig, threadFactory, sessionShutdownCallback);
+        this.reactorConfig = ioReactorConfig != null ? ioReactorConfig : IOReactorConfig.DEFAULT;
         this.requestQueue = new ConcurrentLinkedQueue<>();
         this.selectInterval = this.reactorConfig.getSelectInterval();
         this.lastTimeoutCheck = System.currentTimeMillis();
@@ -103,7 +104,7 @@ public class DefaultConnectingIOReactor
         processSessionRequests();
 
         if (readyCount > 0) {
-            final Set<SelectionKey> selectedKeys = this.selector.selectedKeys();
+            final Set<SelectionKey> selectedKeys = selector().selectedKeys();
             for (final SelectionKey key : selectedKeys) {
 
                 processEvent(key);
@@ -115,7 +116,7 @@ public class DefaultConnectingIOReactor
         final long currentTime = System.currentTimeMillis();
         if ((currentTime - this.lastTimeoutCheck) >= this.selectInterval) {
             this.lastTimeoutCheck = currentTime;
-            final Set<SelectionKey> keys = this.selector.keys();
+            final Set<SelectionKey> keys = selector().keys();
             processTimeouts(keys);
         }
     }
@@ -197,7 +198,7 @@ public class DefaultConnectingIOReactor
                 callback);
 
         this.requestQueue.add(sessionRequest);
-        this.selector.wakeup();
+        selector().wakeup();
 
         return sessionRequest;
     }
@@ -252,7 +253,7 @@ public class DefaultConnectingIOReactor
 
             final SessionRequestHandle requestHandle = new SessionRequestHandle(request);
             try {
-                final SelectionKey key = socketChannel.register(this.selector, SelectionKey.OP_CONNECT,
+                final SelectionKey key = socketChannel.register(selector(), SelectionKey.OP_CONNECT,
                         requestHandle);
                 request.setKey(key);
             } catch (final IOException ex) {

Modified: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/reactor/DefaultListeningIOReactor.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/reactor/DefaultListeningIOReactor.java?rev=1792526&r1=1792525&r2=1792526&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/reactor/DefaultListeningIOReactor.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/reactor/DefaultListeningIOReactor.java
Mon Apr 24 18:10:55 2017
@@ -55,6 +55,8 @@ import org.apache.hc.core5.util.Asserts;
 public class DefaultListeningIOReactor extends AbstractMultiworkerIOReactor
         implements ListeningIOReactor {
 
+    private final IOReactorConfig reactorConfig;
+    private final IOReactorExceptionHandler exceptionHandler;
     private final Queue<ListenerEndpointImpl> requestQueue;
     private final Set<ListenerEndpointImpl> endpoints;
     private final Set<SocketAddress> pausedEndpoints;
@@ -65,7 +67,7 @@ public class DefaultListeningIOReactor e
      * Creates an instance of DefaultListeningIOReactor with the given configuration.
      *
      * @param eventHandlerFactory the factory to create I/O event handlers.
-     * @param config I/O reactor configuration.
+     * @param ioReactorConfig I/O reactor configuration.
      * @param threadFactory the factory to create threads.
      *   Can be {@code null}.
      * @throws IOReactorException in case if a non-recoverable I/O error.
@@ -74,10 +76,13 @@ public class DefaultListeningIOReactor e
      */
     public DefaultListeningIOReactor(
             final IOEventHandlerFactory eventHandlerFactory,
-            final IOReactorConfig config,
+            final IOReactorConfig ioReactorConfig,
             final ThreadFactory threadFactory,
+            final IOReactorExceptionHandler exceptionHandler,
             final Callback<IOSession> sessionShutdownCallback) throws IOReactorException
{
-        super(eventHandlerFactory, config, threadFactory, sessionShutdownCallback);
+        super(eventHandlerFactory, ioReactorConfig, threadFactory, sessionShutdownCallback);
+        this.reactorConfig = ioReactorConfig != null ? ioReactorConfig : IOReactorConfig.DEFAULT;
+        this.exceptionHandler = exceptionHandler;
         this.requestQueue = new ConcurrentLinkedQueue<>();
         this.endpoints = Collections.synchronizedSet(new HashSet<ListenerEndpointImpl>());
         this.pausedEndpoints = new HashSet<>();
@@ -96,8 +101,9 @@ public class DefaultListeningIOReactor e
     public DefaultListeningIOReactor(
             final IOEventHandlerFactory eventHandlerFactory,
             final IOReactorConfig config,
+            final IOReactorExceptionHandler exceptionHandler,
             final Callback<IOSession> sessionShutdownCallback) throws IOReactorException
{
-        this(eventHandlerFactory, config, null, sessionShutdownCallback);
+        this(eventHandlerFactory, config, null, exceptionHandler, sessionShutdownCallback);
     }
 
     /**
@@ -108,9 +114,8 @@ public class DefaultListeningIOReactor e
      *
      * @since 5.0
      */
-    public DefaultListeningIOReactor(
-            final IOEventHandlerFactory eventHandlerFactory) throws IOReactorException {
-        this(eventHandlerFactory, null, null);
+    public DefaultListeningIOReactor(final IOEventHandlerFactory eventHandlerFactory) throws
IOReactorException {
+        this(eventHandlerFactory, null, null, null);
     }
 
     @Override
@@ -128,7 +133,7 @@ public class DefaultListeningIOReactor e
         }
 
         if (readyCount > 0) {
-            final Set<SelectionKey> selectedKeys = this.selector.selectedKeys();
+            final Set<SelectionKey> selectedKeys = selector().selectedKeys();
             for (final SelectionKey key : selectedKeys) {
 
                 processEvent(key);
@@ -150,10 +155,8 @@ public class DefaultListeningIOReactor e
                     try {
                         socketChannel = serverChannel.accept();
                     } catch (final IOException ex) {
-                        if (this.exceptionHandler == null ||
-                                !this.exceptionHandler.handle(ex)) {
-                            throw new IOReactorException(
-                                    "Failure accepting connection", ex);
+                        if (this.exceptionHandler == null || !this.exceptionHandler.handle(ex))
{
+                            throw new IOReactorException("Failure accepting connection",
ex);
                         }
                     }
                     if (socketChannel == null) {
@@ -162,10 +165,8 @@ public class DefaultListeningIOReactor e
                     try {
                         prepareSocket(socketChannel.socket());
                     } catch (final IOException ex) {
-                        if (this.exceptionHandler == null ||
-                                !this.exceptionHandler.handle(ex)) {
-                            throw new IOReactorException(
-                                    "Failure initalizing socket", ex);
+                        if (this.exceptionHandler == null || !this.exceptionHandler.handle(ex))
{
+                            throw new IOReactorException("Failure initalizing socket", ex);
                         }
                     }
                     enqueuePendingSession(socketChannel, null);
@@ -198,7 +199,7 @@ public class DefaultListeningIOReactor e
         Asserts.check(status == IOReactorStatus.INACTIVE || status == IOReactorStatus.ACTIVE,
"I/O reactor has been shut down");
         final ListenerEndpointImpl request = createEndpoint(address);
         this.requestQueue.add(request);
-        this.selector.wakeup();
+        selector().wakeup();
         return request;
     }
 
@@ -234,7 +235,7 @@ public class DefaultListeningIOReactor e
                 return;
             }
             try {
-                final SelectionKey key = serverChannel.register(this.selector, SelectionKey.OP_ACCEPT);
+                final SelectionKey key = serverChannel.register(selector(), SelectionKey.OP_ACCEPT);
                 key.attach(request);
                 request.setKey(key);
             } catch (final IOException ex) {
@@ -293,7 +294,7 @@ public class DefaultListeningIOReactor e
             this.requestQueue.add(request);
         }
         this.pausedEndpoints.clear();
-        this.selector.wakeup();
+        selector().wakeup();
     }
 
 }

Modified: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/reactor/IOReactorExceptionHandler.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/reactor/IOReactorExceptionHandler.java?rev=1792526&r1=1792525&r2=1792526&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/reactor/IOReactorExceptionHandler.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/reactor/IOReactorExceptionHandler.java
Mon Apr 24 18:10:55 2017
@@ -49,16 +49,4 @@ public interface IOReactorExceptionHandl
      */
     boolean handle(IOException ex);
 
-    /**
-     * This method is expected to examine the runtime exception passed as
-     * a parameter and decide whether it is safe to continue execution of
-     * the I/O reactor.
-     *
-     * @param ex potentially recoverable runtime exception
-     * @return {@code true} if it is safe to ignore the exception
-     * and continue execution of the I/O reactor; {@code false} if the
-     * I/O reactor must throw {@link RuntimeException} and terminate
-     */
-    boolean handle(RuntimeException ex);
-
 }

Modified: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/reactor/IOReactorImpl.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/reactor/IOReactorImpl.java?rev=1792526&r1=1792525&r2=1792526&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/reactor/IOReactorImpl.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/reactor/IOReactorImpl.java
Mon Apr 24 18:10:55 2017
@@ -63,7 +63,6 @@ class IOReactorImpl implements IOReactor
     private final AtomicReference<IOReactorStatus> status;
     private final AtomicBoolean shutdownInitiated;
     private final Object shutdownMutex;
-    private final IOReactorExceptionHandler exceptionHandler;
     private final Callback<IOSession> sessionShutdownCallback;
 
     private volatile long lastTimeoutCheck;
@@ -71,12 +70,10 @@ class IOReactorImpl implements IOReactor
     IOReactorImpl(
             final IOEventHandlerFactory eventHandlerFactory,
             final IOReactorConfig reactorConfig,
-            final IOReactorExceptionHandler exceptionHandler,
             final Callback<IOSession> sessionShutdownCallback) {
         super();
         this.reactorConfig = Args.notNull(reactorConfig, "I/O reactor config");
         this.eventHandlerFactory = Args.notNull(eventHandlerFactory, "Event handler factory");
-        this.exceptionHandler = exceptionHandler;
         this.sessionShutdownCallback = sessionShutdownCallback;
         this.shutdownInitiated = new AtomicBoolean(false);
         this.closedSessions = new ConcurrentLinkedQueue<>();
@@ -232,12 +229,6 @@ class IOReactorImpl implements IOReactor
         selectedKeys.clear();
     }
 
-    private void handleRuntimeException(final RuntimeException ex) {
-        if (this.exceptionHandler == null || !this.exceptionHandler.handle(ex)) {
-            throw ex;
-        }
-    }
-
     private void processEvent(final SelectionKey key) {
         final InternalIOSession session = (InternalIOSession) key.attachment();
         try {
@@ -253,7 +244,7 @@ class IOReactorImpl implements IOReactor
             session.shutdown(ShutdownType.GRACEFUL);
         } catch (final RuntimeException ex) {
             session.shutdown(ShutdownType.IMMEDIATE);
-            handleRuntimeException(ex);
+            throw ex;
         }
     }
 
@@ -288,11 +279,7 @@ class IOReactorImpl implements IOReactor
                 if (sessionRequest != null) {
                     sessionRequest.completed(session);
                 }
-                try {
-                    session.onConnected();
-                } catch (final RuntimeException ex) {
-                    handleRuntimeException(ex);
-                }
+                session.onConnected();
             } catch (final CancelledKeyException ex) {
                 session.shutdown(ShutdownType.GRACEFUL);
             }
@@ -309,8 +296,6 @@ class IOReactorImpl implements IOReactor
                 session.onDisconnected();
             } catch (final CancelledKeyException ex) {
                 // ignore and move on
-            } catch (final RuntimeException ex) {
-                handleRuntimeException(ex);
             }
         }
     }
@@ -329,7 +314,7 @@ class IOReactorImpl implements IOReactor
                 session.shutdown(ShutdownType.GRACEFUL);
             } catch (final RuntimeException ex) {
                 session.shutdown(ShutdownType.IMMEDIATE);
-                handleRuntimeException(ex);
+                throw ex;
             }
         }
     }



Mime
View raw message