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/10/12 22:21:01 UTC

svn commit: r463412 - in /tomcat/tc6.0.x/trunk: java/org/apache/catalina/tribes/membership/StaticMember.java java/org/apache/catalina/tribes/util/Arrays.java webapps/docs/config/cluster-interceptor.xml

Author: fhanik
Date: Thu Oct 12 13:21:01 2006
New Revision: 463412

URL: http://svn.apache.org/viewvc?view=rev&rev=463412
Log:
Support to add in static members and to have those parse data arrays in the server.xml file

Added:
    tomcat/tc6.0.x/trunk/java/org/apache/catalina/tribes/membership/StaticMember.java
Modified:
    tomcat/tc6.0.x/trunk/java/org/apache/catalina/tribes/util/Arrays.java
    tomcat/tc6.0.x/trunk/webapps/docs/config/cluster-interceptor.xml

Added: tomcat/tc6.0.x/trunk/java/org/apache/catalina/tribes/membership/StaticMember.java
URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/catalina/tribes/membership/StaticMember.java?view=auto&rev=463412
==============================================================================
--- tomcat/tc6.0.x/trunk/java/org/apache/catalina/tribes/membership/StaticMember.java (added)
+++ tomcat/tc6.0.x/trunk/java/org/apache/catalina/tribes/membership/StaticMember.java Thu Oct 12 13:21:01 2006
@@ -0,0 +1,79 @@
+/*
+ * Copyright 1999,2004-2005 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.catalina.tribes.membership;
+
+import java.io.IOException;
+import org.apache.catalina.tribes.util.UUIDGenerator;
+import org.apache.catalina.tribes.util.Arrays;
+
+/**
+ * <p>Title: </p>
+ *
+ * <p>Description: </p>
+ *
+ * <p>Copyright: Copyright (c) 2006</p>
+ *
+ * <p>Company: </p>
+ *
+ * @author not attributable
+ * @version 1.0
+ */
+public class StaticMember extends MemberImpl {
+    public StaticMember() {
+        super();
+    }
+
+    public StaticMember(String host, int port, long aliveTime) throws IOException {
+        super(host, port, aliveTime);
+    }
+
+    public StaticMember(String host, int port, long aliveTime, byte[] payload) throws IOException {
+        super(host, port, aliveTime, payload);
+    }
+     
+    /**
+     * @param host String, either in byte array string format, like {214,116,1,3}
+     * or as a regular hostname, 127.0.0.1 or tomcat01.mydomain.com
+     */
+    public void setHost(String host) {
+        if ( host == null ) return;
+        if ( host.startsWith("{") ) setHost(Arrays.fromString(host));
+        else try { setHostname(host); }catch (IOException x) { throw new RuntimeException(x);}
+        
+    }
+    
+    /**
+     * @param domain String, either in byte array string format, like {214,116,1,3}
+     * or as a regular string value like 'mydomain'. The latter will be converted using ISO-8859-1 encoding
+     */
+    public void setDomain(String domain) {
+        if ( domain == null ) return;
+        if ( domain.startsWith("{") ) setDomain(Arrays.fromString(domain));
+        else setDomain(Arrays.convert(domain));
+    }
+    
+    /**
+     * @param id String, must be in byte array string format, like {214,116,1,3} and exactly 16 bytes long
+     */
+    public void setUniqueId(String id) {
+        byte[] uuid = Arrays.fromString(id);
+        if ( uuid==null || uuid.length != 16 ) throw new RuntimeException("UUID must be exactly 16 bytes, not:"+id);
+        setUniqueId(uuid);
+    }
+    
+    
+}
\ No newline at end of file

Modified: tomcat/tc6.0.x/trunk/java/org/apache/catalina/tribes/util/Arrays.java
URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/catalina/tribes/util/Arrays.java?view=diff&rev=463412&r1=463411&r2=463412
==============================================================================
--- tomcat/tc6.0.x/trunk/java/org/apache/catalina/tribes/util/Arrays.java (original)
+++ tomcat/tc6.0.x/trunk/java/org/apache/catalina/tribes/util/Arrays.java Thu Oct 12 13:21:01 2006
@@ -24,13 +24,18 @@
 import org.apache.catalina.tribes.group.AbsoluteOrder;
 import org.apache.catalina.tribes.membership.MemberImpl;
 import org.apache.catalina.tribes.membership.Membership;
+import java.io.UnsupportedEncodingException;
+import org.apache.juli.logging.Log;
+import org.apache.juli.logging.LogFactory;
+import java.util.StringTokenizer;
 
 /**
  * @author Filip Hanik
  * @version 1.0
  */
 public class Arrays {
-
+    protected static Log log = LogFactory.getLog(Arrays.class);
+    
     public static boolean contains(byte[] source, int srcoffset, byte[] key, int keyoffset, int length) {
         if ( srcoffset < 0 || srcoffset >= source.length) throw new ArrayIndexOutOfBoundsException("srcoffset is out of bounds.");
         if ( keyoffset < 0 || keyoffset >= key.length) throw new ArrayIndexOutOfBoundsException("keyoffset is out of bounds.");
@@ -186,6 +191,26 @@
             result = 31 * result + element;
         }
         return result;
+    }
+    
+    public static byte[] fromString(String value) { 
+        if ( value == null ) return null;
+        if ( !value.startsWith("{") ) throw new RuntimeException("byte arrays must be represented as {1,3,4,5,6}");
+        StringTokenizer t = new StringTokenizer(value,"{,}",false);
+        byte[] result = new byte[t.countTokens()];
+        for (int i=0; i<result.length; i++ ) result[i] = Byte.parseByte(t.nextToken());
+        return result;
+    }
+
+    
+ 
+    public static byte[] convert(String s) {
+        try {
+            return s.getBytes("ISO-8859-1");
+        }catch (UnsupportedEncodingException ux ) {
+            log.error("Unable to convert ["+s+"] into a byte[] using ISO-8859-1 encoding, falling back to default encoding.");
+            return s.getBytes();
+        }
     }
 
 

Modified: tomcat/tc6.0.x/trunk/webapps/docs/config/cluster-interceptor.xml
URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/webapps/docs/config/cluster-interceptor.xml?view=diff&rev=463412&r1=463411&r2=463412
==============================================================================
--- tomcat/tc6.0.x/trunk/webapps/docs/config/cluster-interceptor.xml (original)
+++ tomcat/tc6.0.x/trunk/webapps/docs/config/cluster-interceptor.xml Thu Oct 12 13:21:01 2006
@@ -47,6 +47,17 @@
    Inside the <code>StaticMembershipInterceptor</code> you can add the static members you wish to have.
    The <code>TcpFailureDetector</code> will do a health check on the static members,and also monitor them for crashes
    so they will have the same level of notification mechanism as the members that are automatically discovered.
+   <source>
+     &lt;Interceptor className=&quot;org.apache.catalina.tribes.group.interceptors.StaticMembershipInterceptor&quot;&gt;
+       &lt;Member className=&quot;org.apache.catalina.tribes.membership.StaticMember&quot;
+                  port=&quot;5678&quot;
+                  securePort=&quot;-1&quot;
+                  host=&quot;tomcat01.mydomain.com&quot;
+                  domain=&quot;staging-cluster&quot;
+                  uniqueId=&quot;{0,1,2,3,4,5,6,7,8,9}&quot;/&gt;
+     &lt;/Interceptor&gt;
+   
+   </source>
   </p>
 </section>
 



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