CloudMembershipProvider (Apache Tomcat 11.0.24 API Documentation)
Description: declaration: package: org.apache.catalina.tribes.membership.cloud, class: CloudMembershipProvider

# Class CloudMembershipProvider

java.lang.Object
org.apache.catalina.tribes.membership.MembershipProviderBase
org.apache.catalina.tribes.membership.cloud.CloudMembershipProvider

All Implemented Interfaces:
  `ChannelListener, Heartbeat, MembershipProvider`

Direct Known Subclasses:
  `DNSMembershipProvider, KubernetesMembershipProvider`

public abstract class CloudMembershipProvider extends MembershipProviderBase implements Heartbeat, ChannelListener
Abstract base class for cloud-based membership providers.

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `protected int`
  `connectionTimeout`
  Connection timeout in milliseconds.
  `protected static final String`
  `CUSTOM_ENV_PREFIX`
  Prefix for custom environment variables.
  `protected long`
  `expirationTime`
  Member expiration time in milliseconds.
  `protected Map<String,String>`
  `headers`
  HTTP headers for cloud API requests.
  `protected String`
  `localIp`
  The local IP address.
  `protected int`
  `port`
  The local port number.
  `protected int`
  `readTimeout`
  Read timeout in milliseconds.
  `protected static final StringManager`
  `sm`
  String manager for this class.
  `protected Instant`
  `startTime`
  The time when this provider started.
  `protected StreamProvider`
  `streamProvider`
  The provider for cloud API streams.
  `protected String`
  `url`
  The URL for the cloud membership service.

  ### Fields inherited from class MembershipProviderBase

  `executor, membership, membershipListener, service`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `CloudMembershipProvider()`
  Default constructor.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `boolean`
  `accept(Serializable msg, Member sender)`
  Invoked by the channel to determine if the listener will process this message or not.
  `protected static byte[]`
  `digest(byte[] input)`
  Thread safe MD5 digest.
  `protected abstract Member[]`
  `fetchMembers()`
  Fetch current cluster members from the cloud orchestration.
  `protected static String`
  `getEnv(String... keys)`
  Get value of environment variable.
  `protected String`
  `getNamespace()`
  Get the Kubernetes namespace, or "tomcat" if the Kubernetes environment variable cannot be found (with a warning log about the missing namespace).
  `void`
  `heartbeat()`
  Heartbeat invocation for resources cleanup etc
  `void`
  `init(Properties properties)`
  Initialize the membership provider with the specified configuration.
  `void`
  `messageReceived(Serializable msg, Member sender)`
  Receive a message from the channel
  `void`
  `start(int level)`
  Start the membership provider.
  `boolean`
  `stop(int level)`
  Stop the membership provider.
  `protected void`
  `updateMember(Member member, boolean add)`
  Add or remove specified member.

  ### Methods inherited from class MembershipProviderBase

  `getMember, getMembers, hasMembers, setMembershipListener, setMembershipService`

  ### Methods inherited from class Object

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

- ## Field Details

  - ### sm

    protected static final StringManager sm
    String manager for this class.

  - ### CUSTOM_ENV_PREFIX

    protected static final String CUSTOM_ENV_PREFIX
    Prefix for custom environment variables.
    See Also:
      - Constant Field Values

  - ### url

    protected String url
    The URL for the cloud membership service.

  - ### streamProvider

    protected StreamProvider streamProvider
    The provider for cloud API streams.

  - ### connectionTimeout

    protected int connectionTimeout
    Connection timeout in milliseconds.

  - ### readTimeout

    protected int readTimeout
    Read timeout in milliseconds.

  - ### startTime

    protected Instant startTime
    The time when this provider started.

  - ### headers

    protected Map<String,String> headers
    HTTP headers for cloud API requests.

  - ### localIp

    protected String localIp
    The local IP address.

  - ### port

    protected int port
    The local port number.

  - ### expirationTime

    protected long expirationTime
    Member expiration time in milliseconds.

- ## Constructor Details

  - ### CloudMembershipProvider

    public CloudMembershipProvider()
    Default constructor.

- ## Method Details

  - ### digest

    protected static byte[] digest(byte[] input)
    Thread safe MD5 digest.
    Parameters:
      `input` - The bytes to digest
    Returns:
      The MD5 digest for the given input

  - ### getEnv

    protected static String getEnv(String... keys)
    Get value of environment variable.
    Parameters:
      `keys` - the environment variables
    Returns:
      the env variables values, or null if not found

  - ### getNamespace

    protected String getNamespace()
    Get the Kubernetes namespace, or "tomcat" if the Kubernetes environment variable cannot be found (with a warning log about the missing namespace).
    Returns:
      the namespace

  - ### init

    public void init(Properties properties) throws IOException
    Description copied from interface: `MembershipProvider`
    Initialize the membership provider with the specified configuration.
    Specified by:
      `init` in interface `MembershipProvider`
    Overrides:
      `init` in class `MembershipProviderBase`
    Parameters:
      `properties` - configuration
    Throws:
      `IOException`

  - ### start

    public void start(int level) throws Exception
    Description copied from interface: `MembershipProvider`
    Start the membership provider.
    Specified by:
      `start` in interface `MembershipProvider`
    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:
      `Exception` - if an error occurs

  - ### stop

    public boolean stop(int level) throws Exception
    Description copied from interface: `MembershipProvider`
    Stop the membership provider.
    Specified by:
      `stop` in interface `MembershipProvider`
    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:
      `Exception` - if an error occurs

  - ### heartbeat

    public void heartbeat()
    Description copied from interface: `Heartbeat`
    Heartbeat invocation for resources cleanup etc
    Specified by:
      `heartbeat` in interface `Heartbeat`

  - ### fetchMembers

    protected abstract Member[] fetchMembers()
    Fetch current cluster members from the cloud orchestration.
    Returns:
      the member array

  - ### updateMember

    protected void updateMember(Member member, boolean add)
    Add or remove specified member.
    Parameters:
      `member` - the member to add
      `add` - true if the member is added, false otherwise

  - ### messageReceived

    public void messageReceived(Serializable msg, Member sender)
    Description copied from interface: `ChannelListener`
    Receive a message from the channel
    Specified by:
      `messageReceived` in interface `ChannelListener`
    Parameters:
      `msg` - Serializable
      `sender` - - the source of the message

  - ### accept

    public boolean accept(Serializable msg, Member sender)
    Description copied from interface: `ChannelListener`
    Invoked by the channel to determine if the listener will process this message or not.
    Specified by:
      `accept` in interface `ChannelListener`
    Parameters:
      `msg` - Serializable
      `sender` - Member
    Returns:
      boolean