hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r676165 - in /httpcomponents/httpcore/trunk: RELEASE_NOTES.txt module-nio/src/main/java/org/apache/http/impl/nio/reactor/AbstractIOReactor.java module-nio/src/main/java/org/apache/http/impl/nio/reactor/BaseIOReactor.java
Date Sat, 12 Jul 2008 12:28:02 GMT
Author: olegk
Date: Sat Jul 12 05:28:02 2008
New Revision: 676165

URL: http://svn.apache.org/viewvc?rev=676165&view=rev
Log:
HTTPCORE-165: Improved handling of CancelledKeyException in I/O reactors


Modified:
    httpcomponents/httpcore/trunk/RELEASE_NOTES.txt
    httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/reactor/AbstractIOReactor.java
    httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/reactor/BaseIOReactor.java

Modified: httpcomponents/httpcore/trunk/RELEASE_NOTES.txt
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/RELEASE_NOTES.txt?rev=676165&r1=676164&r2=676165&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/RELEASE_NOTES.txt (original)
+++ httpcomponents/httpcore/trunk/RELEASE_NOTES.txt Sat Jul 12 05:28:02 2008
@@ -1,3 +1,9 @@
+Changes since 4.0 Beta2
+-------------------
+
+* [HTTPCORE-165] Improved handling of CancelledKeyException in I/O reactors
+  Contributed by Oleg Kalnichevski <olegk at apache.org> 
+
 Release 4.0 Beta 2
 -------------------
 

Modified: httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/reactor/AbstractIOReactor.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/reactor/AbstractIOReactor.java?rev=676165&r1=676164&r2=676165&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/reactor/AbstractIOReactor.java
(original)
+++ httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/reactor/AbstractIOReactor.java
Sat Jul 12 05:28:02 2008
@@ -92,9 +92,9 @@
 
     protected abstract void validate(Set<SelectionKey> keys);
     
-    protected abstract void keyCreated(SelectionKey key, IOSession session);
+    protected abstract void sessionCreated(SelectionKey key, IOSession session);
     
-    protected abstract IOSession keyCancelled(SelectionKey key);
+    protected abstract IOSession getSession(SelectionKey key);
     
     protected abstract void sessionClosed(IOSession session);
     
@@ -198,14 +198,19 @@
                 writable(key);
             }
         } catch (CancelledKeyException ex) {
-            IOSession session = keyCancelled(key);
-            if (session != null) {
-                this.closedSessions.add(session);
-            }
+            IOSession session = getSession(key);
+            queueClosedSession(session);            
             key.attach(null);
         }
     }
 
+    protected void queueClosedSession(final IOSession session) {
+        if (session != null) {
+            this.closedSessions.add(session);
+        }
+    }
+    
+    
     private void processNewChannels() throws IOReactorException {
         ChannelEntry entry;
         while ((entry = this.newChannels.poll()) != null) {
@@ -243,7 +248,7 @@
             this.sessions.add(session);
 
             try {
-                keyCreated(key, session);
+                sessionCreated(key, session);
                 
                 SessionRequestImpl sessionRequest = entry.getSessionRequest();
                 if (sessionRequest != null) {
@@ -260,7 +265,11 @@
         IOSession session;
         while ((session = this.closedSessions.poll()) != null) {
             if (this.sessions.remove(session)) {
-                sessionClosed(session);
+                try {
+                    sessionClosed(session);
+                } catch (CancelledKeyException ex) {
+                    // ignore and move on
+                }
             }
         }
     }

Modified: httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/reactor/BaseIOReactor.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/reactor/BaseIOReactor.java?rev=676165&r1=676164&r2=676165&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/reactor/BaseIOReactor.java
(original)
+++ httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/reactor/BaseIOReactor.java
Sat Jul 12 05:28:02 2008
@@ -96,6 +96,9 @@
 
         try {
             this.eventDispatch.inputReady(session);
+        } catch (CancelledKeyException ex) {
+            queueClosedSession(session);
+            key.attach(null);
         } catch (RuntimeException ex) {
             handleRuntimeException(ex);
         }
@@ -112,6 +115,9 @@
 
         try {
             this.eventDispatch.outputReady(session);
+        } catch (CancelledKeyException ex) {
+            queueClosedSession(session);
+            key.attach(null);
         } catch (RuntimeException ex) {
             handleRuntimeException(ex);
         }
@@ -136,20 +142,19 @@
                     it.remove();
                     continue;
                 }
-                try {
-                    int ops = session.getEventMask();
-                    if ((ops & EventMask.READ) > 0) {
-                        try {
-                            this.eventDispatch.inputReady(session);
-                        } catch (RuntimeException ex) {
-                            handleRuntimeException(ex);
-                        }
-                        if (!session.hasBufferedInput()) {
-                            it.remove();
-                        }
+                int ops = session.getEventMask();
+                if ((ops & EventMask.READ) > 0) {
+                    try {
+                        this.eventDispatch.inputReady(session);
+                    } catch (CancelledKeyException ex) {
+                        it.remove();
+                        queueClosedSession(session);
+                    } catch (RuntimeException ex) {
+                        handleRuntimeException(ex);
+                    }
+                    if (!session.hasBufferedInput()) {
+                        it.remove();
                     }
-                } catch (CancelledKeyException ex) {
-                    it.remove();
                 }
             }
         }
@@ -166,6 +171,9 @@
                 if (handle.getLastAccessTime() + timeout < now) {
                     try {
                         this.eventDispatch.timeout(session);
+                    } catch (CancelledKeyException ex) {
+                        queueClosedSession(session);
+                        key.attach(null);
                     } catch (RuntimeException ex) {
                         handleRuntimeException(ex);
                     }
@@ -175,18 +183,21 @@
     }
 
     @Override
-    protected void keyCreated(final SelectionKey key, final IOSession session) {
+    protected void sessionCreated(final SelectionKey key, final IOSession session) {
         SessionHandle handle = new SessionHandle(session);
         key.attach(handle);
         try {
             this.eventDispatch.connected(session);
+        } catch (CancelledKeyException ex) {
+            queueClosedSession(session);
+            key.attach(null);
         } catch (RuntimeException ex) {
             handleRuntimeException(ex);
         }
     }
 
     @Override
-    protected IOSession keyCancelled(final SelectionKey key) {
+    protected IOSession getSession(final SelectionKey key) {
         Object attachment = key.attachment();
         if (attachment instanceof SessionHandle) {
             SessionHandle handle = (SessionHandle) attachment;
@@ -200,6 +211,8 @@
     protected void sessionClosed(final IOSession session) {
         try {
             this.eventDispatch.disconnected(session);
+        } catch (CancelledKeyException ex) {
+            // ignore
         } catch (RuntimeException ex) {
             handleRuntimeException(ex);
         }



Mime
View raw message