Class McastServiceImpl
java.lang.Object
org.apache.catalina.tribes.membership.MembershipProviderBase
org.apache.catalina.tribes.membership.McastServiceImpl
- All Implemented Interfaces:
MembershipProvider
A membership implementation using simple multicast. This is the representation of a multicast membership
service. This class is responsible for maintaining a list of active cluster nodes in the cluster. If a node fails to
send out a heartbeat, the node will be dismissed. This is the low level implementation that handles the multicasting
sockets. Need to fix this, could use java.nio and only need one thread to send and receive, or just use a timeout on
the receive
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionclassThread that receives multicast packets.protected static classThread that handles recovery.classThread that sends multicast packets. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final InetAddressThe multicast addressprotected booleanFlag to control the receiver thread.protected booleanFlag to control the sender thread.protected final ObjectMutex for expired member checking.protected final booleandisable/enable local loopback messageprotected static final intThe maximum packet size.protected final InetAddressbind addressprotected intRead timeout on the mcast socketprotected final intTime to live for the multicast packets that are being sent outprotected final MemberImplThe local member that we intend to broadcast over and over againprotected final MembershipListenerThe actual listener, for callback when stuff goes downprotected final MessageListenerThe actual listener for broadcast callbacksprotected final intThe multicast portprotected DatagramPacketReuse the receivePacket, no need to create a new one every timeprotected McastServiceImpl.ReceiverThreadThread to listen for pingsprotected intnr of times the system has to fail before a recovery is initiatedprotected booleanAdd the ability to turn on/off recoveryprotected longThe time the recovery thread sleeps between recovery attemptsprotected McastServiceImpl.SenderThreadThread to send pingsprotected final longHow often to we send out a broadcast saying we are alive, must be smaller than timeToExpirationprotected DatagramPacketReuse the sendPacket, no need to create a new one every timeprotected static final StringManagerThe string manager for this class.protected MulticastSocketSocket that we intend to listen toprotected intThe start level.protected final longThe time it takes for a member to expire.Fields inherited from class MembershipProviderBase
executor, membership, membershipListener, service -
Constructor Summary
ConstructorsConstructorDescriptionMcastServiceImpl(MemberImpl member, long sendFrequency, long expireTime, int port, InetAddress bind, InetAddress mcastAddress, int ttl, int soTimeout, MembershipListener service, MessageListener msgservice, boolean localLoopbackDisabled) Create a new mcast service instance. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidCheck for expired members.Get the channel.intGet the recovery counter.longGet the recovery sleep time.longGet the service start time.voidinit()Initialize the mcast service.booleanCheck if recovery is enabled.voidreceive()Receive a datagram packet, locking waitvoidsend(boolean checkexpired) Send a ping.voidsend(boolean checkexpired, DatagramPacket packet) Send a packet.voidsetChannel(Channel channel) Set the channel.voidsetRecoveryCounter(int recoveryCounter) Set the recovery counter.voidsetRecoveryEnabled(boolean recoveryEnabled) Set whether recovery is enabled.voidsetRecoverySleepTime(long recoverySleepTime) Set the recovery sleep time.protected voidSetup the multicast socket.voidstart(int level) Start the membership provider.booleanstop(int level) Stop the membership provider.Methods inherited from class MembershipProviderBase
getMember, getMembers, hasMembers, init, setMembershipListener, setMembershipService
-
Field Details
-
MAX_PACKET_SIZE
protected static final int MAX_PACKET_SIZEThe maximum packet size.- See Also:
-
sm
The string manager for this class. -
doRunSender
protected volatile boolean doRunSenderFlag to control the sender thread. -
doRunReceiver
protected volatile boolean doRunReceiverFlag to control the receiver thread. -
startLevel
protected volatile int startLevelThe start level. -
socket
Socket that we intend to listen to -
member
The local member that we intend to broadcast over and over again -
address
The multicast address -
port
protected final int portThe multicast port -
timeToExpiration
protected final long timeToExpirationThe time it takes for a member to expire. -
sendFrequency
protected final long sendFrequencyHow often to we send out a broadcast saying we are alive, must be smaller than timeToExpiration -
sendPacket
Reuse the sendPacket, no need to create a new one every time -
receivePacket
Reuse the receivePacket, no need to create a new one every time -
memberService
The actual listener, for callback when stuff goes down -
msgservice
The actual listener for broadcast callbacks -
receiver
Thread to listen for pings -
sender
Thread to send pings -
mcastTTL
protected final int mcastTTLTime to live for the multicast packets that are being sent out -
mcastSoTimeout
protected int mcastSoTimeoutRead timeout on the mcast socket -
mcastBindAddress
bind address -
recoveryCounter
protected int recoveryCounternr of times the system has to fail before a recovery is initiated -
recoverySleepTime
protected long recoverySleepTimeThe time the recovery thread sleeps between recovery attempts -
recoveryEnabled
protected boolean recoveryEnabledAdd the ability to turn on/off recovery -
localLoopbackDisabled
protected final boolean localLoopbackDisableddisable/enable local loopback message -
expiredMutex
Mutex for expired member checking.
-
-
Constructor Details
-
McastServiceImpl
public McastServiceImpl(MemberImpl member, long sendFrequency, long expireTime, int port, InetAddress bind, InetAddress mcastAddress, int ttl, int soTimeout, MembershipListener service, MessageListener msgservice, boolean localLoopbackDisabled) throws IOException Create a new mcast service instance.- Parameters:
member- - the local membersendFrequency- - the time (ms) in between pings sent outexpireTime- - the time (ms) for a member to expireport- - the mcast portbind- - the bind address (not sure this is used yet)mcastAddress- - the mcast addressttl- multicast ttl that will be set on the socketsoTimeout- Socket timeoutservice- - the callback servicemsgservice- Message listenerlocalLoopbackDisabled- - disable loopbackMode- Throws:
IOException- Init error
-
-
Method Details
-
init
Initialize the mcast service.- Throws:
IOException- if initialization fails
-
setupSocket
Setup the multicast socket.- Throws:
IOException- if socket setup fails
-
start
Description copied from interface:MembershipProviderStart the membership provider.- Parameters:
level- the readiness level- Channel.DEFAULT - will start all services
- Channel.MBR_RX_SEQ - starts the membership receiver
- Channel.MBR_TX_SEQ - starts the membership broadcaster
- Throws:
IOException
-
stop
Description copied from interface:MembershipProviderStop the membership provider.- Parameters:
level- the readiness level- Channel.DEFAULT - will stop all services
- Channel.MBR_RX_SEQ - stops the membership receiver
- Channel.MBR_TX_SEQ - stops the membership broadcaster
- Returns:
trueif successful- Throws:
IOException
-
receive
Receive a datagram packet, locking wait- Throws:
IOException- Received failed
-
checkExpired
protected void checkExpired()Check for expired members. -
send
Send a ping.- Parameters:
checkexpired-trueto check for expiration- Throws:
IOException- Send error
-
send
Send a packet.- Parameters:
checkexpired- whether to check for expired memberspacket- the packet to send- Throws:
IOException- if send fails
-
getServiceStartTime
public long getServiceStartTime()Get the service start time.- Returns:
- the service start time
-
getRecoveryCounter
public int getRecoveryCounter()Get the recovery counter.- Returns:
- the recovery counter
-
isRecoveryEnabled
public boolean isRecoveryEnabled()Check if recovery is enabled.- Returns:
- true if recovery is enabled
-
getRecoverySleepTime
public long getRecoverySleepTime()Get the recovery sleep time.- Returns:
- the recovery sleep time
-
getChannel
-
setChannel
-
setRecoveryCounter
public void setRecoveryCounter(int recoveryCounter) Set the recovery counter.- Parameters:
recoveryCounter- the recovery counter
-
setRecoveryEnabled
public void setRecoveryEnabled(boolean recoveryEnabled) Set whether recovery is enabled.- Parameters:
recoveryEnabled- whether recovery is enabled
-
setRecoverySleepTime
public void setRecoverySleepTime(long recoverySleepTime) Set the recovery sleep time.- Parameters:
recoverySleepTime- the recovery sleep time
-