You are viewing a plain text version of this content. The canonical link for it is here.
Posted to axis-cvs@ws.apache.org by di...@apache.org on 2007/06/23 03:17:38 UTC

svn commit: r549993 - in /webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/server: DefaultHttpConnectionManager.java HttpServiceProcessor.java

Author: dims
Date: Fri Jun 22 18:17:37 2007
New Revision: 549993

URL: http://svn.apache.org/viewvc?view=rev&rev=549993
Log:
Fix for AXIS2-2595 - HttpServiceProcessor needs hashCode and equals

Modified:
    webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/server/DefaultHttpConnectionManager.java
    webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/server/HttpServiceProcessor.java

Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/server/DefaultHttpConnectionManager.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/server/DefaultHttpConnectionManager.java?view=diff&rev=549993&r1=549992&r2=549993
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/server/DefaultHttpConnectionManager.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/server/DefaultHttpConnectionManager.java Fri Jun 22 18:17:37 2007
@@ -54,17 +54,23 @@
     private static Log LOG = LogFactory.getLog(DefaultHttpConnectionManager.class);
 
     private final ConfigurationContext configurationContext;
+
+    /** The thread pool used to execute processors. */
     private final Executor executor;
+
     private final WorkerFactory workerfactory;
+
     private final HttpParams params;
+
+    /** The list of processors. */
+    // XXX: is this list really needed?
     private final List processors;
 
     private HttpFactory httpFactory = null;
 
