Class MemberImpl
- java.lang.Object
-
- org.apache.catalina.tribes.membership.MemberImpl
-
- All Implemented Interfaces:
Externalizable,Serializable,Member
- Direct Known Subclasses:
StaticMember
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.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected byte[]commandCommand, so that the custom payload doesn't have to be used This is for internal tribes use, such as SHUTDOWN_COMMANDprotected byte[]dataPkgTo avoid serialization over and over again, once the local dataPkg has been set, we use that to transmit dataprotected byte[]domainDomain if we want to filter based on domain.protected byte[]hostThe listen host for this memberprotected Stringhostnameprotected booleanlocalThe flag indicating that this member is a local member.protected longmemberAliveTimeThe number of milliseconds since this member was created, is kept track of using the start timeprotected AtomicIntegermsgCountCounter for how many broadcast messages have been sent from this memberprotected byte[]payloadCustom payload that an app framework can broadcast Also used to transport stop command.protected intportThe tcp listen port for this memberprotected intsecurePortThe tcp/SSL listen port for this memberprotected longserviceStartTimeFor the local member onlyprotected static StringManagersmstatic byte[]TRIBES_MBR_BEGINstatic byte[]TRIBES_MBR_ENDprotected intudpPortThe udp listen port for this memberprotected byte[]uniqueIdUnique session Id for this member-
Fields inherited from interface org.apache.catalina.tribes.Member
SHUTDOWN_PAYLOAD
-
-
Constructor Summary
Constructors Constructor Description MemberImpl()Empty constructor for serializationMemberImpl(String host, int port, long aliveTime)Construct a new member object.MemberImpl(String host, int port, long aliveTime, byte[] payload)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description 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 namebyte[]getCommand()returns the command associated with this memberbyte[]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 dataintgetDataLength()Length of a message obtained byMember.getData(boolean)orMember.getData(boolean, boolean).byte[]getDomain()Domain for this clusterbyte[]getHost()Return the TCP listen host for this memberStringgetHostname()static MembergetMember(byte[] data)static MembergetMember(byte[] data, int offset, int length)static MembergetMember(byte[] data, int offset, int length, MemberImpl member)static MembergetMember(byte[] data, MemberImpl member)Deserializes a member from data sent over the wire.longgetMemberAliveTime()Contains information on how long this member has been online.intgetMsgCount()StringgetName()Return the name of this objectbyte[]getPayload()returns the payload associated with this memberintgetPort()Return the listen port of this memberintgetSecurePort()Returns the secure listen port for the ChannelReceiver implementation.longgetServiceStartTime()intgetUdpPort()Returns the UDP port that this member is listening to for UDP messages.byte[]getUniqueId()returns a UUID unique for this member over all sessions.inthashCode()protected voidinc()Increment the message count.booleanisFailing()booleanisLocal()booleanisReady()The current state of the memberbooleanisSuspect()The current state of the membervoidreadExternal(ObjectInput in)voidsetCommand(byte[] command)voidsetDomain(byte[] domain)voidsetHost(byte[] host)voidsetHostname(String host)voidsetLocal(boolean local)voidsetMemberAliveTime(long time)voidsetMsgCount(int msgCount)voidsetPayload(byte[] payload)voidsetPort(int port)voidsetSecurePort(int securePort)voidsetServiceStartTime(long serviceStartTime)voidsetUdpPort(int port)voidsetUniqueId(byte[] uniqueId)StringtoString()String representation of this objectvoidwriteExternal(ObjectOutput out)
-
-
-
Field Detail
-
TRIBES_MBR_BEGIN
public static final transient byte[] TRIBES_MBR_BEGIN
-
TRIBES_MBR_END
public static final transient byte[] TRIBES_MBR_END
-
sm
protected static final StringManager sm
-
host
protected volatile byte[] host
The listen host for this member
-
hostname
protected transient volatile String hostname
-
port
protected volatile int port
The tcp listen port for this member
-
udpPort
protected volatile int udpPort
The udp listen port for this member
-
securePort
protected volatile int securePort
The tcp/SSL listen port for this member
-
msgCount
protected AtomicInteger msgCount
Counter for how many broadcast messages have been sent from this member
-
memberAliveTime
protected volatile long memberAliveTime
The number of milliseconds since this member was created, is kept track of using the start time
-
serviceStartTime
protected transient long serviceStartTime
For the local member only
-
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
-
uniqueId
protected volatile byte[] uniqueId
Unique session Id for this member
-
payload
protected volatile byte[] payload
Custom payload that an app framework can broadcast Also used to transport stop command.
-
command
protected volatile byte[] command
Command, 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[] domain
Domain if we want to filter based on domain.
-
local
protected volatile boolean local
The flag indicating that this member is a local member.
-
-
Constructor Detail
-
MemberImpl
public MemberImpl()
Empty constructor for serialization
-
MemberImpl
public MemberImpl(String host, int port, long aliveTime) throws IOException
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
public MemberImpl(String host, int port, long aliveTime, byte[] payload) throws IOException
- Throws:
IOException
-
-
Method Detail
-
isReady
public boolean isReady()
Description copied from interface:MemberThe current state of the member
-
isSuspect
public boolean isSuspect()
Description copied from interface:MemberThe current state of the member
-
isFailing
public boolean 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
public static Member getMember(byte[] data, MemberImpl member)
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
public static Member getMember(byte[] data, int offset, int length, MemberImpl member)
-
getMember
public static Member getMember(byte[] data)
-
getMember
public static Member getMember(byte[] data, int offset, int length)
-
getName
public String getName()
Return the name of this object
-
getPort
public int getPort()
Return the listen port of this member- Specified by:
getPortin interfaceMember- Returns:
- - tcp listen port
- See Also:
ChannelReceiver
-
getHost
public byte[] getHost()
Return the TCP listen host for this member- Specified by:
getHostin interfaceMember- Returns:
- IP address or host name
- See Also:
ChannelReceiver
-
getHostname
public String getHostname()
-
getMsgCount
public int getMsgCount()
-
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.- Specified by:
getMemberAliveTimein interfaceMember- Returns:
- nr of milliseconds since this member started.
-
getServiceStartTime
public long getServiceStartTime()
-
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:Memberreturns the payload associated with this member- Specified by:
getPayloadin interfaceMember- Returns:
- byte[]
-
getCommand
public byte[] getCommand()
Description copied from interface:Memberreturns the command associated with this member- Specified by:
getCommandin interfaceMember- Returns:
- byte[]
-
getDomain
public byte[] getDomain()
Description copied from interface:MemberDomain for this cluster
-
getSecurePort
public int getSecurePort()
Description copied from interface:MemberReturns the secure listen port for the ChannelReceiver implementation. Returns -1 if its not listening to a secure port.- Specified by:
getSecurePortin interfaceMember- Returns:
- the listen port for this member, -1 if its not listening on a secure port
- See Also:
ChannelReceiver
-
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 its not listening on a UDP port
-
setMemberAliveTime
public void setMemberAliveTime(long time)
- Specified by:
setMemberAliveTimein interfaceMember
-
toString
public String toString()
String representation of this object
-
bToS
public static String bToS(byte[] data)
-
bToS
public static String bToS(byte[] data, int max)
-
hashCode
public int hashCode()
- Overrides:
hashCodein classObject- Returns:
- The hash code
- See Also:
Object.hashCode()
-
equals
public boolean equals(Object o)
Returns true if the param o is a McastMember with the same name
-
setHost
public void setHost(byte[] host)
-
setHostname
public void setHostname(String host) throws IOException
- Throws:
IOException
-
setMsgCount
public void setMsgCount(int msgCount)
-
setPort
public void setPort(int port)
-
setServiceStartTime
public void setServiceStartTime(long serviceStartTime)
-
setUniqueId
public void setUniqueId(byte[] uniqueId)
-
setPayload
public void setPayload(byte[] payload)
- Specified by:
setPayloadin interfaceMember
-
setCommand
public void setCommand(byte[] command)
- Specified by:
setCommandin interfaceMember
-
setDomain
public void setDomain(byte[] domain)
-
setSecurePort
public void setSecurePort(int securePort)
-
setUdpPort
public void setUdpPort(int port)
-
isLocal
public boolean isLocal()
-
readExternal
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
- Specified by:
readExternalin interfaceExternalizable- Throws:
IOExceptionClassNotFoundException
-
writeExternal
public void writeExternal(ObjectOutput out) throws IOException
- Specified by:
writeExternalin interfaceExternalizable- Throws:
IOException
-
-