Class MemberImpl
java.lang.Object
org.apache.catalina.tribes.membership.MemberImpl
- All Implemented Interfaces:
Externalizable, Serializable, Member
- Direct Known Subclasses:
StaticMember
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.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected byte[]Command, so that the custom payload doesn't have to be used This is for internal tribes use, such as SHUTDOWN_COMMANDprotected byte[]To avoid serialization over and over again, once the local dataPkg has been set, we use that to transmit dataprotected byte[]Domain if we want to filter based on domain.protected byte[]The listen host for this member.protected StringThe hostname string representation.protected booleanThe flag indicating that this member is a local member.protected longThe number of milliseconds since this member was created, is kept track of using the start timeprotected AtomicIntegerCounter for how many broadcast messages have been sent from this memberprotected byte[]Custom payload that an app framework can broadcast Also used to transport stop command.protected intThe tcp listen port for this memberprotected intThe tcp/SSL listen port for this memberprotected longFor the local member onlyprotected static final StringManagerThe string manager for this class.static final byte[]The start marker for tribes member data.static final byte[]The end marker for tribes member data.protected intThe udp listen port for this memberprotected byte[]Unique session Id for this memberFields inherited from interface Member
SHUTDOWN_PAYLOAD -
Constructor Summary
ConstructorsConstructorDescriptionEmpty constructor for serializationMemberImpl(String host, int port, long aliveTime) Construct a new member object.MemberImpl(String host, int port, long aliveTime, byte[] payload) Construct a new member object with payload. -
Method Summary
Modifier and TypeMethodDescriptionstatic StringbToS(byte[] data) Convert byte array to string.static StringbToS(byte[] data, int max) Convert byte array to string with max length.booleanReturns true if the param o is a McastMember with the same namebyte[]Return the command associated with this member.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 databyte[]getData(boolean getalive, boolean reset) Highly optimized version of serializing a member into a byte array Returns a cached byte[] reference, do not modify this dataintLength of a message obtained byMember.getData(boolean)orMember.getData(boolean, boolean).byte[]Return the domain for this cluster.byte[]getHost()Returns the listen host for the ChannelReceiver implementationGet the hostname.static MembergetMember(byte[] data) Deserializes a member from data sent over the wire.static MembergetMember(byte[] data, int offset, int length) Deserializes a member from data sent over the wire.static MembergetMember(byte[] data, int offset, int length, MemberImpl member) Deserializes a member from data sent over the wire.static MembergetMember(byte[] data, MemberImpl member) Deserializes a member from data sent over the wire.longContains information on how long this member has been online.intGet the message count.getName()Return the name of this node, should be unique within the group.byte[]Return the payload associated with this member.intgetPort()Returns the listen port for the ChannelReceiver implementationintReturns the secure listen port for the ChannelReceiver implementation.longGet the service start time.intReturns the UDP port that this member is listening to for UDP messages.byte[]returns a UUID unique for this member over all sessions.inthashCode()protected voidinc()Increment the message count.booleanCheck if the member has been confirmed to malfunction.booleanisLocal()Check if the member is the local member.booleanisReady()The current state of the member.booleanThe current state of the member.voidvoidsetCommand(byte[] command) Set the command associated with this member.voidsetDomain(byte[] domain) Set the domain.voidsetHost(byte[] host) Set the host.voidsetHostname(String host) Set the hostname.voidsetLocal(boolean local) Set if the member is local.voidsetMemberAliveTime(long time) Set the alive time in ms.voidsetMsgCount(int msgCount) Set the message count.voidsetPayload(byte[] payload) Set the payload associated with this member.voidsetPort(int port) Set the port.voidsetSecurePort(int securePort) Set the secure port.voidsetServiceStartTime(long serviceStartTime) Set the service start time.voidsetUdpPort(int port) Set the UDP port.voidsetUniqueId(byte[] uniqueId) Set the unique ID.toString()void
-
Field Details
-
TRIBES_MBR_BEGIN
public static final byte[] TRIBES_MBR_BEGINThe start marker for tribes member data. -
TRIBES_MBR_END
public static final byte[] TRIBES_MBR_ENDThe end marker for tribes member data. -
sm
The string manager for this class. -
host
protected volatile byte[] hostThe listen host for this member. -
hostname
The hostname string representation. -
port
protected volatile int portThe tcp listen port for this member -
udpPort
protected volatile int udpPortThe udp listen port for this member -
securePort
protected volatile int securePortThe tcp/SSL listen port for this member -
msgCount
Counter for how many broadcast messages have been sent from this member -
memberAliveTime
protected volatile long memberAliveTimeThe number of milliseconds since this member was created, is kept track of using the start time -
serviceStartTime
protected transient long serviceStartTimeFor the local member only -
dataPkg
protected transient byte[] dataPkgTo avoid serialization over and over again, once the local dataPkg has been set, we use that to transmit data -
uniqueId
protected volatile byte[] uniqueIdUnique session Id for this member -
payload
protected volatile byte[] payloadCustom payload that an app framework can broadcast Also used to transport stop command. -
command
protected volatile byte[] commandCommand, so that the custom payload doesn't have to be used This is for internal tribes use, such as SHUTDOWN_COMMAND -
domain
protected volatile byte[] domainDomain if we want to filter based on domain. -
local
protected volatile boolean localThe flag indicating that this member is a local member.
-
-
Constructor Details
-
MemberImpl
public MemberImpl()Empty constructor for serialization -
MemberImpl
Construct a new member object.- Parameters:
host- - the tcp listen hostport- - the tcp listen portaliveTime- - the number of milliseconds since this member was created- Throws:
IOException- If there is an error converting the host name to an IP address
-
MemberImpl
Construct a new member object with payload.- Parameters:
host- the tcp listen hostport- the tcp listen portaliveTime- the number of milliseconds since this member was createdpayload- the payload- Throws:
IOException- if there is an error converting the host name to an IP address
-
-
Method Details
-
isReady
-
isSuspect
-
isFailing
-
inc
protected void inc()Increment the message count. -
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
-
getData
public byte[] getData(boolean getalive) Description copied from interface:MemberHighly optimized version of serializing a member into a byte array Returns a cached byte[] reference, do not modify this data -
getDataLength
public int getDataLength()Description copied from interface:MemberLength of a message obtained byMember.getData(boolean)orMember.getData(boolean, boolean).- Specified by:
getDataLengthin interfaceMember- Returns:
- the data length
-
getData
public byte[] getData(boolean getalive, boolean reset) Description copied from interface:MemberHighly optimized version of serializing a member into a byte array Returns a cached byte[] reference, do not modify this data -
getMember
Deserializes a member from data sent over the wire.- Parameters:
data- The bytes receivedmember- The member object to populate- Returns:
- The populated member object.
-
getMember
Deserializes a member from data sent over the wire.- Parameters:
data- The bytes receivedoffset- The offsetlength- The lengthmember- The member object to populate- Returns:
- The populated member object
-
getMember
Deserializes a member from data sent over the wire.- Parameters:
data- the bytes received- Returns:
- the member
-
getMember
Deserializes a member from data sent over the wire.- Parameters:
data- the bytes receivedoffset- the offsetlength- the length- Returns:
- the member
-
getName
-
getPort
-
getHost
-
getHostname
-
getMsgCount
public int getMsgCount()Get the message count.- Returns:
- the message count
-
getMemberAliveTime
public long getMemberAliveTime()Description copied from interface:MemberContains information on how long this member has been online. The result is the number of milliseconds this member has been broadcasting its membership to the group.- Specified by:
getMemberAliveTimein interfaceMember- Returns:
- nr of milliseconds since this member started.
-
getServiceStartTime
public long getServiceStartTime()Get the service start time.- Returns:
- the service start time
-
getUniqueId
public byte[] getUniqueId()Description copied from interface:Memberreturns a UUID unique for this member over all sessions. If the member crashes and restarts, the uniqueId will be different.- Specified by:
getUniqueIdin interfaceMember- Returns:
- byte[]
-
getPayload
public byte[] getPayload()Description copied from interface:MemberReturn the payload associated with this member.- Specified by:
getPayloadin interfaceMember- Returns:
- the payload associated with this member
-
getCommand
public byte[] getCommand()Description copied from interface:MemberReturn the command associated with this member.- Specified by:
getCommandin interfaceMember- Returns:
- the command associated with this member
-
getDomain
-
getSecurePort
public int getSecurePort()Description copied from interface:MemberReturns the secure listen port for the ChannelReceiver implementation. Returns -1 if it's not listening to a secure port.- Specified by:
getSecurePortin interfaceMember- Returns:
- the listen port for this member, -1 if it's not listening on a secure port
- See Also:
-
getUdpPort
public int getUdpPort()Description copied from interface:MemberReturns the UDP port that this member is listening to for UDP messages.- Specified by:
getUdpPortin interfaceMember- Returns:
- the listen UDP port for this member, -1 if it's not listening on a UDP port
-
setMemberAliveTime
public void setMemberAliveTime(long time) Description copied from interface:MemberSet the alive time in ms.- Specified by:
setMemberAliveTimein interfaceMember- Parameters:
time- the value to set
-
toString
-
bToS
Convert byte array to string.- Parameters:
data- the data- Returns:
- the string
-
bToS
Convert byte array to string with max length.- Parameters:
data- the datamax- the max length- Returns:
- the string
-
hashCode
-
equals
-
setHost
public void setHost(byte[] host) Set the host.- Parameters:
host- the host
-
setHostname
Set the hostname.- Parameters:
host- the hostname- Throws:
IOException- if there is an error converting the host name to an IP address
-
setMsgCount
public void setMsgCount(int msgCount) Set the message count.- Parameters:
msgCount- the message count
-
setPort
public void setPort(int port) Set the port.- Parameters:
port- the port
-
setServiceStartTime
public void setServiceStartTime(long serviceStartTime) Set the service start time.- Parameters:
serviceStartTime- the service start time
-
setUniqueId
public void setUniqueId(byte[] uniqueId) Set the unique ID.- Parameters:
uniqueId- the unique ID
-
setPayload
public void setPayload(byte[] payload) Description copied from interface:MemberSet the payload associated with this member.- Specified by:
setPayloadin interfaceMember- Parameters:
payload- the payload
-
setCommand
public void setCommand(byte[] command) Description copied from interface:MemberSet the command associated with this member.- Specified by:
setCommandin interfaceMember- Parameters:
command- the command
-
setDomain
public void setDomain(byte[] domain) Set the domain.- Parameters:
domain- the domain
-
setSecurePort
public void setSecurePort(int securePort) Set the secure port.- Parameters:
securePort- the secure port
-
setUdpPort
public void setUdpPort(int port) Set the UDP port.- Parameters:
port- the UDP port
-
isLocal
-
setLocal
-
readExternal
- Specified by:
readExternalin interfaceExternalizable- Throws:
IOExceptionClassNotFoundException
-
writeExternal
- Specified by:
writeExternalin interfaceExternalizable- Throws:
IOException
-