--- /dev/null
+/*
+ * 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
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.");
}
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();
+ }
+ }
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>
+ <Interceptor className="org.apache.catalina.tribes.group.interceptors.StaticMembershipInterceptor">
+ <Member className="org.apache.catalina.tribes.membership.StaticMember"
+ port="5678"
+ securePort="-1"
+ host="tomcat01.mydomain.com"
+ domain="staging-cluster"
+ uniqueId="{0,1,2,3,4,5,6,7,8,9}"/>
+ </Interceptor>
+
+ </source>
</p>
</section>