-    public DefaultHttpConnectionManager(
-            final ConfigurationContext configurationContext,
-            final Executor executor,
-            final WorkerFactory workerfactory,
+
+    public DefaultHttpConnectionManager(final ConfigurationContext configurationContext,
+            final Executor executor, final WorkerFactory workerfactory,
             final HttpParams params) {
         super();
         if (configurationContext == null) {
@@ -86,7 +92,7 @@
         this.processors = new LinkedList();
     }
 
-    public DefaultHttpConnectionManager(
+	public DefaultHttpConnectionManager(
             final ConfigurationContext configurationContext,
             final Executor executor,
             final WorkerFactory workerfactory,
@@ -97,6 +103,12 @@
     }
 
 
+    /**
+     * Removes the destroyed processors.
+     * 
+     * @see IOProcessor#destroy()
+     */
+    //XXX: is this method really needed? Processors are removed as soon as they complete
     private synchronized void cleanup() {
         for (Iterator i = this.processors.iterator(); i.hasNext();) {
             IOProcessor processor = (IOProcessor) i.next();
@@ -106,20 +118,38 @@
         }
     }
 
+
+    /**
+     * Adds the specified {@linkplain IOProcessor} to the list of processors in 
+     * progress.
+     * 
+     * @param processor The processor to add.
+     * @throws NullPointerException If processor is <code>null</code>.
+     */
     private synchronized void addProcessor(final IOProcessor processor) {
         if (processor == null) {
-            return;
+            throw new NullPointerException("The processor can't be null");
         }
         this.processors.add(processor);
     }
 
-    private synchronized void removeProcessor(final IOProcessor processor) {
+
+    /**
+     * Removes the specified {@linkplain IOProcessor} from the list of
+     * processors.
+     * 
+     * @param processor The processor to remove.
+     * @throws NullPointerException If processor is <code>null</code>.
+     */
+    synchronized void removeProcessor(final IOProcessor processor)
+        throws NullPointerException {
         if (processor == null) {
-            return;
+            throw new NullPointerException("The processor can't be null");
         }
         this.processors.remove(processor);
     }
 
+
     public void process(final AxisHttpConnection conn) {
         if (conn == null) {
             throw new IllegalArgumentException("HTTP connection may not be null");
@@ -149,12 +179,8 @@
             responseFactory = new DefaultHttpResponseFactory();
         }
 
-        AxisHttpService httpService = new AxisHttpService(
-                httpProcessor,
-                connStrategy,
-                responseFactory,
-                this.configurationContext,
-                this.workerfactory.newWorker());
+        AxisHttpService httpService = new AxisHttpService(httpProcessor, connStrategy,
+            responseFactory, this.configurationContext, this.workerfactory.newWorker());
         httpService.setParams(this.params);
 
         // Create I/O processor to execute HTTP service
@@ -168,14 +194,12 @@
             }
 
         };
-        IOProcessor processor = new HttpServiceProcessor(
-                httpService,
-                conn,
-                callback);
+        IOProcessor processor = new HttpServiceProcessor(httpService, conn, callback);
 
         addProcessor(processor);
         this.executor.execute(processor);
     }
+
 
     public synchronized void shutdown() {
         for (int i = 0; i < this.processors.size(); i++) {

Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/server/HttpServiceProcessor.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/server/HttpServiceProcessor.java?view=diff&rev=549993&r1=549992&r2=549993
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/server/HttpServiceProcessor.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/server/HttpServiceProcessor.java Fri Jun 22 18:17:37 2007
@@ -36,41 +36,62 @@
 import org.apache.http.protocol.HttpContext;
 import org.apache.http.protocol.HttpExecutionContext;
 
+import edu.emory.mathcs.backport.java.util.concurrent.atomic.AtomicBoolean;
+import edu.emory.mathcs.backport.java.util.concurrent.atomic.AtomicLong;
+
 import java.io.IOException;
 import java.net.SocketException;
 import java.net.SocketTimeoutException;
 
 /**
  * I/O processor intended to process requests and fill in responses.
- *
+ * 
  * @author Chuck Williams
  */
 public class HttpServiceProcessor implements IOProcessor {
 
     private static final Log LOG = LogFactory.getLog(HttpServiceProcessor.class);
 
-    private volatile boolean terminated;
+    /** Counter used to create unique IDs. */
+    private static AtomicLong counter = new AtomicLong(0L);
+
+    private AtomicBoolean terminated;
 
     private final AxisHttpService httpservice;
+
     private final AxisHttpConnection conn;
+
     private final IOProcessorCallback callback;
 
-    public HttpServiceProcessor(
-            final AxisHttpService httpservice,
-            final AxisHttpConnection conn,
-            final IOProcessorCallback callback) {
+    /**
+     * Unique identifier used by {@linkplain #equals(Object)} and
+     * {@linkplain #hashCode()}.
+     * <p>
+     * This field is needed to allow the equals method to work properly when this
+     * HttpServiceProcessor has to be removed from the list of processors.
+     * 
+     * @see DefaultHttpConnectionManager
+     */
+    private final long id;
+
+
+    public HttpServiceProcessor(final AxisHttpService httpservice,
+            final AxisHttpConnection conn, final IOProcessorCallback callback) {
         super();
         this.httpservice = httpservice;
         this.conn = conn;
         this.callback = callback;
-        this.terminated = false;
+        this.terminated = new AtomicBoolean(false);
+
+        id = counter.incrementAndGet();
     }
 
+
     public void run() {
         LOG.debug("New connection thread");
         HttpContext context = new HttpExecutionContext(null);
         try {
-            while (!Thread.interrupted() && !isDestroyed() && this.conn.isOpen()) {
+            while (! Thread.interrupted() && ! isDestroyed() && this.conn.isOpen()) {
                 this.httpservice.handleRequest(this.conn, context);
             }
         } catch (ConnectionClosedException ex) {
@@ -89,30 +110,68 @@
             }
         } finally {
             destroy();
-            if (this.callback != null) {
-                this.callback.completed(this);
+            if (this.callback == null) {
+                throw new NullPointerException("The callback object can't be null");
             }
+            this.callback.completed(this);
         }
     }
 
+
     public void close() throws IOException {
         this.conn.close();
     }
 
+
     public void destroy() {
-        if (this.terminated) {
-            return;
-        }
-        this.terminated = true;
-        try {
-            this.conn.shutdown();
-        } catch (IOException ex) {
-            LOG.debug("I/O error shutting down connection");
+        if (this.terminated.compareAndSet(false, true)) {
+            try {
+//                this.conn.shutdown();
+                close();
+            } catch (IOException ex) {
+                LOG.debug("I/O error shutting down connection");
+            }
         }
     }
 
+
     public boolean isDestroyed() {
-        return this.terminated;
+        return this.terminated.get();
+    }
+
+
+    // -------------------------------------------------- Methods from Object
+
+    /**
+     * Returns the unique ID of this HttpServiceProcessor.
+     * 
+     * @return The unique ID of this HttpServiceProcessor.
+     */
+    public int hashCode() {
+        final int PRIME = 31;
+        int result = 1;
+        result = PRIME * result + (int) (id ^ (id >>> 32));
+        return result;
+    }
+
+
+   /**
+    * Indicates whether some other object is "equal to" this one.
+    * 
+    * @return <code>true</code> if this HttpServiceProcessor refere to the same 
+    * object as obj or they have the same {@linkplain #id}, <code>false</code> otherwise.
+    */
+    public boolean equals(Object obj) {
+        if (this == obj)
+            return true;
+        if (obj == null)
+            return false;
+        if (getClass() != obj.getClass())
+            return false;
+        final HttpServiceProcessor other = (HttpServiceProcessor) obj;
+        if (id != other.id)
+            return false;
+        return true;
     }
 
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org