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 SummaryNested ClassesModifier and TypeClassDescriptionclassprotected static classclass
- 
Field SummaryFieldsModifier 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.MembershipProviderBaseexecutor, membership, membershipListener
- 
Constructor SummaryConstructorsConstructorDescriptionMcastServiceImpl(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 SummaryModifier 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 servicebooleanstop(int level) Stops the service.Methods inherited from class org.apache.catalina.tribes.membership.MembershipProviderBasegetMember, getMembers, hasMembers, init, setMembershipListener, setMembershipService
- 
Field Details- 
MAX_PACKET_SIZEprotected static final int MAX_PACKET_SIZE- See Also:
 
- 
sm
- 
doRunSenderprotected volatile boolean doRunSenderInternal flag used for the listen thread that listens to the multicasting socket.
- 
doRunReceiverprotected volatile boolean doRunReceiver
- 
startLevelprotected volatile int startLevel
- 
socketSocket that we intend to listen to
- 
memberThe local member that we intend to broad cast over and over again
- 
addressThe multicast address
- 
portprotected final int portThe multicast port
- 
timeToExpirationprotected final long timeToExpirationThe time it takes for a member to expire.
- 
sendFrequencyprotected final long sendFrequencyHow often to we send out a broadcast saying we are alive, must be smaller than timeToExpiration
- 
sendPacketReuse the sendPacket, no need to create a new one every time
- 
receivePacketReuse the receivePacket, no need to create a new one every time
- 
serviceThe actual listener, for callback when stuff goes down
- 
msgserviceThe actual listener for broadcast callbacks
- 
receiverThread to listen for pings
- 
senderThread to send pings
- 
mcastTTLprotected final int mcastTTLTime to live for the multicast packets that are being sent out
- 
mcastSoTimeoutprotected int mcastSoTimeoutRead timeout on the mcast socket
- 
mcastBindAddressbind address
- 
recoveryCounterprotected int recoveryCounternr of times the system has to fail before a recovery is initiated
- 
recoverySleepTimeprotected long recoverySleepTimeThe time the recovery thread sleeps between recovery attempts
- 
recoveryEnabledprotected boolean recoveryEnabledAdd the ability to turn on/off recovery
- 
localLoopbackDisabledprotected final boolean localLoopbackDisableddisable/enable local loopback message
- 
expiredMutex
 
- 
- 
Constructor Details- 
McastServiceImplpublic 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 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:
- IOException- Init error
 
 
- 
- 
Method Details- 
init- Throws:
- IOException
 
- 
setupSocket- Throws:
- IOException
 
- 
startStart the service- Parameters:
- level- 1 starts the receiver, level 2 starts the sender
- Throws:
- IOException- if the service fails to start
- IllegalStateException- if the service is already started
 
- 
stopStops the service.- Parameters:
- level- Stop status
- Returns:
- trueif the stop is complete
- Throws:
- IOException- if the service fails to disconnect from the sockets
 
- 
receiveReceive a datagram packet, locking wait- Throws:
- IOException- Received failed
 
- 
checkExpiredprotected void checkExpired()
- 
sendSend a ping.- Parameters:
- checkexpired-- trueto check for expiration
- Throws:
- IOException- Send error
 
- 
send- Throws:
- IOException
 
- 
getServiceStartTimepublic long getServiceStartTime()
- 
getRecoveryCounterpublic int getRecoveryCounter()
- 
isRecoveryEnabledpublic boolean isRecoveryEnabled()
- 
getRecoverySleepTimepublic long getRecoverySleepTime()
- 
getChannel
- 
setChannel
- 
setRecoveryCounterpublic void setRecoveryCounter(int recoveryCounter) 
- 
setRecoveryEnabledpublic void setRecoveryEnabled(boolean recoveryEnabled) 
- 
setRecoverySleepTimepublic void setRecoverySleepTime(long recoverySleepTime) 
 
-