hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1140049 - in /httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor: AbstractIOReactor.java BaseIOReactor.java SessionHandle.java
Date Mon, 27 Jun 2011 08:29:50 GMT
Author: olegk
Date: Mon Jun 27 08:29:50 2011
New Revision: 1140049

URL: http://svn.apache.org/viewvc?rev=1140049&view=rev
Log:
HTTPCORE-261: moved session time management code from BaseIOReactor to AbstractIOReactor

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/BaseIOReactor.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/SessionHandle.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=1140049&r1=1140048&r2=1140049&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
Mon Jun 27 08:29:50 2011
@@ -144,17 +144,6 @@ public abstract class AbstractIOReactor 
     protected abstract void writable(SelectionKey key);
 
     /**
-     * Triggered to verify whether the I/O session associated with the
-     * given selection key has not timed out.
-     * <p>
-     * Super-classes can implement this method to react to the event.
-     *
-     * @param key the selection key.
-     * @param now current time as long value.
-     */
-    protected abstract void timeoutCheck(SelectionKey key, long now);
-
-    /**
      * Triggered to validate keys currently registered with the selector. This
      * method is called after each I/O select loop.
      * <p>
@@ -174,7 +163,8 @@ public abstract class AbstractIOReactor 
      * @param key the selection key.
      * @param session new I/O session.
      */
-    protected abstract void sessionCreated(SelectionKey key, IOSession session);
+    protected void sessionCreated(final SelectionKey key, final IOSession session) {
+    }
 
     /**
      * Triggered when a session has been closed.
@@ -183,7 +173,18 @@ public abstract class AbstractIOReactor 
      *
      * @param session closed I/O session.
      */
-    protected abstract void sessionClosed(IOSession session);
+    protected void sessionClosed(final IOSession session) {
+    }
+
+    /**
+     * Triggered when a session has timed out.
+     * <p>
+     * Super-classes can implement this method to react to the event.
+     *
+     * @param session timed out I/O session.
+     */
+    protected void sessionTimedOut(final IOSession session) {
+    }
 
     /**
      * Obtains {@link IOSession} instance associated with the given selection
@@ -192,7 +193,15 @@ public abstract class AbstractIOReactor 
      * @param key the selection key.
      * @return I/O session.
      */
