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 TypeClassDescriptionclassprotected static classclass -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final InetAddressThe multicast addressprotected booleanprotected booleanInternal flag used for the listen thread that listens to the multicasting socket.protected final Objectprotected final booleandisable/enable local loopback messageprotected static final intprotected 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 broad cast over and over againprotected 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 final MembershipListenerThe actual listener, for callback when stuff goes downprotected static final StringManagerprotected MulticastSocketSocket that we intend to listen toprotected intprotected final longThe time it takes for a member to expire.Fields inherited from class org.apache.catalina.tribes.membership.MembershipProviderBase
executor, membership, membershipListener -
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 voidintlonglongvoidinit()booleanvoidreceive()Receive a datagram packet, locking waitvoidsend(boolean checkexpired) Send a ping.voidsend(boolean checkexpired, DatagramPacket packet) voidsetChannel(Channel channel) voidsetRecoveryCounter(int recoveryCounter) voidsetRecoveryEnabled(boolean recoveryEnabled) voidsetRecoverySleepTime(long recoverySleepTime) protected voidvoidstart(int level) Start the membership provider.booleanstop(int level) Stop the membership provider.Methods inherited from class org.apache.catalina.tribes.membership.MembershipProviderBase
getMember, getMembers, hasMembers, init, setMembershipListener, setMembershipService
-
Field Details
-
MAX_PACKET_SIZE
protected static final int MAX_PACKET_SIZE- See Also:
-
sm
-
doRunSender
protected volatile boolean doRunSenderInternal flag used for the listen thread that listens to the multicasting socket. -
doRunReceiver
protected volatile boolean doRunReceiver -
startLevel
protected volatile int startLevel -
socket
Socket that we intend to listen to -
member
The local member that we intend to broad cast 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 -
service
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
-
-
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
- Throws:
IOException
-
setupSocket
- Throws:
IOException
-
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() -
send
Send a ping.- Parameters:
checkexpired-trueto check for expiration- Throws:
IOException- Send error
-
send
- Throws:
IOException
-
getServiceStartTime
public long getServiceStartTime() -
getRecoveryCounter
public int getRecoveryCounter() -
isRecoveryEnabled
public boolean isRecoveryEnabled() -
getRecoverySleepTime
public long getRecoverySleepTime() -
getChannel
-
setChannel
-
setRecoveryCounter
public void setRecoveryCounter(int recoveryCounter) -
setRecoveryEnabled
public void setRecoveryEnabled(boolean recoveryEnabled) -
setRecoverySleepTime
public void setRecoverySleepTime(long recoverySleepTime)
-