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

# Class McastService

java.lang.Object
org.apache.catalina.tribes.membership.MembershipServiceBase
org.apache.catalina.tribes.membership.McastService

All Implemented Interfaces:
  `McastServiceMBean, MembershipListener, MembershipService, MessageListener`

public class McastService extends MembershipServiceBase implements MessageListener, McastServiceMBean
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.

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `protected byte[]`
  `domain`
  The domain for multicast messages.
  `protected McastServiceImpl`
  `impl`
  A handle to the actual low level implementation
  `protected MemberImpl`
  `localMember`
  The local member
  `protected MessageListener`
  `msglistener`
  A message listener delegate for broadcasts
  `protected byte[]`
  `payload`
  The payload for multicast messages.
  `protected static final StringManager`
  `sm`
  The string manager for this package.

  ### Fields inherited from class MembershipServiceBase

  `channel, listener, properties`

  ### Fields inherited from interface MembershipService

  `MBR_RX, MBR_TX`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `McastService()`
  Create a membership service.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `boolean`
  `accept(ChannelMessage msg)`
  Allows skipping processing of the specified message.
  `void`
  `broadcast(ChannelMessage message)`
  Broadcasts a message to all members.
  `String`
  `getAddress()`
  Get the multicast address.
  `String`
  `getBind()`
  Get the bind address.
  `byte[]`
  `getDomain()`
  Get the domain.
  `long`
  `getDropTime()`
  Get the drop time.
  `long`
  `getFrequency()`
  Get the heartbeat frequency.
  `boolean`
  `getLocalLoopbackDisabled()`
  Get whether local loopback is disabled.
  `Member`
  `getLocalMember(boolean alive)`
  Get the local member.
  `String`
  `getLocalMemberName()`
  Get the local member name.
  `MembershipProvider`
  `getMembershipProvider()`
  Get the MembershipProvider
  `byte[]`
  `getPayload()`
  Get the payload.
  `int`
  `getPort()`
  Get the multicast port.
  `int`
  `getRecoveryCounter()`
  Get the recovery counter.
  `boolean`
  `getRecoveryEnabled()`
  Get whether recovery is enabled.
  `long`
  `getRecoverySleepTime()`
  Get the recovery sleep time.
  `int`
  `getSoTimeout()`
  Get the socket timeout.
  `int`
  `getTtl()`
  Get the TTL.
  `protected void`
  `hasProperty(Properties properties, String name)`
  Check if a required property is available.
  `static void`
  `main(String[] args)`
  Simple test program
  `void`
  `messageReceived(ChannelMessage msg)`
  Receive a message from the IO components in the Channel stack
  `void`
  `removeMessageListener()`
  Remove the message listener.
  `void`
  `setAddress(String addr)`
  Set the multicast address.
  `void`
  `setBind(String bindaddr)`
  Set the bind address.
  `protected void`
  `setDefaults(Properties properties)`
  Set default property values.
  `void`
  `setDomain(byte[] domain)`
  Set the associated domain.
  `void`
  `setDomain(String domain)`
  Set the domain from a string.
  `void`
  `setDropTime(long time)`
  Set the member drop time.
  `void`
  `setFrequency(long time)`
  Set the heartbeat frequency.
  `void`
  `setLocalLoopbackDisabled(boolean localLoopbackDisabled)`
  Set whether local loopback is disabled.
  `void`
  `setLocalMemberProperties(String listenHost, int listenPort, int securePort, int udpPort)`
  Sets the local member properties for broadcasting.
  `void`
  `setMcastBindAddress(String bindaddr)`
  Set the multicast bind address.
  `void`
  `setMcastDropTime(long time)`
  Set the multicast drop time.
  `void`
  `setMessageListener(MessageListener listener)`
  Set the message listener.
  `void`
  `setPayload(byte[] payload)`
  Set a payload to be broadcasted with each membership broadcast.
  `void`
  `setPort(int port)`
  Set the multicast port.
  `void`
  `setProperties(Properties properties)`
  Sets the properties for the membership service.
  `void`
  `setRecoveryCounter(int recoveryCounter)`
  Set the recovery counter.
  `void`
  `setRecoveryEnabled(boolean recoveryEnabled)`
  Set whether recovery is enabled.
  `void`
  `setRecoverySleepTime(long recoverySleepTime)`
  Set the recovery sleep time.
  `void`
  `setSoTimeout(int mcastSoTimeout)`
  Set the socket timeout.
  `void`
  `setTtl(int mcastTTL)`
  Set the TTL.
  `void`
  `start(int level)`
  Starts the membership service.
  `void`
  `stop(int svc)`
  Stop broadcasting and listening to membership pings

  ### Methods inherited from class MembershipServiceBase

  `findMemberByName, getChannel, getMember, getMembers, getMembersByName, getProperties, hasMembers, memberAdded, memberDisappeared, removeMembershipListener, setChannel, setMembershipListener, start`

  ### Methods inherited from class Object

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

  ### Methods inherited from interface McastServiceMBean

  `findMemberByName, getMembersByName, getProperties, hasMembers`

