org.apache.catalina.tribes.membership

Class McastServiceImpl

public class McastServiceImpl extends Object

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

Version: $Revision: 787702 $, $Date: 2009-06-23 17:16:48 +0200 (Tue, 23 Jun 2009) $

Author: Filip Hanik

Nested Class Summary
classMcastServiceImpl.ReceiverThread
protected static classMcastServiceImpl.RecoveryThread
classMcastServiceImpl.SenderThread
Field Summary
protected InetAddressaddress
The multicast address
protected booleandoRunReceiver
protected booleandoRunSender
Internal flag used for the listen thread that listens to the multicasting socket.
protected ObjectexpiredMutex
protected InetAddressmcastBindAddress
bind address
protected intmcastSoTimeout
Read timeout on the mcast socket
protected intmcastTTL
Time to live for the multicast packets that are being sent out
protected MemberImplmember
The local member that we intend to broad cast over and over again
protected Membershipmembership
The membership, used so that we calculate memberships when they arrive or don't arrive
protected static intMAX_PACKET_SIZE
protected intport
The multicast port
protected DatagramPacketreceivePacket
Reuse the receivePacket, no need to create a new one everytime
protected McastServiceImpl.ReceiverThreadreceiver
Thread to listen for pings
protected intrecoveryCounter
nr of times the system has to fail before a recovery is initiated
protected booleanrecoveryEnabled
Add the ability to turn on/off recovery
protected longrecoverySleepTime
The time the recovery thread sleeps between recovery attempts
protected McastServiceImpl.SenderThreadsender
Thread to send pings
protected longsendFrequency
How often to we send out a broadcast saying we are alive, must be smaller than timeToExpiration
protected DatagramPacketsendPacket
Reuse the sendPacket, no need to create a new one everytime
protected MembershipListenerservice
The actual listener, for callback when shits goes down
protected longserviceStartTime
When was the service started
protected MulticastSocketsocket
Socket that we intend to listen to
protected intstartLevel
protected longtimeToExpiration
The time it takes for a member to expire.
Constructor Summary
McastServiceImpl(MemberImpl member, long sendFrequency, long expireTime, int port, InetAddress bind, InetAddress mcastAddress, int ttl, int soTimeout, MembershipListener service)
Create a new mcast service impl
Method Summary
protected voidcheckExpired()
intgetRecoveryCounter()
longgetRecoverySleepTime()
longgetServiceStartTime()
voidinit()
booleanisRecoveryEnabled()
voidreceive()
Receive a datagram packet, locking wait
voidsend(boolean checkexpired)
Send a ping
voidsetRecoveryCounter(int recoveryCounter)
voidsetRecoveryEnabled(boolean recoveryEnabled)
voidsetRecoverySleepTime(long recoverySleepTime)
protected voidsetupSocket()
voidstart(int level)
Start the service
booleanstop(int level)
Stops the service

Field Detail

address

protected InetAddress address
The multicast address

doRunReceiver

protected boolean doRunReceiver

doRunSender

protected boolean doRunSender
Internal flag used for the listen thread that listens to the multicasting socket.

expiredMutex

protected Object expiredMutex

mcastBindAddress

protected InetAddress mcastBindAddress
bind address

mcastSoTimeout

protected int mcastSoTimeout
Read timeout on the mcast socket

mcastTTL

protected int mcastTTL
Time to live for the multicast packets that are being sent out

member

protected MemberImpl member
The local member that we intend to broad cast over and over again

membership

protected Membership membership
The membership, used so that we calculate memberships when they arrive or don't arrive

MAX_PACKET_SIZE

protected static int MAX_PACKET_SIZE

port

protected int port
The multicast port

receivePacket

protected DatagramPacket receivePacket
Reuse the receivePacket, no need to create a new one everytime

receiver

protected McastServiceImpl.ReceiverThread receiver
Thread to listen for pings

recoveryCounter

protected int recoveryCounter
nr of times the system has to fail before a recovery is initiated

recoveryEnabled

protected boolean recoveryEnabled
Add the ability to turn on/off recovery

recoverySleepTime

protected long recoverySleepTime
The time the recovery thread sleeps between recovery attempts

sender

protected McastServiceImpl.SenderThread sender
Thread to send pings

sendFrequency

protected long sendFrequency
How often to we send out a broadcast saying we are alive, must be smaller than timeToExpiration

sendPacket

protected DatagramPacket sendPacket
Reuse the sendPacket, no need to create a new one everytime

service

protected MembershipListener service
The actual listener, for callback when shits goes down

serviceStartTime

protected long serviceStartTime
When was the service started

socket

protected MulticastSocket socket
Socket that we intend to listen to

startLevel

protected int startLevel

timeToExpiration

protected long timeToExpiration
The time it takes for a member to expire.

Constructor Detail

McastServiceImpl

public McastServiceImpl(MemberImpl member, long sendFrequency, long expireTime, int port, InetAddress bind, InetAddress mcastAddress, int ttl, int soTimeout, MembershipListener service)
Create a new mcast service impl

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 service - the callback service

Throws: IOException

Method Detail

checkExpired

protected void checkExpired()

getRecoveryCounter

public int getRecoveryCounter()

getRecoverySleepTime

public long getRecoverySleepTime()

getServiceStartTime

public long getServiceStartTime()

init

public void init()

isRecoveryEnabled

public boolean isRecoveryEnabled()

receive

public void receive()
Receive a datagram packet, locking wait

Throws: IOException

send

public void send(boolean checkexpired)
Send a ping

Throws: Exception

setRecoveryCounter

public void setRecoveryCounter(int recoveryCounter)

setRecoveryEnabled

public void setRecoveryEnabled(boolean recoveryEnabled)

setRecoverySleepTime

public void setRecoverySleepTime(long recoverySleepTime)

setupSocket

protected void setupSocket()

start

public void start(int level)
Start 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

stop

public boolean stop(int level)
Stops the service

Throws: IOException if the service fails to disconnect from the sockets

Copyright © 2000-2011 Apache Software Foundation. All Rights Reserved.