hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r833205 - in /httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor: AbstractIOReactor.java AbstractMultiworkerIOReactor.java
Date Thu, 05 Nov 2009 22:03:20 GMT
Author: olegk
Date: Thu Nov  5 22:03:20 2009
New Revision: 833205

URL: http://svn.apache.org/viewvc?rev=833205&view=rev
Log:
Minor cleanups in I/O reactor shut down code

Modified:
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/AbstractIOReactor.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/AbstractMultiworkerIOReactor.java

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/AbstractIOReactor.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/AbstractIOReactor.java?rev=833205&r1=833204&r2=833205&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/AbstractIOReactor.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/AbstractIOReactor.java
Thu Nov  5 22:03:20 2009
@@ -58,7 +58,7 @@
 
     private volatile IOReactorStatus status;
     
-    private final Object shutdownMutex;
+    private final Object statusMutex;
     private final long selectTimeout;
     private final boolean interestOpsQueueing;
     private final Selector selector;
@@ -103,7 +103,7 @@
         } catch (IOException ex) {
             throw new IOReactorException("Failure opening selector", ex);
         }
-        this.shutdownMutex = new Object();
+        this.statusMutex = new Object();
         this.status = IOReactorStatus.INACTIVE;
     }
 
@@ -299,15 +299,11 @@
                 
             }
             
-            // Close remaining active channels and the selector itself
-            closeActiveChannels();
-            this.status = IOReactorStatus.SHUT_DOWN;
-            
         } catch (ClosedSelectorException ex) {
         } finally {
-            synchronized (this.shutdownMutex) {
-                hardShutdown();
-                this.shutdownMutex.notifyAll();
+            hardShutdown();
+            synchronized (this.statusMutex) {
+                this.statusMutex.notifyAll();
             }
         }
     }
@@ -529,10 +525,7 @@
             for (Iterator<SelectionKey> it = keys.iterator(); it.hasNext(); ) {
                 SelectionKey key = it.next();
                 IOSession session = getSession(key);
-                if (!session.isClosed()) {
-                    session.close();
-                    sessionClosed(session);
-                }
+                session.close();
             }
             this.selector.close();
         } catch (IOException ignore) {
@@ -543,11 +536,13 @@
      * Attempts graceful shutdown of this I/O reactor.
      */
     public void gracefulShutdown() {
-        if (this.status != IOReactorStatus.ACTIVE) {
-            // Already shutting down
-            return;
+        synchronized (this.statusMutex) {
+            if (this.status != IOReactorStatus.ACTIVE) {
+                // Already shutting down
+                return;
+            }
+            this.status = IOReactorStatus.SHUTTING_DOWN;
         }
-        this.status = IOReactorStatus.SHUTTING_DOWN;
         this.selector.wakeup();
     }
         
@@ -555,13 +550,17 @@
      * Attempts force-shutdown of this I/O reactor.
      */
     public void hardShutdown() throws IOReactorException {
-        if (this.status == IOReactorStatus.SHUT_DOWN) {
-            // Already shut down
-            return;
+        synchronized (this.statusMutex) {
+            if (this.status == IOReactorStatus.SHUT_DOWN) {
+                // Already shut down
+                return;
+            }
+            this.status = IOReactorStatus.SHUT_DOWN;
         }
-        this.status = IOReactorStatus.SHUT_DOWN;
+        
         closeNewChannels();
         closeActiveChannels();
+        processClosedSessions();
     }
     
     /**
@@ -572,11 +571,11 @@
      * @throws InterruptedException if interrupted.
      */
     public void awaitShutdown(long timeout) throws InterruptedException {
-        synchronized (this.shutdownMutex) {
+        synchronized (this.statusMutex) {
             long deadline = System.currentTimeMillis() + timeout;
             long remaining = timeout;
             while (this.status != IOReactorStatus.SHUT_DOWN) {
-                this.shutdownMutex.wait(remaining);
+                this.statusMutex.wait(remaining);
                 if (timeout > 0) {
                     remaining = deadline - System.currentTimeMillis();
                     if (remaining <= 0) {

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/AbstractMultiworkerIOReactor.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/AbstractMultiworkerIOReactor.java?rev=833205&r1=833204&r2=833205&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/AbstractMultiworkerIOReactor.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/AbstractMultiworkerIOReactor.java
Thu Nov  5 22:03:20 2009
@@ -336,8 +336,8 @@
             }
             throw ex;
         } finally {
+            doShutdown();
             synchronized (this.statusLock) {
-                doShutdown();
                 this.status = IOReactorStatus.SHUT_DOWN;
                 this.statusLock.notifyAll();
             }
@@ -355,10 +355,12 @@
      *   interrupted.
      */
     protected void doShutdown() throws InterruptedIOException {
-        if (this.status.compareTo(IOReactorStatus.SHUTTING_DOWN) >= 0) {
-            return;
+        synchronized (this.statusLock) {
+            if (this.status.compareTo(IOReactorStatus.SHUTTING_DOWN) >= 0) {
+                return;
+            }
+            this.status = IOReactorStatus.SHUTTING_DOWN;
         }
-        this.status = IOReactorStatus.SHUTTING_DOWN;
         try {
             cancelRequests();        
         } catch (IOReactorException ex) {
@@ -507,11 +509,11 @@
                 return;
             }
             this.status = IOReactorStatus.SHUTDOWN_REQUEST;
-            this.selector.wakeup();
-            try {
-                awaitShutdown(waitMs);
-            } catch (InterruptedException ignore) {
-            }
+        }
+        this.selector.wakeup();
+        try {
+            awaitShutdown(waitMs);
+        } catch (InterruptedException ignore) {
         }
     }
 



Mime
View raw message