From: fhanik Date: Thu, 12 Oct 2006 20:21:01 +0000 (+0000) Subject: Support to add in static members and to have those parse data arrays in the server... X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=f1be21a08a1cf40e5812a63541bfa5a3af06b51a;p=tomcat7.0 Support to add in static members and to have those parse data arrays in the server.xml file git-svn-id: https://svn.apache.org/repos/asf/tomcat/tc6.0.x/trunk@463412 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/java/org/apache/catalina/tribes/membership/StaticMember.java b/java/org/apache/catalina/tribes/membership/StaticMember.java new file mode 100644 index 000000000..a208f3322 --- /dev/null +++ b/java/org/apache/catalina/tribes/membership/StaticMember.java @@ -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; + +/** + *

Title:

+ * + *

Description:

+ * + *

Copyright: Copyright (c) 2006

+ * + *

Company:

+ * + * @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 diff --git a/java/org/apache/catalina/tribes/util/Arrays.java b/java/org/apache/catalina/tribes/util/Arrays.java index ef075a8b0..ce72d6548 100644 --- a/java/org/apache/catalina/tribes/util/Arrays.java +++ b/java/org/apache/catalina/tribes/util/Arrays.java @@ -24,13 +24,18 @@ import org.apache.catalina.tribes.UniqueId; 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."); @@ -187,6 +192,26 @@ public class Arrays { } 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; iStaticMembershipInterceptor you can add the static members you wish to have. The TcpFailureDetector 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. + + <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> + +