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 Summary
Nested Classes Modifier and Type Class Description classMcastServiceImpl.ReceiverThreadThread that receives multicast packets.protected static classMcastServiceImpl.RecoveryThreadThread that handles recovery.classMcastServiceImpl.SenderThreadThread that sends multicast packets.
-
Field Summary
Fields Modifier and Type Field Description protected java.net.InetAddressaddressThe multicast addressprotected booleandoRunReceiverFlag to control the receiver thread.protected booleandoRunSenderFlag to control the sender thread.protected java.lang.ObjectexpiredMutexMutex for expired member checking.protected booleanlocalLoopbackDisableddisable/enable local loopback messageprotected static intMAX_PACKET_SIZEThe maximum packet size.protected 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 broadcast over and over againprotected MembershipListenermemberServiceThe actual listener, for callback when stuff goes downprotected 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 static StringManagersmThe string manager for this class.protected java.net.MulticastSocketsocketSocket that we intend to listen toprotected intstartLevelThe start level.protected longtimeToExpirationThe time it takes for a member to expire.-
Fields inherited from class org.apache.catalina.tribes.membership.MembershipProviderBase
executor, membership, membershipListener, service
-
-
Constructor Summary
Constructors 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 Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidcheckExpired()Check for expired members.ChannelgetChannel()Get the channel.intgetRecoveryCounter()Get the recovery counter.longgetRecoverySleepTime()Get the recovery sleep time.longgetServiceStartTime()Get the service start time.voidinit()Initialize the mcast service.booleanisRecoveryEnabled()Check if recovery is enabled.voidreceive()Receive a datagram packet, locking waitvoidsend(boolean checkexpired)Send a ping.voidsend(boolean checkexpired, java.net.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 voidsetupSocket()Setup the multicast socket.voidstart(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 Detail
-
MAX_PACKET_SIZE
protected static final int MAX_PACKET_SIZE
The maximum packet size.- See Also:
- Constant Field Values
-
sm
protected static final StringManager sm
The string manager for this class.
-
doRunSender
protected volatile boolean doRunSender
Flag to control the sender thread.
-
doRunReceiver
protected volatile boolean doRunReceiver
Flag to control the receiver thread.
-
startLevel
protected volatile int startLevel
The start level.
-
socket
protected java.net.MulticastSocket socket
Socket that we intend to listen to
-
member
protected final MemberImpl member
The local member that we intend to broadcast over and over again
-
address
protected final java.net.InetAddress address
The multicast address
-
port
protected final int port
The multicast port
-
timeToExpiration
protected final long timeToExpiration
The time it takes for a member to expire.
-
sendFrequency
protected final long sendFrequency
How often to we send out a broadcast saying we are alive, must be smaller than timeToExpiration
-
sendPacket
protected java.net.DatagramPacket sendPacket
Reuse the sendPacket, no need to create a new one every time
-
receivePacket
protected java.net.DatagramPacket receivePacket
Reuse the receivePacket, no need to create a new one every time
-
memberService
protected final MembershipListener memberService
The actual listener, for callback when stuff goes down
-
msgservice
protected final MessageListener msgservice
The actual listener for broadcast callbacks
-
receiver
protected McastServiceImpl.ReceiverThread receiver
Thread to listen for pings
-
sender
protected McastServiceImpl.SenderThread sender
Thread to send pings
-
mcastTTL
protected final int mcastTTL
Time to live for the multicast packets that are being sent out
-
mcastSoTimeout
protected int mcastSoTimeout
Read timeout on the mcast socket
-
mcastBindAddress
protected final java.net.InetAddress mcastBindAddress
bind address
-
recoveryCounter
protected int recoveryCounter
nr of times the system has to fail before a recovery is initiated
-
recoverySleepTime
protected long recoverySleepTime
The time the recovery thread sleeps between recovery attempts
-
recoveryEnabled
protected boolean recoveryEnabled
Add the ability to turn on/off recovery
-
localLoopbackDisabled
protected final boolean localLoopbackDisabled
disable/enable local loopback message
-
expiredMutex
protected final java.lang.Object expiredMutex
Mutex for expired member checking.
-
-
Constructor Detail
-
McastServiceImpl
public 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 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:
java.io.IOException- Init error
-
-
Method Detail
-
init
public void init() throws java.io.IOExceptionInitialize the mcast service.- Throws:
java.io.IOException- if initialization fails
-
setupSocket
protected void setupSocket() throws java.io.IOExceptionSetup the multicast socket.- Throws:
java.io.IOException- if socket setup fails
-
start
public void start(int level) throws java.io.IOExceptionDescription 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:
java.io.IOException
-
stop
public boolean stop(int level) throws java.io.IOExceptionDescription 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:
java.io.IOException
-
receive
public void receive() throws java.io.IOExceptionReceive a datagram packet, locking wait- Throws:
java.io.IOException- Received failed
-
checkExpired
protected void checkExpired()
Check for expired members.
-
send
public void send(boolean checkexpired) throws java.io.IOExceptionSend a ping.- Parameters:
checkexpired-trueto check for expiration- Throws:
java.io.IOException- Send error
-
send
public void send(boolean checkexpired, java.net.DatagramPacket packet) throws java.io.IOExceptionSend a packet.- Parameters:
checkexpired- whether to check for expired memberspacket- the packet to send- Throws:
java.io.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
public Channel getChannel()
Get the channel.- Returns:
- the channel
-
setChannel
public void setChannel(Channel channel)
Set the channel.- Parameters:
channel- the channel to set
-
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
-
-