org.apache.catalina.tribes.membership

Class MemberImpl

public class MemberImpl extends Object implements Member, Externalizable

A membership implementation using simple multicast. This is the representation of a multicast member. Carries the host, and port of the this or other cluster nodes.

Version: $Revision: 892521 $, $Date: 2009-12-19 23:56:24 +0100 (Sat, 19 Dec 2009) $

Author: Filip Hanik

Field Summary
protected byte[]command
Command, so that the custom payload doesn't have to be used This is for internal tribes use, such as SHUTDOWN_COMMAND
protected byte[]dataPkg
To avoid serialization over and over again, once the local dataPkg has been set, we use that to transmit data
protected byte[]domain
Domain if we want to filter based on domain.
static booleanDO_DNS_LOOKUPS
Should a call to getName or getHostName try to do a DNS lookup?
protected byte[]host
The listen host for this member
protected Stringhostname
protected longmemberAliveTime
The number of milliseconds since this members was created, is kept track of using the start time
protected intmsgCount
Counter for how many broadcast messages have been sent from this member
static StringMEMBER_NAME
protected byte[]payload
Custom payload that an app framework can broadcast Also used to transport stop command.
protected intport
The tcp listen port for this member
protected intsecurePort
The tcp/SSL listen port for this member
protected longserviceStartTime
For the local member only
static StringTCP_LISTEN_HOST
static StringTCP_LISTEN_PORT
Public properties specific to this implementation
static byte[]TRIBES_MBR_BEGIN
static byte[]TRIBES_MBR_END
protected byte[]uniqueId
Unique session Id for this member
Constructor Summary
MemberImpl()
Empty constructor for serialization
MemberImpl(String host, int port, long aliveTime)
Construct a new member object
MemberImpl(String host, int port, long aliveTime, byte[] payload)
Method Summary
static StringbToS(byte[] data)
static StringbToS(byte[] data, int max)
booleanequals(Object o)
Returns true if the param o is a McastMember with the same name
byte[]getCommand()
byte[]getData()
Create a data package to send over the wire representing this member.
byte[]getData(boolean getalive)
Highly optimized version of serializing a member into a byte array Returns a cached byte[] reference, do not modify this data
byte[]getData(boolean getalive, boolean reset)
intgetDataLength()
byte[]getDomain()
byte[]getHost()
Return the TCP listen host for this member
StringgetHostname()
static MemberImplgetMember(byte[] data, MemberImpl member)
Deserializes a member from data sent over the wire
static MemberImplgetMember(byte[] data, int offset, int length, MemberImpl member)
static MemberImplgetMember(byte[] data)
static MemberImplgetMember(byte[] data, int offset, int length)
longgetMemberAliveTime()
Contains information on how long this member has been online.
StringgetName()
Return the name of this object
byte[]getPayload()
intgetPort()
Return the listen port of this member
intgetSecurePort()
longgetServiceStartTime()
byte[]getUniqueId()
inthashCode()
protected voidinc()
Increment the message count.
booleanisFailing()
booleanisReady()
booleanisSuspect()
voidreadExternal(ObjectInput in)
voidsetCommand(byte[] command)
voidsetDomain(byte[] domain)
voidsetHost(byte[] host)
voidsetHostname(String host)
voidsetMemberAliveTime(long time)
voidsetMsgCount(int msgCount)
voidsetPayload(byte[] payload)
voidsetPort(int port)
voidsetSecurePort(int securePort)
voidsetServiceStartTime(long serviceStartTime)
voidsetUniqueId(byte[] uniqueId)
StringtoString()
String representation of this object
voidwriteExternal(ObjectOutput out)

Field Detail

command

protected byte[] command
Command, so that the custom payload doesn't have to be used This is for internal tribes use, such as SHUTDOWN_COMMAND

dataPkg

protected transient byte[] dataPkg
To avoid serialization over and over again, once the local dataPkg has been set, we use that to transmit data

domain

protected byte[] domain
Domain if we want to filter based on domain.

DO_DNS_LOOKUPS

public static final boolean DO_DNS_LOOKUPS
Should a call to getName or getHostName try to do a DNS lookup? default is false

host

protected byte[] host
The listen host for this member

hostname

protected transient String hostname

memberAliveTime