- ## Field Details

  - ### sm

    protected static final StringManager sm
    The string manager for this package.

  - ### impl

    protected McastServiceImpl impl
    A handle to the actual low level implementation

  - ### msglistener

    protected MessageListener msglistener
    A message listener delegate for broadcasts

  - ### localMember

    protected MemberImpl localMember
    The local member

  - ### payload

    protected byte[] payload
    The payload for multicast messages.

  - ### domain

    protected byte[] domain
    The domain for multicast messages.

- ## Constructor Details

  - ### McastService

    public McastService()
    Create a membership service.

- ## Method Details

  - ### setProperties

    public void setProperties(Properties properties)
    Sets the properties for the membership service.
    Specified by:
      `setProperties` in interface `MembershipService`
    Overrides:
      `setProperties` in class `MembershipServiceBase`
    Parameters:
      `properties` -
      All are required
      1. mcastPort - the port to listen to
      2. mcastAddress - the mcast group address
      4. bindAddress - the bind address if any - only one that can be null
      5. memberDropTime - the time a member is gone before it is considered gone.
      6. mcastFrequency - the frequency of sending messages
      7. tcpListenPort - the port this member listens to
      8. tcpListenHost - the bind address of this member
    Throws:
      `IllegalArgumentException` - if a property is missing.

  - ### getLocalMemberName

    public String getLocalMemberName()
    Description copied from interface: `McastServiceMBean`
    Get the local member name.
    Specified by:
      `getLocalMemberName` in interface `McastServiceMBean`
    Returns:
      the local member name

  - ### getLocalMember

    public Member getLocalMember(boolean alive)
    Description copied from interface: `MembershipService`
    Get the local member.
    Specified by:
      `getLocalMember` in interface `MembershipService`
    Parameters:
      `alive` - `true` to set the alive time on the local member
    Returns:
      the member object that defines this member

  - ### setLocalMemberProperties

    public void setLocalMemberProperties(String listenHost, int listenPort, int securePort, int udpPort)
    Description copied from interface: `MembershipService`
    Sets the local member properties for broadcasting.
    Specified by:
      `setLocalMemberProperties` in interface `MembershipService`
    Parameters:
      `listenHost` - Listen to host
      `listenPort` - Listen to port
      `securePort` - Use a secure port
      `udpPort` - Use UDP

  - ### setAddress

    public void setAddress(String addr)
    Set the multicast address.
    Parameters:
      `addr` - the address

  - ### getAddress

    public String getAddress()
    Description copied from interface: `McastServiceMBean`
    Get the multicast address.
    Specified by:
      `getAddress` in interface `McastServiceMBean`
    Returns:
      the address

  - ### setMcastBindAddress

    public void setMcastBindAddress(String bindaddr)
    Set the multicast bind address.
    Parameters:
      `bindaddr` - the bind address

  - ### setBind

    public void setBind(String bindaddr)
    Set the bind address.
    Parameters:
      `bindaddr` - the bind address

  - ### getBind

    public String getBind()
    Description copied from interface: `McastServiceMBean`
    Get the bind address.
    Specified by:
      `getBind` in interface `McastServiceMBean`
    Returns:
      the bind address

  - ### setPort

    public void setPort(int port)
    Set the multicast port.
    Parameters:
      `port` - the port

  - ### setRecoveryCounter

    public void setRecoveryCounter(int recoveryCounter)
    Set the recovery counter.
    Parameters:
      `recoveryCounter` - the recovery counter

  - ### getRecoveryCounter

    public int getRecoveryCounter()
    Description copied from interface: `McastServiceMBean`
    Get the recovery counter.
    Specified by:
      `getRecoveryCounter` in interface `McastServiceMBean`
    Returns:
      the recovery counter

  - ### setRecoveryEnabled

    public void setRecoveryEnabled(boolean recoveryEnabled)
    Set whether recovery is enabled.
    Parameters:
      `recoveryEnabled` - whether recovery is enabled

  - ### getRecoveryEnabled

    public boolean getRecoveryEnabled()
    Description copied from interface: `McastServiceMBean`
    Get whether recovery is enabled.
    Specified by:
      `getRecoveryEnabled` in interface `McastServiceMBean`
    Returns:
      whether recovery is enabled

  - ### setRecoverySleepTime

    public void setRecoverySleepTime(long recoverySleepTime)
    Set the recovery sleep time.
    Parameters:
      `recoverySleepTime` - the recovery sleep time

  - ### getRecoverySleepTime

    public long getRecoverySleepTime()
    Description copied from interface: `McastServiceMBean`
    Get the recovery sleep time.
    Specified by:
      `getRecoverySleepTime` in interface `McastServiceMBean`
    Returns:
      the recovery sleep time

  - ### setLocalLoopbackDisabled

    public void setLocalLoopbackDisabled(boolean localLoopbackDisabled)
    Set whether local loopback is disabled.
    Parameters:
      `localLoopbackDisabled` - whether local loopback is disabled

  - ### getLocalLoopbackDisabled

    public boolean getLocalLoopbackDisabled()
    Description copied from interface: `McastServiceMBean`
    Get whether local loopback is disabled.
    Specified by:
      `getLocalLoopbackDisabled` in interface `McastServiceMBean`
    Returns:
      whether local loopback is disabled

  - ### getPort

    public int getPort()
    Description copied from interface: `McastServiceMBean`
    Get the multicast port.
    Specified by:
      `getPort` in interface `McastServiceMBean`
    Returns:
      the port

  - ### setFrequency

    public void setFrequency(long time)
    Set the heartbeat frequency.
    Parameters:
      `time` - the frequency in milliseconds

  - ### getFrequency

    public long getFrequency()
    Description copied from interface: `McastServiceMBean`
    Get the heartbeat frequency.
    Specified by:
      `getFrequency` in interface `McastServiceMBean`
    Returns:
      the frequency

  - ### setMcastDropTime

    public void setMcastDropTime(long time)
    Set the multicast drop time.
    Parameters:
      `time` - the drop time in milliseconds

  - ### setDropTime

    public void setDropTime(long time)
    Set the member drop time.
    Parameters:
      `time` - the drop time in milliseconds

  - ### getDropTime

    public long getDropTime()
    Description copied from interface: `McastServiceMBean`
    Get the drop time.
    Specified by:
      `getDropTime` in interface `McastServiceMBean`
    Returns:
      the drop time

  - ### hasProperty

    protected void hasProperty(Properties properties, String name)
    Check if a required property is available.
    Parameters:
      `properties` - The set of properties
      `name` - The property to check for

  - ### start

    public void start(int level) throws Exception
    Description copied from interface: `MembershipService`
    Starts the membership service. If a membership listeners is added the listener will start to receive membership events.
    Specified by:
      `start` in interface `MembershipService`
    Parameters:
      `level` - - level MBR_RX starts listening for members, level MBR_TX starts broadcasting the server
    Throws:
      `Exception` - if the service fails to start.

  - ### stop

    public void stop(int svc)
    Stop broadcasting and listening to membership pings
    Specified by:
      `stop` in interface `MembershipService`
    Parameters:
      `svc` - - level MBR_RX stops listening for members, level MBR_TX stops broadcasting the server

  - ### setMessageListener

    public void setMessageListener(MessageListener listener)
    Set the message listener.
    Parameters:
      `listener` - the listener

  - ### removeMessageListener

    public void removeMessageListener()
    Remove the message listener.

  - ### messageReceived

    public void messageReceived(ChannelMessage msg)
    Description copied from interface: `MessageListener`
    Receive a message from the IO components in the Channel stack
    Specified by:
      `messageReceived` in interface `MessageListener`
    Parameters:
      `msg` - the message

  - ### accept

    public boolean accept(ChannelMessage msg)
    Description copied from interface: `MessageListener`
    Allows skipping processing of the specified message.
    Specified by:
      `accept` in interface `MessageListener`
    Parameters:
      `msg` - the message
    Returns:
      `true` if the message will be processed

  - ### broadcast

    public void broadcast(ChannelMessage message) throws ChannelException
    Description copied from interface: `MembershipService`
    Broadcasts a message to all members.
    Specified by:
      `broadcast` in interface `MembershipService`
    Overrides:
      `broadcast` in class `MembershipServiceBase`
    Parameters:
      `message` - The message to broadcast
    Throws:
      `ChannelException` - Message broadcast failed

  - ### getSoTimeout

    public int getSoTimeout()
    Description copied from interface: `McastServiceMBean`
    Get the socket timeout.
    Specified by:
      `getSoTimeout` in interface `McastServiceMBean`
    Returns:
      the socket timeout

  - ### setSoTimeout

    public void setSoTimeout(int mcastSoTimeout)
    Set the socket timeout.
    Parameters:
      `mcastSoTimeout` - the timeout in milliseconds

  - ### getTtl

    public int getTtl()
    Description copied from interface: `McastServiceMBean`
    Get the TTL.
    Specified by:
      `getTtl` in interface `McastServiceMBean`
    Returns:
      the TTL

  - ### getPayload

    public byte[] getPayload()
    Get the payload.
    Returns:
      the payload

  - ### getDomain

    public byte[] getDomain()
    Description copied from interface: `McastServiceMBean`
    Get the domain.
    Specified by:
      `getDomain` in interface `McastServiceMBean`
    Returns:
      the domain

  - ### setTtl

    public void setTtl(int mcastTTL)
    Set the TTL.
    Parameters:
      `mcastTTL` - the TTL value

  - ### setPayload

    public void setPayload(byte[] payload)
    Description copied from interface: `MembershipService`
    Set a payload to be broadcasted with each membership broadcast.
    Specified by:
      `setPayload` in interface `MembershipService`
    Parameters:
      `payload` - byte[]

  - ### setDomain

    public void setDomain(byte[] domain)
    Description copied from interface: `MembershipService`
    Set the associated domain.
    Specified by:
      `setDomain` in interface `MembershipService`
    Parameters:
      `domain` - the domain

  - ### setDomain

    public void setDomain(String domain)
    Set the domain from a string.
    Parameters:
      `domain` - the domain string

  - ### getMembershipProvider

    public MembershipProvider getMembershipProvider()
    Description copied from interface: `MembershipService`
    Get the MembershipProvider
    Specified by:
      `getMembershipProvider` in interface `MembershipService`
    Returns:
      MembershipProvider

  - ### setDefaults

    protected void setDefaults(Properties properties)
    Set default property values.
    Parameters:
      `properties` - the properties

  - ### main

    public static void main(String[] args) throws Exception
    Simple test program
    Parameters:
      `args` - Command-line arguments
    Throws:
      `Exception` - If an error occurs