james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nor...@apache.org
Subject svn commit: r1092699 - /james/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/IdleProcessor.java
Date Fri, 15 Apr 2011 13:26:56 GMT
Author: norman
Date: Fri Apr 15 13:26:56 2011
New Revision: 1092699

URL: http://svn.apache.org/viewvc?rev=1092699&view=rev
Log:
Make sure the idle heartbeat get terminated once the idle state was left. See IMAP-299

Modified:
    james/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/IdleProcessor.java

Modified: james/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/IdleProcessor.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/IdleProcessor.java?rev=1092699&r1=1092698&r2=1092699&view=diff
==============================================================================
--- james/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/IdleProcessor.java
(original)
+++ james/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/IdleProcessor.java
Fri Apr 15 13:26:56 2011
@@ -26,7 +26,6 @@ import java.util.List;
 import java.util.Locale;
 import java.util.concurrent.Executors;
 import java.util.concurrent.ScheduledExecutorService;
-import java.util.concurrent.ScheduledFuture;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicBoolean;
 
@@ -51,8 +50,6 @@ public class IdleProcessor extends Abstr
 
     private final ScheduledExecutorService heartbeatExecutor;
 
-    private final static String HEARTBEAT_FUTURE = "IDLE_HEARTBEAT_FUTURE";
-
     // 2 minutes
     public final static long DEFAULT_HEARTBEAT_INTERVAL_IN_SECONDS = 2 * 60;
     public final static TimeUnit DEFAULT_HEARTBEAT_INTERVAL_UNIT = TimeUnit.SECONDS;
@@ -113,40 +110,18 @@ public class IdleProcessor extends Abstr
                     } else {
                         okComplete(command, tag, responder);
 
-                        // See if we need to cancel the idle heartbeat handling
-                        Object oFuture = session.getAttribute(HEARTBEAT_FUTURE);
-                        if (oFuture != null) {
-                            ScheduledFuture<?> future = (ScheduledFuture<?>)
oFuture;
-                            if (future.cancel(true) == false) {
-                                // unable to cancel the future so better logout
-                                // now!
-                                session.getLog().error("Unable to disable idle heartbeat
for unknown reason! Force logout");
-                                session.logout();
-                            }
-                            session.setAttribute(HEARTBEAT_FUTURE, null);
-                        }
                     }
                 }
             });
 
             // Check if we should send heartbeats
             if (heartbeatInterval > 0) {
-                final ScheduledFuture<?> heartbeatFuture = heartbeatExecutor.scheduleWithFixedDelay(new
Runnable() {
+                heartbeatExecutor.schedule(new Runnable() {
 
                     public void run() {
                         // check if we need to cancel the Runnable
                         // See IMAP-275
-                        if (session.getState() == ImapSessionState.LOGOUT) {
-
-                            Object future = session.getAttribute(HEARTBEAT_FUTURE);
-                            if (future != null) {
-                                // cancel the future if needed to be sure it not
-                                // run infinity
-                                ((ScheduledFuture<?>) future).cancel(true);
-                                session.setAttribute(HEARTBEAT_FUTURE, null);
-                            }
-
-                        } else {
+                        if (session.getState() != ImapSessionState.LOGOUT && closed.get()
== false) {
                             // Send a heartbeat to the client to make sure we
                             // reset the idle timeout. This is kind of the same
                             // workaround as dovecot use.
@@ -157,12 +132,12 @@ public class IdleProcessor extends Abstr
                             // See IMAP-272
                             StatusResponse response = getStatusResponseFactory().untaggedOk(HumanReadableText.HEARTBEAT);
                             responder.respond(response);
+                            
+                            // schedule the heartbeat again for the next interval
+                            heartbeatExecutor.schedule(this, heartbeatInterval, heartbeatIntervalUnit);
                         }
                     }
-                }, heartbeatInterval, heartbeatInterval, heartbeatIntervalUnit);
-
-                // store future for later usage
-                session.setAttribute(HEARTBEAT_FUTURE, heartbeatFuture);
+                }, heartbeatInterval, heartbeatIntervalUnit);
             }
 
         } catch (MailboxException e) {



---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


Mime
View raw message