protected long memberAliveTime
The number of milliseconds since this members was created, is kept track of using the start time

msgCount

protected int msgCount
Counter for how many broadcast messages have been sent from this member

MEMBER_NAME

public static final transient String MEMBER_NAME

payload

protected byte[] payload
Custom payload that an app framework can broadcast Also used to transport stop command.

port

protected int port
The tcp listen port for this member

securePort

protected int securePort
The tcp/SSL listen port for this member

serviceStartTime

protected transient long serviceStartTime
For the local member only

TCP_LISTEN_HOST

public static final transient String TCP_LISTEN_HOST

TCP_LISTEN_PORT

public static final transient String TCP_LISTEN_PORT
Public properties specific to this implementation

TRIBES_MBR_BEGIN

public static final transient byte[] TRIBES_MBR_BEGIN

TRIBES_MBR_END

public static final transient byte[] TRIBES_MBR_END

uniqueId

protected byte[] uniqueId
Unique session Id for this member

Constructor Detail

MemberImpl

public MemberImpl()
Empty constructor for serialization

MemberImpl

public MemberImpl(String host, int port, long aliveTime)
Construct a new member object

Parameters: name - the name of this member, cluster unique domain - the cluster domain name of this member host - the tcp listen host port - the tcp listen port

MemberImpl

public MemberImpl(String host, int port, long aliveTime, byte[] payload)

Method Detail

bToS

public static String bToS(byte[] data)

bToS

public static String bToS(byte[] data, int max)

equals

public boolean equals(Object o)
Returns true if the param o is a McastMember with the same name

Parameters: o

getCommand

public byte[] getCommand()

getData

public byte[] getData()
Create a data package to send over the wire representing this member. This is faster than serialization.

Returns: - the bytes for this member deserialized

Throws: Exception

getData

public byte[] getData(boolean getalive)
Highly optimized version of serializing a member into a byte array Returns a cached byte[] reference, do not modify this data

Parameters: getalive boolean

Returns: byte[]

getData

public byte[] getData(boolean getalive, boolean reset)

Parameters: getalive boolean - calculate memberAlive time reset boolean - reset the cached data package, and create a new one

Returns: byte[]

getDataLength

public int getDataLength()

getDomain

public byte[] getDomain()

getHost

public byte[] getHost()
Return the TCP listen host for this member

Returns: IP address or host name

getHostname

public String getHostname()

getMember

public static MemberImpl getMember(byte[] data, MemberImpl member)
Deserializes a member from data sent over the wire

Parameters: data - the bytes received

Returns: a member object.

getMember

public static MemberImpl getMember(byte[] data, int offset, int length, MemberImpl member)

getMember

public static MemberImpl getMember(byte[] data)

getMember

public static MemberImpl getMember(byte[] data, int offset, int length)

getMemberAliveTime

public long getMemberAliveTime()
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.

Returns: nr of milliseconds since this member started.

getName

public String getName()
Return the name of this object

Returns: a unique name to the cluster

getPayload

public byte[] getPayload()

getPort

public int getPort()
Return the listen port of this member

Returns: - tcp listen port

getSecurePort

public int getSecurePort()

getServiceStartTime

public long getServiceStartTime()

getUniqueId

public byte[] getUniqueId()

hashCode

public int hashCode()

Returns: The hash code

See Also: java.lang.Object#hashCode()

inc

protected void inc()
Increment the message count.

isFailing

public boolean isFailing()

isReady

public boolean isReady()

isSuspect

public boolean isSuspect()

readExternal

public void readExternal(ObjectInput in)

setCommand

public void setCommand(byte[] command)

setDomain

public void setDomain(byte[] domain)

setHost

public void setHost(byte[] host)

setHostname

public void setHostname(String host)

setMemberAliveTime

public void setMemberAliveTime(long time)

setMsgCount

public void setMsgCount(int msgCount)

setPayload

public void setPayload(byte[] payload)

setPort

public void setPort(int port)

setSecurePort

public void setSecurePort(int securePort)

setServiceStartTime

public void setServiceStartTime(long serviceStartTime)

setUniqueId

public void setUniqueId(byte[] uniqueId)

toString

public String toString()
String representation of this object

writeExternal

public void writeExternal(ObjectOutput out)
Copyright © 2000-2011 Apache Software Foundation. All Rights Reserved.