Author: fhanik Date: Thu Jun 29 01:33:29 2006 New Revision: 417959 URL: http://svn.apache.org/viewvc?rev=417959&view=rev Log: Added Member.getCommand, so that we don't have to piggyback on application payload to transfer internal tribes commands
Modified: tomcat/container/tc5.5.x/modules/groupcom/VERSION tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/tribes/Member.java tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/tribes/group/interceptors/TcpFailureDetector.java tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/tribes/membership/McastServiceImpl.java tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/tribes/membership/MemberImpl.java Modified: tomcat/container/tc5.5.x/modules/groupcom/VERSION URL: http://svn.apache.org/viewvc/tomcat/container/tc5.5.x/modules/groupcom/VERSION?rev=417959&r1=417958&r2=417959&view=diff ============================================================================== --- tomcat/container/tc5.5.x/modules/groupcom/VERSION (original) +++ tomcat/container/tc5.5.x/modules/groupcom/VERSION Thu Jun 29 01:33:29 2006 @@ -1,3 +1,5 @@ +0.9.3.3 + - Added Member.getCommand, to separate out internal tribes logic from application payload 0.9.3.2 - MemberImpl.toString has a limit on the size it prints out 0.9.3.1 Modified: tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/tribes/Member.java URL: http://svn.apache.org/viewvc/tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/tribes/Member.java?rev=417959&r1=417958&r2=417959&view=diff ============================================================================== --- tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/tribes/Member.java (original) +++ tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/tribes/Member.java Thu Jun 29 01:33:29 2006 @@ -95,4 +95,9 @@ */ public byte[] getPayload(); + /** + * returns the command associated with this member + * @return byte[] + */ + public byte[] getCommand(); } 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=417959&r1=417958&r2=417959&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 Thu Jun 29 01:33:29 2006 @@ -135,7 +135,7 @@ public void memberDisappeared(Member member) { if ( membership == null ) setupMembership(); boolean notify = false; - boolean shutdown = Arrays.equals(member.getPayload(),Member.SHUTDOWN_PAYLOAD); + boolean shutdown = Arrays.equals(member.getCommand(),Member.SHUTDOWN_PAYLOAD); if ( !shutdown ) log.info("Received memberDisappeared["+member+"] message. Will verify."); synchronized (membership) { //check to see if the member really is gone @@ -245,7 +245,7 @@ long readTimeout, long conTimeout, int optionFlag) { //could be a shutdown notification - if ( Arrays.equals(mbr.getPayload(),Member.SHUTDOWN_PAYLOAD) ) return false; + if ( Arrays.equals(mbr.getCommand(),Member.SHUTDOWN_PAYLOAD) ) return false; Socket socket = new Socket(); try { Modified: tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/tribes/membership/McastServiceImpl.java URL: http://svn.apache.org/viewvc/tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/tribes/membership/McastServiceImpl.java?rev=417959&r1=417958&r2=417959&view=diff ============================================================================== --- tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/tribes/membership/McastServiceImpl.java (original) +++ tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/tribes/membership/McastServiceImpl.java Thu Jun 29 01:33:29 2006 @@ -255,12 +255,10 @@ //we're shutting down, send a shutdown message and close the socket if ( startLevel == 0 ) { //send a stop message - byte[] payload = member.getPayload(); - member.setPayload(Member.SHUTDOWN_PAYLOAD); + member.setCommand(Member.SHUTDOWN_PAYLOAD); member.getData(true, true); send(false); //restore payload - member.setPayload(payload); member.getData(true, true); //leave mcast group try {socket.leaveGroup(address);}catch ( Exception ignore){} @@ -282,7 +280,7 @@ if (log.isDebugEnabled()) log.debug("Mcast receive ping from member " + m); Thread t = null; - if (Arrays.equals(m.getPayload(), Member.SHUTDOWN_PAYLOAD)) { + if (Arrays.equals(m.getCommand(), Member.SHUTDOWN_PAYLOAD)) { if (log.isDebugEnabled()) log.debug("Member has shutdown:" + m); membership.removeMember(m); t = new Thread() { Modified: tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/tribes/membership/MemberImpl.java URL: http://svn.apache.org/viewvc/tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/tribes/membership/MemberImpl.java?rev=417959&r1=417958&r2=417959&view=diff ============================================================================== --- tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/tribes/membership/MemberImpl.java (original) +++ tomcat/container/tc5.5.x/modules/groupcom/src/share/org/apache/catalina/tribes/membership/MemberImpl.java Thu Jun 29 01:33:29 2006 @@ -1,433 +1,462 @@ -/* - * 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 java.io.ObjectInput; -import java.io.ObjectOutput; -import java.util.Arrays; - -import org.apache.catalina.tribes.Member; -import org.apache.catalina.tribes.io.XByteBuffer; -import org.apache.catalina.tribes.transport.SenderState; - -/** - * A <b>membership</b> implementation using simple multicast. - * This is the representation of a multicast member. - * Carries the host, and port of the this or other cluster nodes. - * - * @author Filip Hanik - * @version $Revision: 304032 $, $Date: 2005-07-27 10:11:55 -0500 (Wed, 27 Jul 2005) $ - */ -public class MemberImpl implements Member, java.io.Externalizable { - - /** - * Public properties specific to this implementation - */ - public static final transient String TCP_LISTEN_PORT = "tcpListenPort"; - public static final transient String TCP_LISTEN_HOST = "tcpListenHost"; - public static final transient String MEMBER_NAME = "memberName"; - - /** - * The listen host for this member - */ - protected byte[] host; - protected transient String hostname; - /** - * The tcp listen port for this member - */ - protected int port; - - /** - * Counter for how many broadcast messages have been sent from this member - */ - protected int msgCount = 0; - /** - * The number of milliseconds since this members was - * created, is kept track of using the start time - */ - protected long memberAliveTime = 0; - - /** - * For the local member only - */ - protected transient long serviceStartTime; - - /** - * To avoid serialization over and over again, once the local dataPkg - * has been set, we use that to transmit data - */ - protected transient byte[] dataPkg = null; - - /** - * Unique session Id for this member - */ - protected byte[] uniqueId = new byte[16]; - - /** - * Custom payload that an app framework can broadcast - * Also used to transport stop command. - */ - protected byte[] payload = new byte[0]; - - /** - * Empty constructor for serialization - */ - public MemberImpl() { - - } - - /** - * Construct a new member object - * @param name - the name of this member, cluster unique - * @param domain - the cluster domain name of this member - * @param host - the tcp listen host - * @param port - the tcp listen port - */ - public MemberImpl(String host, - int port, - long aliveTime) throws IOException { - setHostname(host); - this.port = port; - this.memberAliveTime=aliveTime; - } - - public MemberImpl(String host, - int port, - long aliveTime, - byte[] payload) throws IOException { - this(host,port,aliveTime); - setPayload(payload); - } - - public boolean isReady() { - return SenderState.getSenderState(this).isReady(); - } - public boolean isSuspect() { - return SenderState.getSenderState(this).isSuspect(); - } - public boolean isFailing() { - return SenderState.getSenderState(this).isFailing(); - } - - /** - * Increment the message count. - */ - protected void inc() { - msgCount++; - } - - /** - * Create a data package to send over the wire representing this member. - * This is faster than serialization. - * @return - the bytes for this member deserialized - * @throws Exception - */ - public byte[] getData() { - return getData(true); - } - /** - * Highly optimized version of serializing a member into a byte array - * Returns a cached byte[] reference, do not modify this data - * @param getalive boolean - * @return byte[] - */ - public byte[] getData(boolean getalive) { - return getData(getalive,false); - } - - - public int getDataLength() { - return 8+4+1+host.length+16+4+payload.length; - } - - /** - * - * @param getalive boolean - calculate memberAlive time - * @param reset boolean - reset the cached data package, and create a new one - * @return byte[] - */ - public byte[] getData(boolean getalive, boolean reset) { - if ( reset ) dataPkg = null; - //look in cache first - if ( dataPkg!=null ) { - if ( getalive ) { - //you'd be surprised, but System.currentTimeMillis - //shows up on the profiler - long alive=System.currentTimeMillis()-getServiceStartTime(); - XByteBuffer.toBytes( (long) alive, dataPkg, 0); - } - return dataPkg; - } - - //package looks like - //alive - 8 bytes - //port - 4 bytes - //host length - 1 byte - //host - hl bytes - //dlen - 4 bytes - //domain - dlen bytes - //uniqueId - 16 bytes - //payload length - 4 bytes - //payload plen bytes - byte[] addr = host; - long alive=System.currentTimeMillis()-getServiceStartTime(); - byte hl = (byte)addr.length; - byte[] data = new byte[getDataLength()]; - int pos = 0; - //alive data - XByteBuffer.toBytes((long)alive,data,0); - pos += 8; - //port - XByteBuffer.toBytes(port,data,pos); - pos += 4; - //host length - data[pos++] = hl; - //host - System.arraycopy(addr,0,data,pos,addr.length); - pos+=addr.length; - //unique Id - System.arraycopy(uniqueId,0,data,pos,uniqueId.length); - pos+=uniqueId.length; - //payload - XByteBuffer.toBytes(payload.length,data,pos); - pos+=4; - System.arraycopy(payload,0,data,pos,payload.length); - pos+=payload.length; - - //create local data - dataPkg = data; - return data; - } - /** - * Deserializes a member from data sent over the wire - * @param data - the bytes received - * @return a member object. - */ - public static MemberImpl getMember(byte[] data, MemberImpl member) { - //package looks like - //alive - 8 bytes - //port - 4 bytes - //host length - 1 byte - //host - hl bytes - //uniqueId - 16 bytes - //payload length - 4bytes - //payload - pl bytes - int pos = 0; - - byte[] alived = new byte[8]; - System.arraycopy(data, pos, alived, 0, 8); - pos+=8; - byte[] portd = new byte[4]; - System.arraycopy(data, pos, portd, 0, 4); - pos+=4; - - byte hl = data[pos++]; - byte[] addr = new byte[hl]; - System.arraycopy(data, pos, addr, 0, hl); - pos+=hl; - - byte[] uniqueId = new byte[16]; - System.arraycopy(data, pos, uniqueId, 0, 16); - pos+=16; - - int pl = XByteBuffer.toInt(data,pos); - pos+=4; - - byte[] payload = new byte[pl]; - System.arraycopy(data, pos, payload, 0, payload.length); - pos+=payload.length; - - member.setHost(addr); - member.setPort(XByteBuffer.toInt(portd, 0)); - member.setMemberAliveTime(XByteBuffer.toLong(alived, 0)); - member.setUniqueId(uniqueId); - member.payload = payload; - - member.dataPkg = new byte[data.length]; - System.arraycopy(data,0,member.dataPkg,0,data.length); - - return member; - } - - public static MemberImpl getMember(byte[] data) { - return getMember(data,new MemberImpl()); - } - - /** - * Return the name of this object - * @return a unique name to the cluster - */ - public String getName() { - return "tcp://"+getHostname()+":"+getPort(); - } - - /** - * Return the listen port of this member - * @return - tcp listen port - */ - public int getPort() { - return this.port; - } - - /** - * Return the TCP listen host for this member - * @return IP address or host name - */ - public byte[] getHost() { - return host; - } - - public String getHostname() { - if ( this.hostname != null ) return hostname; - else { - try { - this.hostname = java.net.InetAddress.getByAddress(host).getHostName(); - return this.hostname; - }catch ( IOException x ) { - throw new RuntimeException("Unable to parse hostname.",x); - } - } - } - - /** - * Contains information on how long this member has been online. - * The result is the number of milli seconds this member has been - * broadcasting its membership to the cluster. - * @return nr of milliseconds since this member started. - */ - public long getMemberAliveTime() { - return memberAliveTime; - } - - public long getServiceStartTime() { - return serviceStartTime; - } - - public byte[] getUniqueId() { - return uniqueId; - } - - public byte[] getPayload() { - return payload; - } - - public void setMemberAliveTime(long time) { - memberAliveTime=time; - } - - - - /** - * String representation of this object - */ - public String toString() { - StringBuffer buf = new StringBuffer("org.apache.catalina.tribes.membership.MemberImpl["); - buf.append(getName()).append(","); - buf.append(getHostname()).append(","); - buf.append(port).append(", alive="); - buf.append(memberAliveTime).append(","); - buf.append("id=").append(bToS(this.uniqueId)).append(", "); - buf.append("payload=").append(bToS(this.payload,5)).append(", "); - buf.append("]"); - return buf.toString(); - } - public static String bToS(byte[] data) { - return bToS(data,data.length); - } - public static String bToS(byte[] data, int max) { - StringBuffer buf = new StringBuffer(4*16); - buf.append("{"); - for (int i=0; data!=null && i<data.length; i++ ) { - buf.append(String.valueOf(data[i])).append(" "); - if ( i==max ) { - buf.append("..."); - break; - } - } - buf.append("}"); - return buf.toString(); - } - - /** - * @see java.lang.Object#hashCode() - * @return The hash code - */ - public int hashCode() { - return getHost()[0]+getHost()[1]+getHost()[2]+getHost()[3]; - } - - /** - * Returns true if the param o is a McastMember with the same name - * @param o - */ - public boolean equals(Object o) { - if ( o instanceof MemberImpl ) { - return Arrays.equals(this.getHost(),((MemberImpl)o).getHost()) && - this.getPort() == ((MemberImpl)o).getPort() && - Arrays.equals(this.getUniqueId(),((MemberImpl)o).getUniqueId()); - } - else - return false; - } - - public void setHost(byte[] host) { - this.host = host; - } - - public void setHostname(String host) throws IOException { - hostname = host; - this.host = java.net.InetAddress.getByName(host).getAddress(); - } - - public void setMsgCount(int msgCount) { - this.msgCount = msgCount; - } - - public void setPort(int port) { - this.port = port; - this.dataPkg = null; - } - - public void setServiceStartTime(long serviceStartTime) { - this.serviceStartTime = serviceStartTime; - } - - public void setUniqueId(byte[] uniqueId) { - this.uniqueId = uniqueId; - } - - public void setPayload(byte[] payload) { - this.payload = payload; - getData(true,true); - } - - public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { - int length = in.readInt(); - byte[] message = new byte[length]; - in.read(message); - getMember(message,this); - - } - - public void writeExternal(ObjectOutput out) throws IOException { - byte[] data = this.getData(); - out.writeInt(data.length); - out.write(data); - } - -} +/* + * 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 java.io.ObjectInput; +import java.io.ObjectOutput; +import java.util.Arrays; + +import org.apache.catalina.tribes.Member; +import org.apache.catalina.tribes.io.XByteBuffer; +import org.apache.catalina.tribes.transport.SenderState; + +/** + * A <b>membership</b> implementation using simple multicast. + * This is the representation of a multicast member. + * Carries the host, and port of the this or other cluster nodes. + * + * @author Filip Hanik + * @version $Revision: 304032 $, $Date: 2005-07-27 10:11:55 -0500 (Wed, 27 Jul 2005) $ + */ +public class MemberImpl implements Member, java.io.Externalizable { + + /** + * Public properties specific to this implementation + */ + public static final transient String TCP_LISTEN_PORT = "tcpListenPort"; + public static final transient String TCP_LISTEN_HOST = "tcpListenHost"; + public static final transient String MEMBER_NAME = "memberName"; + + /** + * The listen host for this member + */ + protected byte[] host; + protected transient String hostname; + /** + * The tcp listen port for this member + */ + protected int port; + + /** + * Counter for how many broadcast messages have been sent from this member + */ + protected int msgCount = 0; + /** + * The number of milliseconds since this members was + * created, is kept track of using the start time + */ + protected long memberAliveTime = 0; + + /** + * For the local member only + */ + protected transient long serviceStartTime; + + /** + * To avoid serialization over and over again, once the local dataPkg + * has been set, we use that to transmit data + */ + protected transient byte[] dataPkg = null; + + /** + * Unique session Id for this member + */ + protected byte[] uniqueId = new byte[16]; + + /** + * Custom payload that an app framework can broadcast + * Also used to transport stop command. + */ + protected byte[] payload = new byte[0]; + + /** + * Command, so that the custom payload doesn't have to be used + * This is for internal tribes use, such as SHUTDOWN_COMMAND + */ + protected byte[] command = new byte[0]; + + /** + * Empty constructor for serialization + */ + public MemberImpl() { + + } + + /** + * Construct a new member object + * @param name - the name of this member, cluster unique + * @param domain - the cluster domain name of this member + * @param host - the tcp listen host + * @param port - the tcp listen port + */ + public MemberImpl(String host, + int port, + long aliveTime) throws IOException { + setHostname(host); + this.port = port; + this.memberAliveTime=aliveTime; + } + + public MemberImpl(String host, + int port, + long aliveTime, + byte[] payload) throws IOException { + this(host,port,aliveTime); + setPayload(payload); + } + + public boolean isReady() { + return SenderState.getSenderState(this).isReady(); + } + public boolean isSuspect() { + return SenderState.getSenderState(this).isSuspect(); + } + public boolean isFailing() { + return SenderState.getSenderState(this).isFailing(); + } + + /** + * Increment the message count. + */ + protected void inc() { + msgCount++; + } + + /** + * Create a data package to send over the wire representing this member. + * This is faster than serialization. + * @return - the bytes for this member deserialized + * @throws Exception + */ + public byte[] getData() { + return getData(true); + } + /** + * Highly optimized version of serializing a member into a byte array + * Returns a cached byte[] reference, do not modify this data + * @param getalive boolean + * @return byte[] + */ + public byte[] getData(boolean getalive) { + return getData(getalive,false); + } + + + public int getDataLength() { + return 8+4+1+host.length+4+command.length+16+4+payload.length; + } + + /** + * + * @param getalive boolean - calculate memberAlive time + * @param reset boolean - reset the cached data package, and create a new one + * @return byte[] + */ + public byte[] getData(boolean getalive, boolean reset) { + if ( reset ) dataPkg = null; + //look in cache first + if ( dataPkg!=null ) { + if ( getalive ) { + //you'd be surprised, but System.currentTimeMillis + //shows up on the profiler + long alive=System.currentTimeMillis()-getServiceStartTime(); + XByteBuffer.toBytes( (long) alive, dataPkg, 0); + } + return dataPkg; + } + + //package looks like + //alive - 8 bytes + //port - 4 bytes + //host length - 1 byte + //host - hl bytes + //clen - 4 bytes + //command - clen bytes + //uniqueId - 16 bytes + //payload length - 4 bytes + //payload plen bytes + byte[] addr = host; + long alive=System.currentTimeMillis()-getServiceStartTime(); + byte hl = (byte)addr.length; + byte[] data = new byte[getDataLength()]; + int pos = 0; + //alive data + XByteBuffer.toBytes((long)alive,data,0); + pos += 8; + //port + XByteBuffer.toBytes(port,data,pos); + pos += 4; + //host length + data[pos++] = hl; + //host + System.arraycopy(addr,0,data,pos,addr.length); + pos+=addr.length; + //clen - 4 bytes + XByteBuffer.toBytes(command.length,data,pos); + pos+=4; + //command - clen bytes + System.arraycopy(command,0,data,pos,command.length); + pos+=command.length; + //unique Id + System.arraycopy(uniqueId,0,data,pos,uniqueId.length); + pos+=uniqueId.length; + //payload + XByteBuffer.toBytes(payload.length,data,pos); + pos+=4; + System.arraycopy(payload,0,data,pos,payload.length); + pos+=payload.length; + + //create local data + dataPkg = data; + return data; + } + /** + * Deserializes a member from data sent over the wire + * @param data - the bytes received + * @return a member object. + */ + public static MemberImpl getMember(byte[] data, MemberImpl member) { + //package looks like + //alive - 8 bytes + //port - 4 bytes + //host length - 1 byte + //host - hl bytes + //command length - 4 bytes + //command clen bytes + //uniqueId - 16 bytes + //payload length - 4bytes + //payload - pl bytes + int pos = 0; + + byte[] alived = new byte[8]; + System.arraycopy(data, pos, alived, 0, 8); + pos+=8; + byte[] portd = new byte[4]; + System.arraycopy(data, pos, portd, 0, 4); + pos+=4; + + byte hl = data[pos++]; + byte[] addr = new byte[hl]; + System.arraycopy(data, pos, addr, 0, hl); + pos+=hl; + + int cl = XByteBuffer.toInt(data,pos); + pos+=4; + + byte[] command = new byte[cl]; + System.arraycopy(data, pos, command, 0, command.length); + pos+=command.length; + + byte[] uniqueId = new byte[16]; + System.arraycopy(data, pos, uniqueId, 0, 16); + pos+=16; + + int pl = XByteBuffer.toInt(data,pos); + pos+=4; + + byte[] payload = new byte[pl]; + System.arraycopy(data, pos, payload, 0, payload.length); + pos+=payload.length; + + member.setHost(addr); + member.setPort(XByteBuffer.toInt(portd, 0)); + member.setMemberAliveTime(XByteBuffer.toLong(alived, 0)); + member.setUniqueId(uniqueId); + member.payload = payload; + + member.dataPkg = new byte[data.length]; + System.arraycopy(data,0,member.dataPkg,0,data.length); + + return member; + } + + public static MemberImpl getMember(byte[] data) { + return getMember(data,new MemberImpl()); + } + + /** + * Return the name of this object + * @return a unique name to the cluster + */ + public String getName() { + return "tcp://"+getHostname()+":"+getPort(); + } + + /** + * Return the listen port of this member + * @return - tcp listen port + */ + public int getPort() { + return this.port; + } + + /** + * Return the TCP listen host for this member + * @return IP address or host name + */ + public byte[] getHost() { + return host; + } + + public String getHostname() { + if ( this.hostname != null ) return hostname; + else { + try { + this.hostname = java.net.InetAddress.getByAddress(host).getHostName(); + return this.hostname; + }catch ( IOException x ) { + throw new RuntimeException("Unable to parse hostname.",x); + } + } + } + + /** + * Contains information on how long this member has been online. + * The result is the number of milli seconds this member has been + * broadcasting its membership to the cluster. + * @return nr of milliseconds since this member started. + */ + public long getMemberAliveTime() { + return memberAliveTime; + } + + public long getServiceStartTime() { + return serviceStartTime; + } + + public byte[] getUniqueId() { + return uniqueId; + } + + public byte[] getPayload() { + return payload; + } + + public byte[] getCommand() { + return command; + } + + public void setMemberAliveTime(long time) { + memberAliveTime=time; + } + + + + /** + * String representation of this object + */ + public String toString() { + StringBuffer buf = new StringBuffer("org.apache.catalina.tribes.membership.MemberImpl["); + buf.append(getName()).append(","); + buf.append(getHostname()).append(","); + buf.append(port).append(", alive="); + buf.append(memberAliveTime).append(","); + buf.append("id=").append(bToS(this.uniqueId)).append(", "); + buf.append("payload=").append(bToS(this.payload,5)).append(", "); + buf.append("]"); + return buf.toString(); + } + public static String bToS(byte[] data) { + return bToS(data,data.length); + } + public static String bToS(byte[] data, int max) { + StringBuffer buf = new StringBuffer(4*16); + buf.append("{"); + for (int i=0; data!=null && i<data.length; i++ ) { + buf.append(String.valueOf(data[i])).append(" "); + if ( i==max ) { + buf.append("..."); + break; + } + } + buf.append("}"); + return buf.toString(); + } + + /** + * @see java.lang.Object#hashCode() + * @return The hash code + */ + public int hashCode() { + return getHost()[0]+getHost()[1]+getHost()[2]+getHost()[3]; + } + + /** + * Returns true if the param o is a McastMember with the same name + * @param o + */ + public boolean equals(Object o) { + if ( o instanceof MemberImpl ) { + return Arrays.equals(this.getHost(),((MemberImpl)o).getHost()) && + this.getPort() == ((MemberImpl)o).getPort() && + Arrays.equals(this.getUniqueId(),((MemberImpl)o).getUniqueId()); + } + else + return false; + } + + public void setHost(byte[] host) { + this.host = host; + } + + public void setHostname(String host) throws IOException { + hostname = host; + this.host = java.net.InetAddress.getByName(host).getAddress(); + } + + public void setMsgCount(int msgCount) { + this.msgCount = msgCount; + } + + public void setPort(int port) { + this.port = port; + this.dataPkg = null; + } + + public void setServiceStartTime(long serviceStartTime) { + this.serviceStartTime = serviceStartTime; + } + + public void setUniqueId(byte[] uniqueId) { + this.uniqueId = uniqueId; + } + + public void setPayload(byte[] payload) { + this.payload = payload; + getData(true,true); + } + + public void setCommand(byte[] command) { + this.command = command!=null?command:new byte[0]; + } + + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + int length = in.readInt(); + byte[] message = new byte[length]; + in.read(message); + getMember(message,this); + + } + + public void writeExternal(ObjectOutput out) throws IOException { + byte[] data = this.getData(); + out.writeInt(data.length); + out.write(data); + } + +} --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]