tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fha...@apache.org
Subject svn commit: r407877 - /tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/tribes/group/interceptors/TcpFailureDetector.java
Date Fri, 19 May 2006 18:26:09 GMT
Author: fhanik
Date: Fri May 19 11:26:09 2006
New Revision: 407877

URL: http://svn.apache.org/viewvc?rev=407877&view=rev
Log:
small adjustment to the failure detector, difference between member add and disappear

Modified:
    tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/tribes/group/interceptors/TcpFailureDetector.java

Modified: tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/tribes/group/interceptors/TcpFailureDetector.java
URL: http://svn.apache.org/viewvc/tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/tribes/group/interceptors/TcpFailureDetector.java?rev=407877&r1=407876&r2=407877&view=diff
==============================================================================
--- tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/tribes/group/interceptors/TcpFailureDetector.java
(original)
+++ tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/tribes/group/interceptors/TcpFailureDetector.java
Fri May 19 11:26:09 2006
@@ -76,7 +76,9 @@
     
     protected Membership membership = null;
     
-    protected HashMap suspect = new HashMap();
+    protected HashMap removeSuspects = new HashMap();
+    
+    protected HashMap addSuspects = new HashMap();
     
     public void sendMessage(Member[] destination, ChannelMessage msg, InterceptorPayload
payload) throws ChannelException {
         try {
@@ -110,12 +112,20 @@
     
     public synchronized void memberAdded(Member member) {
         if ( membership == null ) setupMembership();
-        if ( suspect.containsKey(member) ) {
+        if ( removeSuspects.containsKey(member) ) {
             //previously marked suspect, system below picked up the member again
-            suspect.remove(member);
+            removeSuspects.remove(member);
         } else {
             //if we add it here, then add it upwards too
-            if ( memberAlive(member) && membership.memberAlive((MemberImpl)member))
 super.memberAdded(member);
+            if ( membership.memberAlive((MemberImpl)member) ) {
+                //check to see if it is alive
+                if (memberAlive(member)) {
+                    super.memberAdded(member);
+                } else {
+                    membership.removeMember((MemberImpl)member);
+                    addSuspects.put(member, new Long(System.currentTimeMillis()));
+                }
+            }        
         }
     }
 
@@ -130,7 +140,7 @@
             super.memberDisappeared(member);
         } else {
             //add the member as suspect
-            suspect.put(member, new Long(System.currentTimeMillis()));
+            removeSuspects.put(member, new Long(System.currentTimeMillis()));
         }
     }
     
@@ -154,34 +164,51 @@
     }
     
     public synchronized void heartbeat() {
-        if ( membership == null ) setupMembership();
-        //update all alive times
-        Member[] members = super.getMembers();
-        for ( int i=0; i<members.length; i++ ) {
-            if ( membership.memberAlive((MemberImpl)members[i]) ) {
-                //we don't have this one in our membership, check to see if he/she is alive
-                if ( memberAlive(members[i]) ) {
-                    log.warn("Member added, even though we werent notified:"+members[i]);
-                    super.memberAdded(members[i]);
-                } else {
-                    membership.removeMember((MemberImpl)members[i]);
-                }//end if
-            }//end if
-        }//for
-        
-        //check suspect members if they are still alive,
-        //if not, simply issue the memberDisappeared message
-        MemberImpl[] keys = (MemberImpl[])suspect.keySet().toArray(new MemberImpl[suspect.size()]);
-        for (int i=0; i<keys.length; i++ ) {
-            MemberImpl m = (MemberImpl)keys[i];
-            if (membership.getMember(m)!=null && (!memberAlive(m))) {
-                membership.removeMember(m);
-                super.memberDisappeared(m);
-                suspect.remove(m);
-            }//end if
+        try {
+            if (membership == null) setupMembership();
+            //update all alive times
+            Member[] members = super.getMembers();
+            for (int i = 0; i < members.length; i++) {
+                if (membership.memberAlive( (MemberImpl) members[i])) {
+                    //we don't have this one in our membership, check to see if he/she is
alive
+                    if (memberAlive(members[i])) {
+                        log.warn("Member added, even though we werent notified:" + members[i]);
+                        super.memberAdded(members[i]);
+                    } else {
+                        membership.removeMember( (MemberImpl) members[i]);
+                    } //end if
+                } //end if
+            } //for
+
+            //check suspect members if they are still alive,
+            //if not, simply issue the memberDisappeared message
+            MemberImpl[] keys = (MemberImpl[]) removeSuspects.keySet().toArray(new MemberImpl[removeSuspects.size()]);
+            for (int i = 0; i < keys.length; i++) {
+                MemberImpl m = (MemberImpl) keys[i];
+                if (membership.getMember(m) != null && (!memberAlive(m))) {
+                    membership.removeMember(m);
+                    super.memberDisappeared(m);
+                    removeSuspects.remove(m);
+                } //end if
+            }
+
+            //check add suspects members if they are alive now,
+            //if they are, simply issue the memberAdded message
+            keys = (MemberImpl[]) addSuspects.keySet().toArray(new MemberImpl[addSuspects.size()]);
+            for (int i = 0; i < keys.length; i++) {
+                MemberImpl m = (MemberImpl) keys[i];
+                if ( membership.getMember(m) == null && (memberAlive(m))) {
+                    membership.memberAlive(m);
+                    super.memberAdded(m);
+                    addSuspects.remove(m);
+                } //end if
+            }
+
+        }catch ( Exception x ) {
+            log.warn("Unable to perform heartbeat on the TcpFailureDetector.",x);
+        } finally {
+            super.heartbeat();
         }
-        
-        super.heartbeat();
     }
     
     protected synchronized void setupMembership() {



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


Mime
View raw message