You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mina.apache.org by tr...@apache.org on 2008/04/04 10:35:17 UTC

svn commit: r644643 - /mina/trunk/core/src/main/java/org/apache/mina/filter/keepalive/KeepAliveFilter.java

Author: trustin
Date: Fri Apr  4 01:34:53 2008
New Revision: 644643

URL: http://svn.apache.org/viewvc?rev=644643&view=rev
Log:
Fixed DIRMINA-562 - KeepAliveFilter shouldn't forward sessionIdle(READER_IDLE) to the next filter.
* Made sure READER_IDLE event is not forwarded to the next filter.
* Updated JavaDoc

Modified:
    mina/trunk/core/src/main/java/org/apache/mina/filter/keepalive/KeepAliveFilter.java

Modified: mina/trunk/core/src/main/java/org/apache/mina/filter/keepalive/KeepAliveFilter.java
URL: http://svn.apache.org/viewvc/mina/trunk/core/src/main/java/org/apache/mina/filter/keepalive/KeepAliveFilter.java?rev=644643&r1=644642&r2=644643&view=diff
==============================================================================
--- mina/trunk/core/src/main/java/org/apache/mina/filter/keepalive/KeepAliveFilter.java (original)
+++ mina/trunk/core/src/main/java/org/apache/mina/filter/keepalive/KeepAliveFilter.java Fri Apr  4 01:34:53 2008
@@ -22,9 +22,11 @@
 import org.apache.mina.common.AttributeKey;
 import org.apache.mina.common.DefaultWriteRequest;
 import org.apache.mina.common.IdleStatus;
+import org.apache.mina.common.IoEventType;
 import org.apache.mina.common.IoFilter;
 import org.apache.mina.common.IoFilterAdapter;
 import org.apache.mina.common.IoFilterChain;
+import org.apache.mina.common.IoHandler;
 import org.apache.mina.common.IoSession;
 import org.apache.mina.common.IoSessionConfig;
 import org.apache.mina.common.WriteRequest;
@@ -41,7 +43,10 @@
  * This filter adjusts <tt>idleTime</tt> property for
  * {@link IdleStatus#READER_IDLE} automatically.  Changing the <tt>idleTime</tt>
  * property for {@link IdleStatus#READER_IDLE} will lead this filter to a
- * unexpected behavior.
+ * unexpected behavior.  Please also note that any {@link IoFilter} and
+ * {@link IoHandler} behind {@link KeepAliveFilter} will not get
+ * {@link IoEventType#SESSION_IDLE} event with {@link IdleStatus#READER_IDLE}
+ * parameter at all.
  * 
  * <h2>Implementing {@link KeepAliveMessageFactory}</h2>
  * 
@@ -270,44 +275,42 @@
     @Override
     public void sessionIdle(
             NextFilter nextFilter, IoSession session, IdleStatus status) throws Exception {
-        try {
-            if (status == IdleStatus.READER_IDLE) {
-                if (!session.containsAttribute(WAITING_FOR_RESPONSE)) {
-                    Object pingMessage = messageFactory.getRequest(session);
-                    if (pingMessage != null) {
-                        nextFilter.filterWrite(
-                                session,
-                                new DefaultWriteRequest(pingMessage));
-
-                        // If policy is OFF, there's no need to wait for
-                        // the response.
-                        if (getPolicy() != KeepAlivePolicy.OFF) {
-                            markStatus(session);
-                        } else {
-                            resetStatus(session);
-                        }
-                    }
-                } else {
-                    resetStatus(session);
-                    switch (getPolicy()) {
-                    case OFF:
-                        break;
-                    case LOG:
-                        logTimeout();
-                        break;
-                    case EXCEPTION:
-                        throw new KeepAliveTimeoutException(
-                                getTimeoutMessage());
-                    case CLOSE:
-                        logTimeout();
-                        session.close();
-                        break;
-                    default:
-                        throw new InternalError();
+        if (status == IdleStatus.READER_IDLE) {
+            if (!session.containsAttribute(WAITING_FOR_RESPONSE)) {
+                Object pingMessage = messageFactory.getRequest(session);
+                if (pingMessage != null) {
+                    nextFilter.filterWrite(
+                            session,
+                            new DefaultWriteRequest(pingMessage));
+
+                    // If policy is OFF, there's no need to wait for
+                    // the response.
+                    if (getPolicy() != KeepAlivePolicy.OFF) {
+                        markStatus(session);
+                    } else {
+                        resetStatus(session);
                     }
                 }
+            } else {
+                resetStatus(session);
+                switch (getPolicy()) {
+                case OFF:
+                    break;
+                case LOG:
+                    logTimeout();
+                    break;
+                case EXCEPTION:
+                    throw new KeepAliveTimeoutException(
+                            getTimeoutMessage());
+                case CLOSE:
+                    logTimeout();
+                    session.close();
+                    break;
+                default:
+                    throw new InternalError();
+                }
             }
-        } finally {
+        } else {
             nextFilter.sessionIdle(session, status);
         }
     }