Package org.apache.catalina.tribes.membership

## Class McastService

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

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

      public class McastService
      extends java.lang.Object
      implements MembershipService, MembershipListener, 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` |
    `protected static Member[]` | `EMPTY_MEMBERS` | Return all the members
    `protected McastServiceImpl` | `impl` | A handle to the actual low level implementation
    `protected MembershipListener` | `listener` | A membership listener delegate (should be the cluster :)
    `protected MemberImpl` | `localMember` | The local member
    `protected MessageListener` | `msglistener` | A message listener delegate for broadcasts
    `protected byte[]` | `payload` |
    `protected java.util.Properties` | `properties` | The implementation specific properties
    `protected static StringManager` | `sm` | The string manager for this package.

    - ### Fields inherited from interface org.apache.catalina.tribes.MembershipService

      `MBR_RX, MBR_TX`

  - ### Constructor Summary

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

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `boolean` | `accept​(ChannelMessage msg)` |
    `void` | `broadcast​(ChannelMessage message)` | Broadcasts a message to all members.
    `Member` | `findMemberByName​(java.lang.String name)` | Return the member by name
    `java.lang.String` | `getAddress()` |
    `java.lang.String` | `getBind()` |
    `Channel` | `getChannel()` | Return the channel that is related to this MembershipService
    `byte[]` | `getDomain()` |
    `long` | `getDropTime()` |
    `long` | `getFrequency()` |
    `boolean` | `getLocalLoopbackDisabled()` |
    `Member` | `getLocalMember​(boolean alive)` | Get the local member.
    `java.lang.String` | `getLocalMemberName()` |
    `Member` | `getMember​(Member mbr)` | Retrieve the specified member from the membership.
    `Member[]` | `getMembers()` |
    `java.lang.String[]` | `getMembersByName()` | Return all the members by name
    `byte[]` | `getPayload()` |
    `int` | `getPort()` |
    `java.util.Properties` | `getProperties()`
    `int` | `getRecoveryCounter()` |
    `boolean` | `getRecoveryEnabled()` |
    `long` | `getRecoverySleepTime()` |
    `int` | `getSoTimeout()` |
    `int` | `getTtl()` |
    `boolean` | `hasMembers()` | has members?
    `protected void` | `hasProperty​(java.util.Properties properties, java.lang.String name)` | Check if a required property is available.
    `static void` | `main​(java.lang.String[] args)` | Simple test program
    `void` | `memberAdded​(Member member)` | A member was added to the group
    `void` | `memberDisappeared​(Member member)` | Callback from the impl when a new member has been received
    `void` | `messageReceived​(ChannelMessage msg)` | Receive a message from the IO components in the Channel stack
    `void` | `removeMembershipListener()` | Remove the membership listener
    `void` | `removeMessageListener()` |
    `void` | `setAddress​(java.lang.String addr)` |
    `void` | `setBind​(java.lang.String bindaddr)` |
    `void` | `setChannel​(Channel channel)` | Set the channel that is related to this MembershipService
    `protected void` | `setDefaults​(java.util.Properties properties)` |
    `void` | `setDomain​(byte[] domain)` |
    `void` | `setDomain​(java.lang.String domain)` |
    `void` | `setDropTime​(long time)` |
    `void` | `setFrequency​(long time)` |
    `void` | `setLocalLoopbackDisabled​(boolean localLoopbackDisabled)` |
    `void` | `setLocalMemberProperties​(java.lang.String listenHost, int listenPort, int securePort, int udpPort)` | Sets the local member properties for broadcasting.
    `void` | `setMcastBindAddress​(java.lang.String bindaddr)` |
    `void` | `setMcastDropTime​(long time)` |
    `void` | `setMembershipListener​(MembershipListener listener)` | Add a membership listener, this version only supports one listener per service, so calling this method twice will result in only the second listener being active.
    `void` | `setMessageListener​(MessageListener listener)` |
    `void` | `setPayload​(byte[] payload)` | Set a payload to be broadcasted with each membership broadcast.
    `void` | `setPort​(int port)` |
    `void` | `setProperties​(java.util.Properties properties)` | Sets the properties for the membership service.
    `void` | `setRecoveryCounter​(int recoveryCounter)` |
    `void` | `setRecoveryEnabled​(boolean recoveryEnabled)` |
    `void` | `setRecoverySleepTime​(long recoverySleepTime)` |
    `void` | `setSoTimeout​(int mcastSoTimeout)` |
    `void` | `setTtl​(int mcastTTL)` |
    `void` | `start()` | Start broadcasting and listening to membership pings
    `void` | `start​(int level)` | Starts the membership service.
    `void` | `stop​(int svc)` | Stop broadcasting and listening to membership pings

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

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

- - ### Field Detail

    - #### sm

          protected static final StringManager sm

      The string manager for this package.

    - #### properties

          protected java.util.Properties properties

      The implementation specific properties

    - #### impl

          protected McastServiceImpl impl

      A handle to the actual low level implementation

    - #### listener

          protected volatile MembershipListener listener

      A membership listener delegate (should be the cluster :)

    - #### msglistener

          protected MessageListener msglistener

      A message listener delegate for broadcasts

    - #### localMember

          protected MemberImpl localMember

      The local member

    - #### payload

          protected byte[] payload

    - #### domain

          protected byte[] domain

    - #### EMPTY_MEMBERS

          protected static final Member[] EMPTY_MEMBERS

      Return all the members

  - ### Constructor Detail

    - #### McastService

          public McastService()

      Create a membership service.

  - ### Method Detail

    - #### setProperties

          public void setProperties​(java.util.Properties properties)

      Sets the properties for the membership service.
      Specified by:
        `setProperties` in interface `MembershipService`
      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:
        `java.lang.IllegalArgumentException` - if a property is missing.

    - #### getProperties

          public java.util.Properties getProperties()

      Specified by:
        `getProperties` in interface `McastServiceMBean`
      Specified by:
        `getProperties` in interface `MembershipService`
      Returns:
        the properties for the configuration used.

    - #### getLocalMemberName

          public java.lang.String getLocalMemberName()

      Specified by:
        `getLocalMemberName` in interface `McastServiceMBean`
      Returns:
        the local member name

    - #### getLocalMember

          public Member getLocalMember​(boolean alive)

      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​(java.lang.String listenHost,
                                               int listenPort,
                                               int securePort,
                                               int udpPort)

      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​(java.lang.String addr)

    - #### getAddress

          public java.lang.String getAddress()

      Specified by:
        `getAddress` in interface `McastServiceMBean`

    - #### setMcastBindAddress

          public void setMcastBindAddress​(java.lang.String bindaddr)

    - #### setBind

          public void setBind​(java.lang.String bindaddr)

    - #### getBind

          public java.lang.String getBind()

      Specified by:
        `getBind` in interface `McastServiceMBean`

    - #### setPort

          public void setPort​(int port)

    - #### setRecoveryCounter

          public void setRecoveryCounter​(int recoveryCounter)

    - #### getRecoveryCounter

          public int getRecoveryCounter()

      Specified by:
        `getRecoveryCounter` in interface `McastServiceMBean`

    - #### setRecoveryEnabled

          public void setRecoveryEnabled​(boolean recoveryEnabled)

    - #### getRecoveryEnabled

          public boolean getRecoveryEnabled()

      Specified by:
        `getRecoveryEnabled` in interface `McastServiceMBean`

    - #### setRecoverySleepTime

          public void setRecoverySleepTime​(long recoverySleepTime)

    - #### getRecoverySleepTime

          public long getRecoverySleepTime()

      Specified by:
        `getRecoverySleepTime` in interface `McastServiceMBean`

    - #### setLocalLoopbackDisabled

          public void setLocalLoopbackDisabled​(boolean localLoopbackDisabled)

    - #### getLocalLoopbackDisabled

          public boolean getLocalLoopbackDisabled()

      Specified by:
        `getLocalLoopbackDisabled` in interface `McastServiceMBean`

    - #### getPort

          public int getPort()

      Specified by:
        `getPort` in interface `McastServiceMBean`

    - #### setFrequency

          public void setFrequency​(long time)

    - #### getFrequency

          public long getFrequency()

      Specified by:
        `getFrequency` in interface `McastServiceMBean`

    - #### setMcastDropTime

          public void setMcastDropTime​(long time)

    - #### setDropTime

          public void setDropTime​(long time)

    - #### getDropTime

          public long getDropTime()

      Specified by:
        `getDropTime` in interface `McastServiceMBean`

    - #### hasProperty

          protected void hasProperty​(java.util.Properties properties,
                                     java.lang.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()
                     throws java.lang.Exception

      Start broadcasting and listening to membership pings
      Specified by:
        `start` in interface `MembershipService`
      Throws:
        `java.lang.Exception` - if a IO error occurs

    - #### start

          public void start​(int level)
                     throws java.lang.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 broad casting the server
      Throws:
        `java.lang.Exception` - if the service fails to start.
        `java.lang.IllegalArgumentException` - if the level is incorrect.

    - #### 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 broad casting the server

    - #### getMembersByName

          public java.lang.String[] getMembersByName()

      Return all the members by name
      Specified by:
        `getMembersByName` in interface `McastServiceMBean`
      Specified by:
        `getMembersByName` in interface `MembershipService`
      Returns:
        all members by name

    - #### findMemberByName

          public Member findMemberByName​(java.lang.String name)

      Return the member by name
      Specified by:
        `findMemberByName` in interface `McastServiceMBean`
      Specified by:
        `findMemberByName` in interface `MembershipService`
      Parameters:
        `name` - The member name
      Returns:
        the member

    - #### hasMembers

          public boolean hasMembers()

      has members?
      Specified by:
        `hasMembers` in interface `McastServiceMBean`
      Specified by:
        `hasMembers` in interface `MembershipService`
      Returns:
        true if the the group contains members

    - #### getMember

          public Member getMember​(Member mbr)

      Description copied from interface: `MembershipService`
      Retrieve the specified member from the membership.
      Specified by:
        `getMember` in interface `MembershipService`
      Parameters:
        `mbr` - The member to retrieve
      Returns:
        the member

    - #### getMembers

          public Member[] getMembers()

      Specified by:
        `getMembers` in interface `MembershipService`
      Returns:
        a list of all the members in the cluster.

    - #### setMembershipListener

          public void setMembershipListener​(MembershipListener listener)

      Add a membership listener, this version only supports one listener per service, so calling this method twice will result in only the second listener being active.
      Specified by:
        `setMembershipListener` in interface `MembershipService`
      Parameters:
        `listener` - The listener

    - #### setMessageListener

          public void setMessageListener​(MessageListener listener)

    - #### removeMessageListener

          public void removeMessageListener()

    - #### removeMembershipListener

          public void removeMembershipListener()

      Remove the membership listener
      Specified by:
        `removeMembershipListener` in interface `MembershipService`

    - #### memberAdded

          public void memberAdded​(Member member)

      Description copied from interface: `MembershipListener`
      A member was added to the group
      Specified by:
        `memberAdded` in interface `MembershipListener`
      Parameters:
        `member` - Member - the member that was added

    - #### memberDisappeared

          public void memberDisappeared​(Member member)

      Callback from the impl when a new member has been received
      Specified by:
        `memberDisappeared` in interface `MembershipListener`
      Parameters:
        `member` - The member
      See Also:
        `Member.SHUTDOWN_PAYLOAD`

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

    - #### accept

          public boolean accept​(ChannelMessage msg)

      Specified by:
        `accept` in interface `MessageListener`

    - #### 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`
      Parameters:
        `message` - The message to broadcast
      Throws:
        `ChannelException` - Message broadcast failed

    - #### getSoTimeout

          public int getSoTimeout()

      Specified by:
        `getSoTimeout` in interface `McastServiceMBean`

    - #### setSoTimeout

          public void setSoTimeout​(int mcastSoTimeout)

    - #### getTtl

          public int getTtl()

      Specified by:
        `getTtl` in interface `McastServiceMBean`

    - #### getPayload

          public byte[] getPayload()

    - #### getDomain

          public byte[] getDomain()

      Specified by:
        `getDomain` in interface `McastServiceMBean`

    - #### setTtl

          public void setTtl​(int mcastTTL)

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

      Specified by:
        `setDomain` in interface `MembershipService`

    - #### setDomain

          public void setDomain​(java.lang.String domain)

    - #### getChannel

          public Channel getChannel()

      Description copied from interface: `MembershipService`
      Return the channel that is related to this MembershipService
      Specified by:
        `getChannel` in interface `MembershipService`
      Returns:
        Channel

    - #### setChannel

          public void setChannel​(Channel channel)

      Description copied from interface: `MembershipService`
      Set the channel that is related to this MembershipService
      Specified by:
        `setChannel` in interface `MembershipService`
      Parameters:
        `channel` - The channel

    - #### setDefaults

          protected void setDefaults​(java.util.Properties properties)

    - #### main

          public static void main​(java.lang.String[] args)
                           throws java.lang.Exception

      Simple test program
      Parameters:
        `args` - Command-line arguments
      Throws:
        `java.lang.Exception` - If an error occurs