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 class
McastServiceImpl.ReceiverThread
protected static class
McastServiceImpl.RecoveryThread
class
McastServiceImpl.SenderThread
-
Field Summary
Fields Modifier and Type Field Description protected java.net.InetAddress
address
The multicast addressprotected boolean
doRunReceiver
protected boolean
doRunSender
Internal flag used for the listen thread that listens to the multicasting socket.protected java.lang.Object
expiredMutex
protected boolean
localLoopbackDisabled
disable/enable local loopback messageprotected static int
MAX_PACKET_SIZE
protected java.net.InetAddress
mcastBindAddress
bind addressprotected int
mcastSoTimeout
Read timeout on the mcast socketprotected int
mcastTTL
Time to live for the multicast packets that are being sent outprotected MemberImpl
member
The local member that we intend to broad cast over and over againprotected MessageListener
msgservice
The actual listener for broadcast callbacksprotected int
port
The multicast portprotected java.net.DatagramPacket
receivePacket
Reuse the receivePacket, no need to create a new one every timeprotected McastServiceImpl.ReceiverThread
receiver
Thread to listen for pingsprotected int
recoveryCounter
nr of times the system has to fail before a recovery is initiatedprotected boolean
recoveryEnabled
Add the ability to turn on/off recoveryprotected long
recoverySleepTime
The time the recovery thread sleeps between recovery attemptsprotected McastServiceImpl.SenderThread
sender
Thread to send pingsprotected long
sendFrequency
How often to we send out a broadcast saying we are alive, must be smaller than timeToExpirationprotected java.net.DatagramPacket
sendPacket
Reuse the sendPacket, no need to create a new one every timeprotected MembershipListener
service
The actual listener, for callback when stuff goes downprotected static StringManager
sm
protected java.net.MulticastSocket
socket
Socket that we intend to listen toprotected int
startLevel
protected long
timeToExpiration
The time it takes for a member to expire.-
Fields inherited from class org.apache.catalina.tribes.membership.MembershipProviderBase
executor, membership, membershipListener
-
-
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 void
checkExpired()
Channel
getChannel()
int
getRecoveryCounter()
long
getRecoverySleepTime()
long
getServiceStartTime()
void
init()
boolean
isRecoveryEnabled()
void
receive()
Receive a datagram packet, locking waitvoid
send(boolean checkexpired)
Send a ping.void
send(boolean checkexpired, java.net.DatagramPacket packet)
void
setChannel(Channel channel)
void
setRecoveryCounter(int recoveryCounter)
void
setRecoveryEnabled(boolean recoveryEnabled)
void
setRecoverySleepTime(long recoverySleepTime)
protected void
setupSocket()
void
start(int level)
Start the serviceboolean
stop(int level)
Stops the service.-
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
- See Also:
- Constant Field Values
-
sm
protected static final StringManager sm
-
doRunSender
protected volatile boolean doRunSender
Internal flag used for the listen thread that listens to the multicasting socket.
-
doRunReceiver
protected volatile boolean doRunReceiver
-
startLevel
protected volatile int startLevel
-
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 broad cast 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
-
service
protected final MembershipListener service
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
-
-
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.IOException
- Throws:
java.io.IOException
-
setupSocket
protected void setupSocket() throws java.io.IOException
- Throws:
java.io.IOException
-
start
public void start(int level) throws java.io.IOException
Start the service- Parameters:
level
- 1 starts the receiver, level 2 starts the sender- Throws:
java.io.IOException
- if the service fails to startjava.lang.IllegalStateException
- if the service is already started
-
stop
public boolean stop(int level) throws java.io.IOException
Stops the service.- Parameters:
level
- Stop status- Returns:
true
if the stop is complete- Throws:
java.io.IOException
- if the service fails to disconnect from the sockets
-
receive
public void receive() throws java.io.IOException
Receive a datagram packet, locking wait- Throws:
java.io.IOException
- Received failed
-
checkExpired
protected void checkExpired()
-
send
public void send(boolean checkexpired) throws java.io.IOException
Send a ping.- Parameters:
checkexpired
-true
to check for expiration- Throws:
java.io.IOException
- Send error
-
send
public void send(boolean checkexpired, java.net.DatagramPacket packet) throws java.io.IOException
- Throws:
java.io.IOException
-
getServiceStartTime
public long getServiceStartTime()
-
getRecoveryCounter
public int getRecoveryCounter()
-
isRecoveryEnabled
public boolean isRecoveryEnabled()
-
getRecoverySleepTime
public long getRecoverySleepTime()
-
getChannel
public Channel getChannel()
-
setChannel
public void setChannel(Channel channel)
-
setRecoveryCounter
public void setRecoveryCounter(int recoveryCounter)
-
setRecoveryEnabled
public void setRecoveryEnabled(boolean recoveryEnabled)
-
setRecoverySleepTime
public void setRecoverySleepTime(long recoverySleepTime)
-
-