McastServiceImpl (Apache Tomcat 7.0.103 API Documentation)

org.apache.catalina.tribes.membership

## Class McastServiceImpl

- java.lang.Object
- - org.apache.catalina.tribes.membership.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

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `class` | `McastServiceImpl.ReceiverThread`
    `protected static class` | `McastServiceImpl.RecoveryThread`
    `class` | `McastServiceImpl.SenderThread`

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected InetAddress` | `address` The multicast address
    `protected boolean` | `doRunReceiver`
    `protected boolean` | `doRunSender` Internal flag used for the listen thread that listens to the multicasting socket.
    `protected ExecutorService` | `executor` Dont interrupt the sender/receiver thread, but pass off to an executor
    `protected Object` | `expiredMutex`
    `protected boolean` | `localLoopbackDisabled` disable/enable local loopback message
    `protected static int` | `MAX_PACKET_SIZE`
    `protected InetAddress` | `mcastBindAddress` bind address
    `protected int` | `mcastSoTimeout` Read timeout on the mcast socket
    `protected int` | `mcastTTL` Time to live for the multicast packets that are being sent out
    `protected MemberImpl` | `member` The local member that we intend to broad cast over and over again
    `protected Membership` | `membership` The membership, used so that we calculate memberships when they arrive or don't arrive
    `protected MessageListener` | `msgservice` The actual listener for broadcast callbacks
    `protected int` | `port` The multicast port
    `protected DatagramPacket` | `receivePacket` Reuse the receivePacket, no need to create a new one everytime
    `protected McastServiceImpl.ReceiverThread` | `receiver` Thread to listen for pings
    `protected int` | `recoveryCounter` nr of times the system has to fail before a recovery is initiated
    `protected boolean` | `recoveryEnabled` Add the ability to turn on/off recovery
    `protected long` | `recoverySleepTime` The time the recovery thread sleeps between recovery attempts
    `protected McastServiceImpl.SenderThread` | `sender` Thread to send pings
    `protected long` | `sendFrequency` How often to we send out a broadcast saying we are alive, must be smaller than timeToExpiration
    `protected DatagramPacket` | `sendPacket` Reuse the sendPacket, no need to create a new one everytime
    `protected MembershipListener` | `service` The actual listener, for callback when stuff goes down
    `protected MulticastSocket` | `socket` Socket that we intend to listen to
    `protected int` | `startLevel`
    `protected long` | `timeToExpiration` The time it takes for a member to expire.

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `McastServiceImpl(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 impl

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected void` | `checkExpired()`
    `Channel` | `getChannel()`
    `int` | `getRecoveryCounter()`
    `long` | `getRecoverySleepTime()`
    `long` | `getServiceStartTime()`
    `void` | `init()`
    `boolean` | `isRecoveryEnabled()`
    `void` | `receive()` Receive a datagram packet, locking wait
    `void` | `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` | `setupSocket()`
    `void` | `start(int level)` Start the service
    `boolean` | `stop(int level)` Stops the service

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### MAX_PACKET_SIZE

          protected static int MAX_PACKET_SIZE

    - #### 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 MulticastSocket socket

      Socket that we intend to listen to

    - #### member

          protected MemberImpl member

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

    - #### address

          protected InetAddress address

      The multicast address

    - #### port

          protected int port

      The multicast port

    - #### timeToExpiration

          protected long timeToExpiration

      The time it takes for a member to expire.

    - #### 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

    - #### receivePacket

          protected DatagramPacket receivePacket

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

    - #### membership

          protected Membership membership

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

    - #### service

          protected MembershipListener service

      The actual listener, for callback when stuff goes down

    - #### msgservice

          protected 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 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 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

    - #### executor

          protected ExecutorService executor

      Dont interrupt the sender/receiver thread, but pass off to an executor

    - #### localLoopbackDisabled

          protected boolean localLoopbackDisabled

      disable/enable local loopback message

    - #### expiredMutex

          protected final Object expiredMutex

  - ### Constructor Detail

    - #### 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 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
        `localLoopbackDisabled` - - disable loopbackMode
      Throws:
        `IOException`

  - ### Method Detail

    - #### init

          public void init()
                    throws IOException

      Throws:
        `IOException`

    - #### setupSocket

          protected void setupSocket()
                              throws IOException

      Throws:
        `IOException`

    - #### start

          public void start(int level)
                     throws IOException

      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)
                       throws IOException

      Stops the service
      Throws:
        `IOException` - if the service fails to disconnect from the sockets

    - #### receive

          public void receive()
                       throws IOException

      Receive a datagram packet, locking wait
      Throws:
        `IOException`

    - #### checkExpired

          protected void checkExpired()

    - #### send

          public void send(boolean checkexpired)
                    throws IOException

      Send a ping
      Throws:
        `IOException`

    - #### send

          public void send(boolean checkexpired,
                  DatagramPacket packet)
                    throws IOException

      Throws:
        `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)

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