-    protected abstract IOSession getSession(SelectionKey key);
+    protected IOSession getSession(final SelectionKey key) {
+        Object attachment = key.attachment();
+        if (attachment instanceof SessionHandle) {
+            SessionHandle handle = (SessionHandle) attachment;
+            return handle.getSession();
+        } else {
+            return null;
+        }
+    }
 
     public IOReactorStatus getStatus() {
         return this.status;
@@ -324,6 +333,8 @@ public abstract class AbstractIOReactor 
      * @param key the selection key that triggered an event.
      */
     protected void processEvent(final SelectionKey key) {
+        SessionHandle handle = (SessionHandle) key.attachment();
+        IOSession session = handle.getSession();
         try {
             if (key.isAcceptable()) {
                 acceptable(key);
@@ -332,13 +343,14 @@ public abstract class AbstractIOReactor 
                 connectable(key);
             }
             if (key.isReadable()) {
+                handle.resetLastRead();
                 readable(key);
             }
             if (key.isWritable()) {
+                handle.resetLastWrite();
                 writable(key);
             }
         } catch (CancelledKeyException ex) {
-            IOSession session = getSession(key);
             queueClosedSession(session);
             key.attach(null);
         }
@@ -416,6 +428,8 @@ public abstract class AbstractIOReactor 
                 if (sessionRequest != null) {
                     sessionRequest.completed(session);
                 }
+                SessionHandle handle = new SessionHandle(session);
+                key.attach(handle);
                 sessionCreated(key, session);
             } catch (CancelledKeyException ex) {
                 queueClosedSession(session);
@@ -469,6 +483,30 @@ public abstract class AbstractIOReactor 
     }
 
     /**
+     * Triggered to verify whether the I/O session associated with the
+     * given selection key has not timed out.
+     * <p>
+     * Super-classes can implement this method to react to the event.
+     *
+     * @param key the selection key.
+     * @param now current time as long value.
+     */
+    protected void timeoutCheck(final SelectionKey key, long now) {
+        Object attachment = key.attachment();
+        if (attachment instanceof SessionHandle) {
+            SessionHandle handle = (SessionHandle) key.attachment();
+            IOSession session = handle.getSession();
+            int timeout = session.getSocketTimeout();
+            if (timeout > 0) {
+                if (handle.getLastAccessTime() + timeout < now) {
+                    sessionTimedOut(session);
+                }
+            }
+        }
+    }
+
+
+    /**
      * Closes out all I/O sessions maintained by this I/O reactor.
      */
     protected void closeSessions() {

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/BaseIOReactor.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/BaseIOReactor.java?rev=1140049&r1=1140048&r2=1140049&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/BaseIOReactor.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/BaseIOReactor.java
Mon Jun 27 08:29:50 2011
@@ -109,7 +109,7 @@ public class BaseIOReactor extends Abstr
      *
      * @param exceptionHandler the exception handler.
      */
-    public void setExceptionHandler(IOReactorExceptionHandler exceptionHandler) {
+    public void setExceptionHandler(final IOReactorExceptionHandler exceptionHandler) {
         this.exceptionHandler = exceptionHandler;
     }
 
@@ -153,10 +153,7 @@ public class BaseIOReactor extends Abstr
      */
     @Override
     protected void readable(final SelectionKey key) {
-        SessionHandle handle = (SessionHandle) key.attachment();
-        IOSession session = handle.getSession();
-        handle.resetLastRead();
-
+        IOSession session = getSession(key);
         try {
             this.eventDispatch.inputReady(session);
             if (session.hasBufferedInput()) {
@@ -177,10 +174,7 @@ public class BaseIOReactor extends Abstr
      */
     @Override
     protected void writable(final SelectionKey key) {
-        SessionHandle handle = (SessionHandle) key.attachment();
-        IOSession session = handle.getSession();
-        handle.resetLastWrite();
-
+        IOSession session = getSession(key);
         try {
             this.eventDispatch.outputReady(session);
         } catch (CancelledKeyException ex) {
@@ -247,57 +241,32 @@ public class BaseIOReactor extends Abstr
     }
 
     /**
-     * Performs timeout check for the I/O session associated with the given
-     * selection key.
-     */
-    @Override
-    protected void timeoutCheck(final SelectionKey key, long now) {
-        Object attachment = key.attachment();
-        if (attachment instanceof SessionHandle) {
-            SessionHandle handle = (SessionHandle) key.attachment();
-            IOSession session = handle.getSession();
-            int timeout = session.getSocketTimeout();
-            if (timeout > 0) {
-                if (handle.getLastAccessTime() + timeout < now) {
-                    try {
-                        this.eventDispatch.timeout(session);
-                    } catch (CancelledKeyException ex) {
-                        queueClosedSession(session);
-                        key.attach(null);
-                    } catch (RuntimeException ex) {
-                        handleRuntimeException(ex);
-                    }
-                }
-            }
-        }
-    }
-
-    /**
      * Processes newly created I/O session. This method dispatches the event
      * notification to the {@link IOEventDispatch#connected(IOSession)} method.
      */
     @Override
     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);
         }
     }
 
+    /**
+     * Processes timed out I/O session. This method dispatches the event
+     * notification to the {@link IOEventDispatch#timeout(IOSession)} method.
+     */
     @Override
-    protected IOSession getSession(final SelectionKey key) {
-        Object attachment = key.attachment();
-        if (attachment instanceof SessionHandle) {
-            SessionHandle handle = (SessionHandle) attachment;
-            return handle.getSession();
-        } else {
-            return null;
+    protected void sessionTimedOut(final IOSession session) {
+        try {
+            this.eventDispatch.timeout(session);
+        } catch (CancelledKeyException ex) {
+            queueClosedSession(session);
+        } catch (RuntimeException ex) {
+            handleRuntimeException(ex);
         }
     }
 

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/SessionHandle.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/SessionHandle.java?rev=1140049&r1=1140048&r2=1140049&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/SessionHandle.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/SessionHandle.java
Mon Jun 27 08:29:50 2011
@@ -34,8 +34,11 @@ import org.apache.http.nio.reactor.IOSes
  * to a {@link IOSession} along with information about time of last I/O
  * operations on that session.
  *
+ * @deprecated use {@link IOSessionImpl}
+ *
  * @since 4.0
  */
+@Deprecated
 public class SessionHandle {
 
     private final IOSession session;



Mime
View raw message