Class McastServiceImpl
- java.lang.Object
- 
- org.apache.catalina.tribes.membership.MembershipProviderBase
- 
- org.apache.catalina.tribes.membership.McastServiceImpl
 
 
- 
- All Implemented Interfaces:
- MembershipProvider
 
 public class McastServiceImpl extends MembershipProviderBase 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 SummaryNested Classes Modifier and Type Class Description classMcastServiceImpl.ReceiverThreadprotected static classMcastServiceImpl.RecoveryThreadclassMcastServiceImpl.SenderThread
 - 
Field SummaryFields Modifier and Type Field Description protected java.net.InetAddressaddressThe multicast addressprotected booleandoRunReceiverprotected booleandoRunSenderInternal flag used for the listen thread that listens to the multicasting socket.protected java.lang.ObjectexpiredMutexprotected booleanlocalLoopbackDisableddisable/enable local loopback messageprotected static intMAX_PACKET_SIZEprotected java.net.InetAddressmcastBindAddressbind addressprotected intmcastSoTimeoutRead timeout on the mcast socketprotected intmcastTTLTime to live for the multicast packets that are being sent outprotected MemberImplmemberThe local member that we intend to broad cast over and over againprotected MessageListenermsgserviceThe actual listener for broadcast callbacksprotected intportThe multicast portprotected java.net.DatagramPacketreceivePacketReuse the receivePacket, no need to create a new one every timeprotected McastServiceImpl.ReceiverThreadreceiverThread to listen for pingsprotected intrecoveryCounternr of times the system has to fail before a recovery is initiatedprotected booleanrecoveryEnabledAdd the ability to turn on/off recoveryprotected longrecoverySleepTimeThe time the recovery thread sleeps between recovery attemptsprotected McastServiceImpl.SenderThreadsenderThread to send pingsprotected longsendFrequencyHow often to we send out a broadcast saying we are alive, must be smaller than timeToExpirationprotected java.net.DatagramPacketsendPacketReuse the sendPacket, no need to create a new one every timeprotected MembershipListenerserviceThe actual listener, for callback when stuff goes downprotected static StringManagersmprotected java.net.MulticastSocketsocketSocket that we intend to listen toprotected intstartLevelprotected longtimeToExpirationThe time it takes for a member to expire.- 
Fields inherited from class org.apache.catalina.tribes.membership.MembershipProviderBaseexecutor, membership, membershipListener
 
- 
 - 
Constructor SummaryConstructors Constructor Description McastServiceImpl(MemberImpl member, long sendFrequency, long expireTime, int port, java.net.InetAddress bind, java.net.InetAddress mcastAddress, int ttl, int soTimeout, MembershipListener service, MessageListener msgservice, boolean localLoopbackDisabled)Create a new mcast service instance.
 - 
Method SummaryAll Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidcheckExpired()ChannelgetChannel()intgetRecoveryCounter()longgetRecoverySleepTime()longgetServiceStartTime()voidinit()booleanisRecoveryEnabled()voidreceive()Receive a datagram packet, locking waitvoidsend(boolean checkexpired)Send a ping.voidsend(boolean checkexpired, java.net.DatagramPacket packet)voidsetChannel(Channel channel)voidsetRecoveryCounter(int recoveryCounter)voidsetRecoveryEnabled(boolean recoveryEnabled)voidsetRecoverySleepTime(long recoverySleepTime)protected voidsetupSocket()voidstart(int level)Start the servicebooleanstop(int level)Stops the service.- 
Methods inherited from class org.apache.catalina.tribes.membership.MembershipProviderBasegetMember, getMembers, hasMembers, init, setMembershipListener, setMembershipService
 
- 
 
- 
- 
- 
Field Detail- 
MAX_PACKET_SIZEprotected static final int MAX_PACKET_SIZE - See Also:
- Constant Field Values
 
 - 
smprotected static final StringManager sm 
 - 
doRunSenderprotected volatile boolean doRunSender Internal flag used for the listen thread that listens to the multicasting socket.
 - 
doRunReceiverprotected volatile boolean doRunReceiver 
 - 
startLevelprotected volatile int startLevel 
 - 
socketprotected java.net.MulticastSocket socket Socket that we intend to listen to
 - 
memberprotected final MemberImpl member The local member that we intend to broad cast over and over again
 - 
addressprotected final java.net.InetAddress address The multicast address
 - 
portprotected final int port The multicast port
 - 
timeToExpirationprotected final long timeToExpiration The time it takes for a member to expire.
 - 
