Class McastServiceImpl

  • public class McastServiceImpl
    extends java.lang.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
    • Field Detail

      • 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 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 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 sendPacket
        Reuse the sendPacket, no need to create a new one every time
      • receivePacket

        protected receivePacket
        Reuse the receivePacket, no need to create a new one every time
      • membership

        protected Membership membership
        The membership, used so that we calculate memberships when they arrive or don't arrive
      • 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
      • 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 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
      • executor

        protected final java.util.concurrent.ExecutorService executor
        Dont interrupt the sender/receiver thread, but pass off to an executor
      • 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,
                                int ttl,
                                int soTimeout,
                                MembershipListener service,
                                MessageListener msgservice,
                                boolean localLoopbackDisabled)
        Create a new mcast service instance.
        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: - Init error
    • Method Detail

      • init

        public void init()
      • setupSocket

        protected void setupSocket()
      • start

        public void start​(int level)
        Start the service
        level - 1 starts the receiver, level 2 starts the sender
        Throws: - if the service fails to start
        java.lang.IllegalStateException - if the service is already started
      • stop

        public boolean stop​(int level)
        Stops the service.
        level - Stop status
        true if the stop is complete
        Throws: - if the service fails to disconnect from the sockets
      • receive

        public void receive()
        Receive a datagram packet, locking wait
        Throws: - Received failed
      • checkExpired

        protected void checkExpired()
      • send

        public void send​(boolean checkexpired)
        Send a ping.
        checkexpired - true to check for expiration
        Throws: - Send error
      • send

        public void send​(boolean checkexpired,
      • 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)