tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kfuj...@apache.org
Subject svn commit: r1721090 - in /tomcat/tc7.0.x/trunk: java/org/apache/catalina/tribes/group/interceptors/StaticMembershipInterceptor.java webapps/docs/changelog.xml
Date Mon, 21 Dec 2015 05:11:59 GMT
Author: kfujino
Date: Mon Dec 21 05:11:59 2015
New Revision: 1721090

URL: http://svn.apache.org/viewvc?rev=1721090&view=rev
Log:
Add support for the shutdown notification of local members in the static cluster.

Modified:
    tomcat/tc7.0.x/trunk/java/org/apache/catalina/tribes/group/interceptors/StaticMembershipInterceptor.java
    tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml

Modified: tomcat/tc7.0.x/trunk/java/org/apache/catalina/tribes/group/interceptors/StaticMembershipInterceptor.java
URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/catalina/tribes/group/interceptors/StaticMembershipInterceptor.java?rev=1721090&r1=1721089&r2=1721090&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/java/org/apache/catalina/tribes/group/interceptors/StaticMembershipInterceptor.java
(original)
+++ tomcat/tc7.0.x/trunk/java/org/apache/catalina/tribes/group/interceptors/StaticMembershipInterceptor.java
Mon Dec 21 05:11:59 2015
@@ -28,6 +28,7 @@ import org.apache.catalina.tribes.group.
 import org.apache.catalina.tribes.group.ChannelInterceptorBase;
 import org.apache.catalina.tribes.io.ChannelData;
 import org.apache.catalina.tribes.io.XByteBuffer;
+import org.apache.catalina.tribes.membership.StaticMember;
 import org.apache.juli.logging.Log;
 import org.apache.juli.logging.LogFactory;
 
@@ -39,6 +40,10 @@ public class StaticMembershipInterceptor
         76, 111, 99, 97, 108, 32, 83, 116, 97, 116, 105, 99, 77, 101, 109, 98, 101, 114,
32, 78,
         111, 116, 105, 102, 105, 99, 97, 116, 105, 111, 110, 32, 68, 97, 116, 97};
 
+    protected static final byte[] MEMBER_STOP = new byte[] {
+        76, 111, 99, 97, 108, 32, 83, 116, 97, 116, 105, 99, 77, 101, 109, 98, 101, 114,
32, 83,
+        104, 117, 116, 100, 111, 119, 110, 32, 68, 97, 116, 97};
+
     protected ArrayList<Member> members = new ArrayList<Member>();
     protected Member localMember = null;
 
@@ -71,7 +76,18 @@ public class StaticMembershipInterceptor
             if (member != null) {
                 super.memberAdded(member);
             }
-            
+        } else if (msg.getMessage().getLength() == MEMBER_STOP.length &&
+                Arrays.equals(MEMBER_STOP, msg.getMessage().getBytes())) {
+            // receive member shutdown
+            Member member = getMember(msg.getAddress());
+            if (member != null && member instanceof StaticMember) {
+                try {
+                    ((StaticMember)member).setCommand(Member.SHUTDOWN_PAYLOAD);
+                    super.memberDisappeared(member);
+                } finally {
+                    ((StaticMember)member).setCommand(new byte[0]);
+                }
+            }
         } else {
             super.messageReceived(msg);
         }
@@ -171,20 +187,35 @@ public class StaticMembershipInterceptor
         }
     }
 
+    /**
+     * {@inheritDoc}
+     * <p>
+     * Sends local member shutdown.
+     */
+    @Override
+    public void stop(int svc) throws ChannelException {
+        // Sends local member shutdown.
+        Member[] members = getfirstInterceptor().getMembers();
+        sendShutdown(members);
+        super.stop(svc);
+    }
+
     protected void sendLocalMember(Member[] members) {
-        if ( members == null || members.length == 0 ) return;
-        ChannelData data = new ChannelData(true);
-        data.setAddress(getLocalMember(false));
-        data.setTimestamp(System.currentTimeMillis());
-        data.setOptions(getOptionFlag());
-        data.setMessage(new XByteBuffer(MEMBER_START, false));
         try {
-            super.sendMessage(members, data, null);
-        }catch (ChannelException cx) {
+            sendMemberMessage(members, MEMBER_START);
+        } catch (ChannelException cx) {
             log.warn("Local member notification failed.",cx);
         }
     }
 
+    protected void sendShutdown(Member[] members) {
+        try {
+            sendMemberMessage(members, MEMBER_STOP);
+        } catch (ChannelException cx) {
+            log.warn("Shutdown notification failed.",cx);
+        }
+    }
+
     protected ChannelInterceptor getfirstInterceptor() {
         ChannelInterceptor result = null;
         ChannelInterceptor now = this;
@@ -195,4 +226,13 @@ public class StaticMembershipInterceptor
         return result;
     }
 
+    protected void sendMemberMessage(Member[] members, byte[] message) throws ChannelException
{
+        if ( members == null || members.length == 0 ) return;
+        ChannelData data = new ChannelData(true);
+        data.setAddress(getLocalMember(false));
+        data.setTimestamp(System.currentTimeMillis());
+        data.setOptions(getOptionFlag());
+        data.setMessage(new XByteBuffer(message, false));
+        super.sendMessage(members, data, null);
+    }
 }
\ No newline at end of file

Modified: tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml
URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml?rev=1721090&r1=1721089&r2=1721090&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml Mon Dec 21 05:11:59 2015
@@ -137,6 +137,10 @@
         Ignore the unnecessary member remove operation from different domain.
         (kfujino)
       </fix>
+      <fix>
+        Add support for the shutdown notification of local members in the static
+        cluster. (kfujino)
+      </fix>
     </changelog>
   </subsection>
   <subsection name="Other">



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


Mime
View raw message