You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by fh...@apache.org on 2006/05/02 23:15:25 UTC

svn commit: r399050 - in /tomcat/container/tc5.5.x/modules/groupcom: src/share/org/apache/catalina/tribes/group/GroupChannel.java to-do.txt

Author: fhanik
Date: Tue May  2 14:15:22 2006
New Revision: 399050

URL: http://svn.apache.org/viewcvs?rev=399050&view=rev
Log:
Implemented a channel interceptor heartbeat, useful for cleaning up

Modified:
    tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/tribes/group/GroupChannel.java
    tomcat/container/tc5.5.x/modules/groupcom/to-do.txt

Modified: tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/tribes/group/GroupChannel.java
URL: http://svn.apache.org/viewcvs/tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/tribes/group/GroupChannel.java?rev=399050&r1=399049&r2=399050&view=diff
==============================================================================
--- tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/tribes/group/GroupChannel.java (original)
+++ tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/tribes/group/GroupChannel.java Tue May  2 14:15:22 2006
@@ -21,6 +21,7 @@
 import java.util.Iterator;
 
 import org.apache.catalina.tribes.ByteMessage;
+import org.apache.catalina.tribes.Channel;
 import org.apache.catalina.tribes.ChannelException;
 import org.apache.catalina.tribes.ChannelInterceptor;
 import org.apache.catalina.tribes.ChannelListener;
@@ -32,15 +33,9 @@
 import org.apache.catalina.tribes.Member;
 import org.apache.catalina.tribes.MembershipListener;
 import org.apache.catalina.tribes.MembershipService;
+import org.apache.catalina.tribes.group.interceptors.MessageDispatchInterceptor;
 import org.apache.catalina.tribes.io.ClusterData;
 import org.apache.catalina.tribes.io.XByteBuffer;
-import java.io.ObjectInput;
-import java.io.Externalizable;
-
-import java.io.IOException;
-import java.io.ObjectOutput;
-import org.apache.catalina.tribes.Channel;
-import org.apache.catalina.tribes.group.interceptors.MessageDispatchInterceptor;
 
 /**
  * The GroupChannel manages the replication channel. It coordinates
@@ -51,7 +46,9 @@
  * @version $Revision: 304032 $, $Date: 2005-07-27 10:11:55 -0500 (Wed, 27 Jul 2005) $
  */
 public class GroupChannel extends ChannelInterceptorBase implements ManagedChannel {
-    
+    protected boolean heartbeatEnabled = true;
+    protected long heartbeatSleeptime = 60*1000;//only run once a minute
+    protected HeartbeatThread hbthread = null;
     
     private ChannelCoordinator coordinator = new ChannelCoordinator();
     private ChannelInterceptor interceptors = null;
@@ -240,10 +237,23 @@
     
     }
     
-    public void start(int svc) throws ChannelException {
+    public synchronized void start(int svc) throws ChannelException {
         setupDefaultStack();
         if (optionCheck) checkOptionFlags();
         super.start(svc);
+        if ( hbthread == null && heartbeatEnabled ) {
+            hbthread = new HeartbeatThread(this,heartbeatSleeptime);
+            hbthread.start();
+        }
+    }
+    
+    public synchronized void stop(int svc) throws ChannelException {
+        if (hbthread != null) {
+            hbthread.stopHeartbeat();
+            hbthread.interrupt();
+            hbthread = null;
+        }
+        super.stop(svc);
     }
     
     public ChannelInterceptor getFirstInterceptor() {
@@ -297,6 +307,29 @@
         return new InterceptorIterator(this.getNext(),this.coordinator);
     }
 
+    public void setOptionCheck(boolean optionCheck) {
+        this.optionCheck = optionCheck;
+    }
+
+    public void setHeartbeatEnabled(boolean heartbeatEnabled) {
+        this.heartbeatEnabled = heartbeatEnabled;
+    }
+
+    public void setHeartbeatSleeptime(long heartbeatSleeptime) {
+        this.heartbeatSleeptime = heartbeatSleeptime;
+    }
+
+    public boolean getOptionCheck() {
+        return optionCheck;
+    }
+
+    public boolean getHeartbeatEnabled() {
+        return heartbeatEnabled;
+    }
+
+    public long getHeartbeatSleeptime() {
+        return heartbeatSleeptime;
+    }
 
     public static class InterceptorIterator implements Iterator {
         private ChannelInterceptor end;
@@ -324,14 +357,40 @@
         }
     }
 
-    public void setOptionCheck(boolean optionCheck) {
-        this.optionCheck = optionCheck;
-    }
-
-    public boolean getOptionCheck() {
-        return optionCheck;
-    }
-    
+    public static class HeartbeatThread extends Thread {
+        protected static org.apache.commons.logging.Log log = org.apache.commons.logging.LogFactory.getLog(HeartbeatThread.class);
+        protected static int counter = 1;
+        protected static synchronized int inc() {
+            return counter++;
+        }
+        
+        protected boolean doRun = true;
+        protected GroupChannel channel;
+        protected long sleepTime;
+        public HeartbeatThread(GroupChannel channel, long sleepTime) {
+            super();
+            setName("GroupChannel-Heartbeat-"+inc());
+            setDaemon(true);
+            this.channel = channel;
+            this.sleepTime = sleepTime;
+        }
+        public void stopHeartbeat() {
+            doRun = false;
+        }
+        
+        public void run() {
+            while (doRun) {
+                try {
+                    Thread.sleep(sleepTime);
+                    channel.heartbeat();
+                } catch ( InterruptedException x ) {
+                    interrupted();
+                } catch ( Exception x ) {
+                    log.error("Unable to send heartbeat through Tribes interceptor stack.",x);
+                }//catch
+            }//while
+        }//run
+    }//HeartbeatThread
     
     
 

Modified: tomcat/container/tc5.5.x/modules/groupcom/to-do.txt
URL: http://svn.apache.org/viewcvs/tomcat/container/tc5.5.x/modules/groupcom/to-do.txt?rev=399050&r1=399049&r2=399050&view=diff
==============================================================================
--- tomcat/container/tc5.5.x/modules/groupcom/to-do.txt (original)
+++ tomcat/container/tc5.5.x/modules/groupcom/to-do.txt Tue May  2 14:15:22 2006
@@ -36,6 +36,8 @@
 ===========================================
  a) Somehow the first NIO connection made, always closes down, why
  
+ b) pull the network cord and watch the membership layer freak out
+ 
 Code Tasks:
 ===========================================
 43. Silent member, node discovery.



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