hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r502725 - in /jakarta/httpcomponents/httpcore/trunk: ./ module-nio/src/main/java/org/apache/http/nio/concurrent/ module-nio/src/main/java/org/apache/http/nio/impl/reactor/ module-nio/src/test/java/org/apache/http/nio/mockup/
Date Fri, 02 Feb 2007 20:23:44 GMT
Author: olegk
Date: Fri Feb  2 12:23:43 2007
New Revision: 502725

URL: http://svn.apache.org/viewvc?view=rev&rev=502725
Log:
HTTPCORE-27: I/O reactors can now accept a thread factory as an optional parameter

Added:
    jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/concurrent/ThreadFactory.java
  (with props)
Modified:
    jakarta/httpcomponents/httpcore/trunk/RELEASE_NOTES.txt
    jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/impl/reactor/AbstractMultiworkerIOReactor.java
    jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/impl/reactor/DefaultConnectingIOReactor.java
    jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/impl/reactor/DefaultListeningIOReactor.java
    jakarta/httpcomponents/httpcore/trunk/module-nio/src/test/java/org/apache/http/nio/mockup/TestHttpClient.java
    jakarta/httpcomponents/httpcore/trunk/module-nio/src/test/java/org/apache/http/nio/mockup/TestHttpServer.java

Modified: jakarta/httpcomponents/httpcore/trunk/RELEASE_NOTES.txt
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/RELEASE_NOTES.txt?view=diff&rev=502725&r1=502724&r2=502725
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/RELEASE_NOTES.txt (original)
+++ jakarta/httpcomponents/httpcore/trunk/RELEASE_NOTES.txt Fri Feb  2 12:23:43 2007
@@ -1,5 +1,10 @@
 Changes since release 4.0 Alpha 3
 -------------------
+
+* [HTTPCORE-27]: I/O reactors can now accept a thread factory as an optional
+  parameter.
+  Contributed by Oleg Kalnichevski <olegk at apache.org>
+
 * [HTTPCORE-36]: Fixed #setHandlers() method and matching of request URIs 
   with a query part in HttpRequestHandlerRegistry
   Contributed by Oleg Kalnichevski <olegk at apache.org>

Added: jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/concurrent/ThreadFactory.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/concurrent/ThreadFactory.java?view=auto&rev=502725
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/concurrent/ThreadFactory.java
(added)
+++ jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/concurrent/ThreadFactory.java
Fri Feb  2 12:23:43 2007
@@ -0,0 +1,44 @@
+/*
+ * $HeadURL$
+ * $Revision$
+ * $Date$
+ *
+ * ====================================================================
+ * 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.http.nio.concurrent;
+
+/**
+ * Abstract thread factory. This interface is needed in order to
+ * avoid direct dependency on java.util.concurrent
+ * 
+ * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
+ */
+public interface ThreadFactory {
+
+    Thread newThread(Runnable r);
+    
+}

Propchange: jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/concurrent/ThreadFactory.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/concurrent/ThreadFactory.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/impl/reactor/AbstractMultiworkerIOReactor.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/impl/reactor/AbstractMultiworkerIOReactor.java?view=diff&rev=502725&r1=502724&r2=502725
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/impl/reactor/AbstractMultiworkerIOReactor.java
(original)
+++ jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/impl/reactor/AbstractMultiworkerIOReactor.java
Fri Feb  2 12:23:43 2007
@@ -33,6 +33,7 @@
 
 import java.io.InterruptedIOException;
 
+import org.apache.http.nio.concurrent.ThreadFactory;
 import org.apache.http.nio.reactor.IOEventDispatch;
 import org.apache.http.nio.reactor.IOReactor;
 import org.apache.http.nio.reactor.IOReactorException;
