# Class CloudMembershipService

java.lang.Object
org.apache.catalina.tribes.membership.MembershipServiceBase
org.apache.catalina.tribes.membership.cloud.CloudMembershipService

All Implemented Interfaces:
  `CloudMembershipServiceMBean, MembershipListener, MembershipService`

public class CloudMembershipService extends MembershipServiceBase implements CloudMembershipServiceMBean
A `MembershipService` that uses Kubernetes API(default) or DNS to retrieve the members of a cluster.

The default implementation of the MembershipProvider component is the `KubernetesMembershipProvider`. The MembershipProvider can be configured by the `membershipProviderClassName` property. Possible shortcuts are `kubernetes` and `dns`. For dns look at the `DNSMembershipProvider`.

Configuration example

`server.xml`

    <Server ...

      <Service ...

        <Engine ...

          <Host ...

            <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster">
              <Channel className="org.apache.catalina.tribes.group.GroupChannel">
                <Membership className="org.apache.catalina.tribes.membership.cloud.CloudMembershipService"/>
              </Channel>
            </Cluster>
            ...

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `protected static final byte[]`
  `INITIAL_ID`
  Initial unique identifier for the local member.
  `static final String`
  `MEMBERSHIP_PROVIDER_CLASS_NAME`
  Property name for the membership provider class.
  `protected static final StringManager`
  `sm`
  String manager for this class.

  ### Fields inherited from class MembershipServiceBase

  `channel, listener, properties`

  ### Fields inherited from interface MembershipService

  `MBR_RX, MBR_TX`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `CloudMembershipService()`
  Returns the default constructor for CloudMembershipService.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `int`
  `getConnectTimeout()`
  Returns the connection timeout in milliseconds.
  `long`
  `getExpirationTime()`
  Returns the member expiration time in milliseconds.
  `Member`
  `getLocalMember(boolean incAliveTime)`
  Get the local member.
  `MembershipProvider`
  `getMembershipProvider()`
  Get the MembershipProvider
  `String`
  `getMembershipProviderClassName()`
  Return the membership provider class.
  `Object`
  `getProperty(String name)`
  Return a property.
  `int`
  `getReadTimeout()`
  Returns the read timeout in milliseconds.
  `void`
  `setConnectTimeout(int connectTimeout)`
  Set the connection timeout in milliseconds.
  `void`
  `setDomain(byte[] domain)`
  Set the associated domain.
  `void`
  `setExpirationTime(long expirationTime)`
  Set the member expiration time in milliseconds.
  `void`
  `setLocalMemberProperties(String listenHost, int listenPort, int securePort, int udpPort)`
  Sets the local member properties for broadcasting.
  `void`
  `setMembershipProvider(MembershipProvider memberProvider)`
  Set the membership provider.
  `void`
  `setMembershipProviderClassName(String membershipProviderClassName)`
  Set the membership provider class.
  `void`
  `setPayload(byte[] payload)`
  Set a payload to be broadcasted with each membership broadcast.
  `boolean`
  `setProperty(String name, String value)`
  Set a property.
  `void`
  `setReadTimeout(int readTimeout)`
  Set the read timeout in milliseconds.
  `void`
  `start(int level)`
  Starts the membership service.
  `void`
  `stop(int level)`
  Stops the membership service.

  ### Methods inherited from class MembershipServiceBase

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

  ### Methods inherited from class Object

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

  ### Methods inherited from interface CloudMembershipServiceMBean

  `findMemberByName, getMembersByName, getProperties, hasMembers`

- ## Field Details

  - ### sm

    protected static final StringManager sm
    String manager for this class.

  - ### MEMBERSHIP_PROVIDER_CLASS_NAME

    public static final String MEMBERSHIP_PROVIDER_CLASS_NAME
    Property name for the membership provider class.
    See Also:
      - Constant Field Values

  - ### INITIAL_ID

    protected static final byte[] INITIAL_ID
    Initial unique identifier for the local member.

- ## Constructor Details

  - ### CloudMembershipService

    public CloudMembershipService()
    Returns the default constructor for CloudMembershipService.

- ## Method Details

  - ### getProperty

    public Object getProperty(String name)
    Return a property.
    Parameters:
      `name` - the property name
    Returns:
      the property value

  - ### setProperty

    public boolean setProperty(String name, String value)
    Set a property.
    Parameters:
      `name` - the property name
      `value` - the property value
    Returns:
      `true` if the property was successfully set

  - ### getMembershipProviderClassName

    public String getMembershipProviderClassName()
    Return the membership provider class.
    Returns:
      the classname

  - ### setMembershipProviderClassName

    public void setMembershipProviderClassName(String membershipProviderClassName)
    Set the membership provider class.
    Parameters:
      `membershipProviderClassName` - the class name

  - ### 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 level)
    Description copied from interface: `MembershipService`
    Stops the membership service. If a membership listeners is added the listener will start to receive membership events.
    Specified by:
      `stop` in interface `MembershipService`
    Parameters:
      `level` - - level MBR_RX stops listening for members, level MBR_TX stops broadcasting the server

  - ### getLocalMember

    public Member getLocalMember(boolean incAliveTime)
    Description copied from interface: `MembershipService`
    Get the local member.
    Specified by:
      `getLocalMember` in interface `MembershipService`
    Parameters:
      `incAliveTime` - `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

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

  - ### getMembershipProvider

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

  - ### setMembershipProvider

    public void setMembershipProvider(MembershipProvider memberProvider)
    Set the membership provider.
    Parameters:
      `memberProvider` - the membership provider

  - ### getConnectTimeout

    public int getConnectTimeout()
    Description copied from interface: `CloudMembershipServiceMBean`
    Returns the connection timeout in milliseconds.
    Specified by:
      `getConnectTimeout` in interface `CloudMembershipServiceMBean`
    Returns:
      the connection timeout

  - ### setConnectTimeout

    public void setConnectTimeout(int connectTimeout)
    Set the connection timeout in milliseconds.
    Parameters:
      `connectTimeout` - the connection timeout

  - ### getReadTimeout

    public int getReadTimeout()
    Description copied from interface: `CloudMembershipServiceMBean`
    Returns the read timeout in milliseconds.
    Specified by:
      `getReadTimeout` in interface `CloudMembershipServiceMBean`
    Returns:
      the read timeout

  - ### setReadTimeout

    public void setReadTimeout(int readTimeout)
    Set the read timeout in milliseconds.
    Parameters:
      `readTimeout` - the read timeout

  - ### getExpirationTime

    public long getExpirationTime()
    Description copied from interface: `CloudMembershipServiceMBean`
    Returns the member expiration time in milliseconds.
    Specified by:
      `getExpirationTime` in interface `CloudMembershipServiceMBean`
    Returns:
      the expiration time

  - ### setExpirationTime

    public void setExpirationTime(long expirationTime)
    Set the member expiration time in milliseconds.
    Parameters:
      `expirationTime` - the expiration time