sendFrequencyprotected final long sendFrequency How often to we send out a broadcast saying we are alive, must be smaller than timeToExpiration
 - 
sendPacketprotected java.net.DatagramPacket sendPacket Reuse the sendPacket, no need to create a new one every time
 - 
receivePacketprotected java.net.DatagramPacket receivePacket Reuse the receivePacket, no need to create a new one every time
 - 
serviceprotected final MembershipListener service The actual listener, for callback when stuff goes down
 - 
msgserviceprotected final MessageListener msgservice The actual listener for broadcast callbacks
 - 
receiverprotected McastServiceImpl.ReceiverThread receiver Thread to listen for pings
 - 
senderprotected McastServiceImpl.SenderThread sender Thread to send pings
 - 
mcastTTLprotected final int mcastTTL Time to live for the multicast packets that are being sent out
 - 
mcastSoTimeoutprotected int mcastSoTimeout Read timeout on the mcast socket
 - 
mcastBindAddressprotected final java.net.InetAddress mcastBindAddress bind address
 - 
recoveryCounterprotected int recoveryCounter nr of times the system has to fail before a recovery is initiated
 - 
recoverySleepTimeprotected long recoverySleepTime The time the recovery thread sleeps between recovery attempts
 - 
recoveryEnabledprotected boolean recoveryEnabled Add the ability to turn on/off recovery
 - 
localLoopbackDisabledprotected final boolean localLoopbackDisabled disable/enable local loopback message
 - 
expiredMutexprotected final java.lang.Object expiredMutex 
 
- 
 - 
Constructor Detail- 
McastServiceImplpublic McastServiceImpl(MemberImpl member, long sendFrequency, long expireTime, int port, java.net.InetAddress bind, java.net.InetAddress mcastAddress, int ttl, int soTimeout, MembershipListener service, MessageListener msgservice, boolean localLoopbackDisabled) throws java.io.IOException Create a new mcast service instance.- Parameters:
- member- - the local member
- sendFrequency- - the time (ms) in between pings sent out
- expireTime- - the time (ms) for a member to expire
- port- - the mcast port
- bind- - the bind address (not sure this is used yet)
- mcastAddress- - the mcast address
- ttl- multicast ttl that will be set on the socket
- soTimeout- Socket timeout
- service- - the callback service
- msgservice- Message listener
- localLoopbackDisabled- - disable loopbackMode
- Throws:
- java.io.IOException- Init error
 
 
- 
 - 
Method Detail- 
initpublic void init() throws java.io.IOException- Throws:
- java.io.IOException
 
 - 
setupSocketprotected void setupSocket() throws java.io.IOException- Throws:
- java.io.IOException
 
 - 
startpublic void start(int level) throws java.io.IOExceptionStart the service- Parameters:
- level- 1 starts the receiver, level 2 starts the sender
- Throws:
- java.io.IOException- if the service fails to start
- java.lang.IllegalStateException- if the service is already started
 
 - 
stoppublic boolean stop(int level) throws java.io.IOExceptionStops the service.- Parameters:
- level- Stop status
- Returns:
- trueif the stop is complete
- Throws:
- java.io.IOException- if the service fails to disconnect from the sockets
 
 - 
receivepublic void receive() throws java.io.IOExceptionReceive a datagram packet, locking wait- Throws:
- java.io.IOException- Received failed
 
 - 
checkExpiredprotected void checkExpired() 
 - 
sendpublic void send(boolean checkexpired) throws java.io.IOExceptionSend a ping.- Parameters:
- checkexpired-- trueto check for expiration
- Throws:
- java.io.IOException- Send error
 
 - 
sendpublic void send(boolean checkexpired, java.net.DatagramPacket packet) throws java.io.IOException- Throws:
- java.io.IOException
 
 - 
getServiceStartTimepublic long getServiceStartTime() 
 - 
getRecoveryCounterpublic int getRecoveryCounter() 
 - 
isRecoveryEnabledpublic boolean isRecoveryEnabled() 
 - 
getRecoverySleepTimepublic long getRecoverySleepTime() 
 - 
getChannelpublic Channel getChannel() 
 - 
setChannelpublic void setChannel(Channel channel) 
 - 
setRecoveryCounterpublic void setRecoveryCounter(int recoveryCounter) 
 - 
setRecoveryEnabledpublic void setRecoveryEnabled(boolean recoveryEnabled) 
 - 
setRecoverySleepTimepublic void setRecoverySleepTime(long recoverySleepTime) 
 
- 
 
-