McastServiceImpl (Apache Tomcat 9.0.111 API Documentation)
Description: declaration: package: org.apache.catalina.tribes.membership, class: McastServiceImpl

# 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 final 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 final Object`
  `expiredMutex`
  `protected final boolean`
  `localLoopbackDisabled`
  disable/enable local loopback message
  `protected static final int`
  `MAX_PACKET_SIZE`
  `protected final InetAddress`
  `mcastBindAddress`
  bind address
  `protected int`
  `mcastSoTimeout`
  Read timeout on the mcast socket
  `protected final int`
  `mcastTTL`
  Time to live for the multicast packets that are being sent out
  `protected final MemberImpl`
  `member`
  The local member that we intend to broadcast over and over again
  `protected final MessageListener`
  `msgservice`
  The actual listener for broadcast callbacks
  `protected final int`
  `port`
  The multicast port
  `protected DatagramPacket`
  `receivePacket`
  Reuse the receivePacket, no need to create a new one every time
  `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 final 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 every time
  `protected final MembershipListener`
  `service`
  The actual listener, for callback when stuff goes down
  `protected static final StringManager`
  `sm`
  `protected MulticastSocket`
  `socket`
  Socket that we intend to listen to
  `protected int`
  `startLevel`
  `protected final long`
  `timeToExpiration`
  The time it takes for a member to expire.

  ### Fields inherited from class MembershipProviderBase

  `executor, membership, membershipListener`

- ## Constructor Summary

  Constructors
  Constructor
  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 instance.

- ## Method Summary

  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 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 membership provider.
  `boolean`
  `stop(int level)`
  Stop the membership provider.

  ### Methods inherited from class MembershipProviderBase

  `getMember, getMembers, hasMembers, init, setMembershipListener, setMembershipService`

  ### Methods inherited from class Object

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

- ## Field Details

  - ### 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 MulticastSocket socket
    Socket that we intend to listen to

  - ### member

    protected final MemberImpl member
    The local member that we intend to broadcast over and over again

  - ### address

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

  - ### receivePacket

    protected 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 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 Object 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 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:
      `IOException` - Init error

- ## Method Details

  - ### init

    public void init() throws IOException
    Throws:
      `IOException`

  - ### setupSocket

    protected void setupSocket() throws IOException
    Throws:
      `IOException`

  - ### start

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

    public boolean stop(int level) throws IOException
    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

    public void receive() throws IOException
    Receive a datagram packet, locking wait
    Throws:
      `IOException` - Received failed

  - ### checkExpired

    protected void checkExpired()

  - ### send

    public void send(boolean checkexpired) throws IOException
    Send a ping.
    Parameters:
      `checkexpired` - `true` to check for expiration
    Throws:
      `IOException` - Send error

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