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
Modifier and TypeClassDescriptionclass
protected static class
class
-
Field Summary
Modifier and TypeFieldDescriptionprotected final InetAddress
The multicast addressprotected boolean
protected boolean
Internal flag used for the listen thread that listens to the multicasting socket.protected final Object
protected final boolean
disable/enable local loopback messageprotected static final int
protected final InetAddress
bind addressprotected int
Read timeout on the mcast socketprotected final int
Time to live for the multicast packets that are being sent outprotected final MemberImpl
The local member that we intend to broad cast over and over againprotected final MessageListener
The actual listener for broadcast callbacksprotected final int
The multicast portprotected DatagramPacket
Reuse the receivePacket, no need to create a new one every timeprotected McastServiceImpl.ReceiverThread
Thread to listen for pingsprotected int
nr of times the system has to fail before a recovery is initiatedprotected boolean
Add the ability to turn on/off recoveryprotected long
The time the recovery thread sleeps between recovery attemptsprotected McastServiceImpl.SenderThread
Thread to send pingsprotected final long
How often to we send out a broadcast saying we are alive, must be smaller than timeToExpirationprotected DatagramPacket
Reuse the sendPacket, no need to create a new one every timeprotected final MembershipListener
The actual listener, for callback when stuff goes downprotected static final StringManager
protected MulticastSocket
Socket that we intend to listen toprotected int
protected final long
The time it takes for a member to expire.Fields inherited from class org.apache.catalina.tribes.membership.MembershipProviderBase
executor, membership, membershipListener
-
Constructor Summary
ConstructorDescriptionMcastServiceImpl
(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 void
int
long
long
void
init()
boolean
void
receive()
Receive a datagram packet, locking waitvoid
send
(boolean checkexpired) Send a ping.void
send
(boolean checkexpired, DatagramPacket packet) void
setChannel
(Channel channel) void
setRecoveryCounter
(int recoveryCounter) void
setRecoveryEnabled
(boolean recoveryEnabled) void
setRecoverySleepTime
(long recoverySleepTime) protected void
void
start
(int level) Start the membership provider.boolean
stop
(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:MembershipProvider
Start 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:MembershipProvider
Stop 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:
true
if successful- Throws:
IOException
-
receive
Receive a datagram packet, locking wait- Throws:
IOException
- Received failed
-
checkExpired
protected void checkExpired() -
send
Send a ping.- Parameters:
checkexpired
-true
to 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)
-