@@ -40,29 +41,40 @@
 public abstract class AbstractMultiworkerIOReactor implements IOReactor {
 
     private final int workerCount;
+    private final ThreadFactory threadFactory;
     private final BaseIOReactor[] ioReactors;
-    private final WorkerThread[] threads;
+    private final Worker[] workers;
+    private final Thread[] threads;
     
     private int currentWorker = 0;
     
-    public AbstractMultiworkerIOReactor(long selectTimeout, int workerCount) 
-            throws IOReactorException {
+    public AbstractMultiworkerIOReactor(
+            long selectTimeout, 
+            int workerCount, 
+            final ThreadFactory threadFactory) throws IOReactorException {
         super();
         if (workerCount <= 0) {
             throw new IllegalArgumentException("Worker count may not be negative or zero");
         }
         this.workerCount = workerCount;
+        if (threadFactory != null) {
+            this.threadFactory = threadFactory;
+        } else {
+            this.threadFactory = new DefaultThreadFactory();
+        }
         this.ioReactors = new BaseIOReactor[workerCount];
-        this.threads = new WorkerThread[workerCount];
         for (int i = 0; i < this.ioReactors.length; i++) {
             this.ioReactors[i] = new BaseIOReactor(selectTimeout);
         }
+        this.workers = new Worker[workerCount];
+        this.threads = new Thread[workerCount];
     }
 
     protected void startWorkers(final IOEventDispatch eventDispatch) {
         for (int i = 0; i < this.workerCount; i++) {
             BaseIOReactor ioReactor = this.ioReactors[i];
-            this.threads[i] = new WorkerThread(ioReactor, eventDispatch);
+            this.workers[i] = new Worker(ioReactor, eventDispatch);
+            this.threads[i] = this.threadFactory.newThread(this.workers[i]);
         }
         for (int i = 0; i < this.workerCount; i++) {
             this.threads[i].start();
@@ -86,8 +98,9 @@
     protected void verifyWorkers() 
             throws InterruptedIOException, IOReactorException {
         for (int i = 0; i < this.workerCount; i++) {
-            WorkerThread worker = this.threads[i];
-            if (!worker.isAlive()) {
+            Worker worker = this.workers[i];
+            Thread thread = this.threads[i];
+            if (!thread.isAlive()) {
                 if (worker.getReactorException() != null) {
                     throw worker.getReactorException();
                 }
@@ -103,7 +116,7 @@
         this.ioReactors[this.currentWorker++ % this.workerCount].addChannel(entry);
     }
         
-    static class WorkerThread extends Thread {
+    static class Worker implements Runnable {
 
         final BaseIOReactor ioReactor;
         final IOEventDispatch eventDispatch;
@@ -111,7 +124,7 @@
         private volatile IOReactorException reactorException;
         private volatile InterruptedIOException interruptedException;
         
-        public WorkerThread(final BaseIOReactor ioReactor, final IOEventDispatch eventDispatch)
{
+        public Worker(final BaseIOReactor ioReactor, final IOEventDispatch eventDispatch)
{
             super();
             this.ioReactor = ioReactor;
             this.eventDispatch = eventDispatch;
@@ -145,4 +158,12 @@
         
     }
 
+    static class DefaultThreadFactory implements ThreadFactory {
+
+        public Thread newThread(final Runnable r) {
+            return new Thread(r, "I/O reactor worker thread");
+        }
+        
+    }
+    
 }

Modified: jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/impl/reactor/DefaultConnectingIOReactor.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/impl/reactor/DefaultConnectingIOReactor.java?view=diff&rev=502725&r1=502724&r2=502725
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/impl/reactor/DefaultConnectingIOReactor.java
(original)
+++ jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/impl/reactor/DefaultConnectingIOReactor.java
Fri Feb  2 12:23:43 2007
@@ -42,6 +42,7 @@
 import java.util.Iterator;
 import java.util.Set;
 
+import org.apache.http.nio.concurrent.ThreadFactory;
 import org.apache.http.nio.reactor.ConnectingIOReactor;
 import org.apache.http.nio.reactor.IOEventDispatch;
 import org.apache.http.nio.reactor.IOReactorException;
@@ -62,9 +63,11 @@
     
     private long lastTimeoutCheck;
     
-    public DefaultConnectingIOReactor(int workerCount, final HttpParams params) 
-            throws IOReactorException {
-        super(TIMEOUT_CHECK_INTERVAL, workerCount);
+    public DefaultConnectingIOReactor(
+            int workerCount, 
+            final ThreadFactory threadFactory,
+            final HttpParams params) throws IOReactorException {
+        super(TIMEOUT_CHECK_INTERVAL, workerCount, threadFactory);
         if (params == null) {
             throw new IllegalArgumentException("HTTP parameters may not be null");
         }
@@ -78,6 +81,12 @@
         }
     }
 
+    public DefaultConnectingIOReactor(
+            int workerCount, 
+            final HttpParams params) throws IOReactorException {
+        this(workerCount, null, params);
+    }
+    
     public void execute(final IOEventDispatch eventDispatch) 
             throws InterruptedIOException, IOReactorException {
         if (eventDispatch == null) {

Modified: jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/impl/reactor/DefaultListeningIOReactor.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/impl/reactor/DefaultListeningIOReactor.java?view=diff&rev=502725&r1=502724&r2=502725
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/impl/reactor/DefaultListeningIOReactor.java
(original)
+++ jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/impl/reactor/DefaultListeningIOReactor.java
Fri Feb  2 12:23:43 2007
@@ -43,6 +43,7 @@
 import java.util.Iterator;
 import java.util.Set;
 
+import org.apache.http.nio.concurrent.ThreadFactory;
 import org.apache.http.nio.reactor.IOEventDispatch;
 import org.apache.http.nio.reactor.IOReactorException;
 import org.apache.http.nio.reactor.IOReactorExceptionHandler;
@@ -62,9 +63,11 @@
     
     private IOReactorExceptionHandler exceptionHandler;
     
-    public DefaultListeningIOReactor(int workerCount, final HttpParams params) 
-            throws IOReactorException {
-        super(TIMEOUT_CHECK_INTERVAL, workerCount);
+    public DefaultListeningIOReactor(
+            int workerCount, 
+            final ThreadFactory threadFactory,
+            final HttpParams params) throws IOReactorException {
+        super(TIMEOUT_CHECK_INTERVAL, workerCount, threadFactory);
         if (params == null) {
             throw new IllegalArgumentException("HTTP parameters may not be null");
         }
@@ -76,6 +79,12 @@
         }
     }
 
+    public DefaultListeningIOReactor(
+            int workerCount, 
+            final HttpParams params) throws IOReactorException {
+        this(workerCount, null, params);
+    }
+    
     public void setExceptionHandler(final IOReactorExceptionHandler exceptionHandler) {
         this.exceptionHandler = exceptionHandler;
     }

Modified: jakarta/httpcomponents/httpcore/trunk/module-nio/src/test/java/org/apache/http/nio/mockup/TestHttpClient.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-nio/src/test/java/org/apache/http/nio/mockup/TestHttpClient.java?view=diff&rev=502725&r1=502724&r2=502725
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-nio/src/test/java/org/apache/http/nio/mockup/TestHttpClient.java
(original)
+++ jakarta/httpcomponents/httpcore/trunk/module-nio/src/test/java/org/apache/http/nio/mockup/TestHttpClient.java
Fri Feb  2 12:23:43 2007
@@ -64,7 +64,7 @@
             .setBooleanParameter(HttpConnectionParams.TCP_NODELAY, true)
             .setParameter(HttpProtocolParams.USER_AGENT, "TEST-CLIENT/1.1");
 
-        this.ioReactor = new DefaultConnectingIOReactor(1, this.params);
+        this.ioReactor = new DefaultConnectingIOReactor(2, this.params);
     }
     
     public void setHttpRequestExecutionHandler(final HttpRequestExecutionHandler handler)
{

Modified: jakarta/httpcomponents/httpcore/trunk/module-nio/src/test/java/org/apache/http/nio/mockup/TestHttpServer.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-nio/src/test/java/org/apache/http/nio/mockup/TestHttpServer.java?view=diff&rev=502725&r1=502724&r2=502725
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-nio/src/test/java/org/apache/http/nio/mockup/TestHttpServer.java
(original)
+++ jakarta/httpcomponents/httpcore/trunk/module-nio/src/test/java/org/apache/http/nio/mockup/TestHttpServer.java
Fri Feb  2 12:23:43 2007
@@ -73,7 +73,7 @@
             .setParameter(HttpProtocolParams.ORIGIN_SERVER, "TEST-SERVER/1.1");
         
         this.reqistry = new HttpRequestHandlerRegistry();
-        this.ioReactor = new DefaultListeningIOReactor(1, this.params);
+        this.ioReactor = new DefaultListeningIOReactor(2, this.params);
         this.mutex = new Object();
     }
     



Mime
View raw message