ChannelInterceptor (Apache Tomcat 11.0.25 API Documentation)
Description: declaration: package: org.apache.catalina.tribes, interface: ChannelInterceptor

# Interface ChannelInterceptor

All Superinterfaces:
  `Heartbeat, MembershipListener`

All Known Implementing Classes:
  `ChannelCoordinator, ChannelInterceptorBase, DomainFilterInterceptor, EncryptInterceptor, FragmentationInterceptor, GroupChannel, GzipInterceptor, MessageDispatchInterceptor, NonBlockingCoordinator, OrderInterceptor, SimpleCoordinator, StaticMembershipInterceptor, TcpFailureDetector, TcpPingInterceptor, ThroughputInterceptor, TwoPhaseCommitInterceptor`

public interface ChannelInterceptor extends MembershipListener, Heartbeat
A ChannelInterceptor is an interceptor that intercepts messages and membership messages in the channel stack. This allows interceptors to modify the message or perform other actions when a message is sent or received.

Interceptors are tied together in a linked list.

See Also:
  - `ChannelInterceptorBase`

- ## Nested Class Summary

  Nested Classes
  Modifier and Type
  Interface
  Description
  `static interface`
  `ChannelInterceptor.InterceptorEvent`
  Event fired by an interceptor.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `fireInterceptorEvent(ChannelInterceptor.InterceptorEvent event)`
  Fire an event.
  `Channel`
  `getChannel()`
  Return the channel that is related to this interceptor
  `Member`
  `getLocalMember(boolean incAliveTime)`
  Intercepts the `Channel.getLocalMember(boolean)` method
  `Member`
  `getMember(Member mbr)`
  Intercepts the `Channel.getMember(Member)` method
  `Member[]`
  `getMembers()`
  Intercepts the `Channel.getMembers()` method
  `ChannelInterceptor`
  `getNext()`
  Retrieve the next interceptor in the list
  `int`
  `getOptionFlag()`
  An interceptor can react to a message based on a set bit on the message options.
  `ChannelInterceptor`
  `getPrevious()`
  Retrieve the previous interceptor in the list
  `boolean`
  `hasMembers()`
  Intercepts the `Channel.hasMembers()` method
  `void`
  `heartbeat()`
  The `heartbeat()` method gets invoked periodically to allow interceptors to clean up resources, time out object and perform actions that are unrelated to sending/receiving data.
  `void`
  `messageReceived(ChannelMessage data)`
  The `messageReceived` is invoked when a message is received.
  `void`
  `sendMessage(Member[] destination, ChannelMessage msg, InterceptorPayload payload)`
  The `sendMessage` method is called when a message is being sent to one more destinations.
  `void`
  `setChannel(Channel channel)`
  Set the channel that is related to this interceptor
  `void`
  `setNext(ChannelInterceptor next)`
  Set the next interceptor in the list of interceptors
  `void`
  `setOptionFlag(int flag)`
  Sets the option flag
  `void`
  `setPrevious(ChannelInterceptor previous)`
  Set the previous interceptor in the list
  `void`
  `start(int svc)`
  Starts up the channel.
  `void`
  `stop(int svc)`
  Shuts down the channel.

  ### Methods inherited from interface MembershipListener

  `memberAdded, memberDisappeared`

- ## Method Details

  - ### getOptionFlag

    int getOptionFlag()
    An interceptor can react to a message based on a set bit on the message options. When a message is sent, the options can be retrieved from ChannelMessage.getOptions() and if the bit is set, this interceptor will react to it.

    A simple evaluation if an interceptor should react to the message would be:
    `boolean react = (getOptionFlag() == (getOptionFlag() & ChannelMessage.getOptions()));`
    The default option is 0, meaning there is no way for the application to trigger the interceptor. The interceptor itself will decide.

    Returns:
      int
    See Also:
      - `ChannelMessage.getOptions()`

  - ### setOptionFlag

    void setOptionFlag(int flag)
    Sets the option flag
    Parameters:
      `flag` - int
    See Also:
      - `getOptionFlag()`

  - ### setNext

    void setNext(ChannelInterceptor next)
    Set the next interceptor in the list of interceptors
    Parameters:
      `next` - ChannelInterceptor

  - ### getNext

    ChannelInterceptor getNext()
    Retrieve the next interceptor in the list
    Returns:
      ChannelInterceptor - returns the next interceptor in the list or null if no more interceptors exist

  - ### setPrevious

    void setPrevious(ChannelInterceptor previous)
    Set the previous interceptor in the list
    Parameters:
      `previous` - ChannelInterceptor

  - ### getPrevious

    ChannelInterceptor getPrevious()
    Retrieve the previous interceptor in the list
    Returns:
      ChannelInterceptor - returns the previous interceptor in the list or null if no more interceptors exist

  - ### sendMessage

    void sendMessage(Member[] destination, ChannelMessage msg, InterceptorPayload payload) throws ChannelException
    The `sendMessage` method is called when a message is being sent to one more destinations. The interceptor can modify any of the parameters and then pass on the message down the stack by invoking `getNext().sendMessage(destination,msg,payload)`.

    Alternatively the interceptor can stop the message from being sent by not invoking `getNext().sendMessage(destination,msg,payload)`.

    If the message is to be sent asynchronous the application can be notified of completion and errors by passing in an error handler attached to a payload object.

    The ChannelMessage.getAddress contains Channel.getLocalMember, and can be overwritten to simulate a message sent from another node.

    Parameters:
      `destination` - Member[] - the destination for this message
      `msg` - ChannelMessage - the message to be sent
      `payload` - InterceptorPayload - the payload, carrying an error handler and future useful data, can be null
    Throws:
      `ChannelException` - if a serialization error happens.
    See Also:
      - `ErrorHandler`
      - `InterceptorPayload`

  - ### messageReceived

    void messageReceived(ChannelMessage data)
    The `messageReceived` is invoked when a message is received. `ChannelMessage.getAddress()` is the sender, or the reply-to address if it has been overwritten.
    Parameters:
      `data` - ChannelMessage

  - ### heartbeat

    void heartbeat()
    The `heartbeat()` method gets invoked periodically to allow interceptors to clean up resources, time out object and perform actions that are unrelated to sending/receiving data.
    Specified by:
      `heartbeat` in interface `Heartbeat`

  - ### hasMembers

    boolean hasMembers()
    Intercepts the `Channel.hasMembers()` method
    Returns:
      boolean - if the channel has members in its membership group
    See Also:
      - `Channel.hasMembers()`

  - ### getMembers

    Member[] getMembers()
    Intercepts the `Channel.getMembers()` method
    Returns:
      the members
    See Also:
      - `Channel.getMembers()`

  - ### getLocalMember

    Member getLocalMember(boolean incAliveTime)
    Intercepts the `Channel.getLocalMember(boolean)` method
    Parameters:
      `incAliveTime` - boolean
    Returns:
      the member that represents this node
    See Also:
      - `Channel.getLocalMember(boolean)`

  - ### getMember

    Member getMember(Member mbr)
    Intercepts the `Channel.getMember(Member)` method
    Parameters:
      `mbr` - Member
    Returns:
      Member - the actual member information, including stay alive
    See Also:
      - `Channel.getMember(Member)`

  - ### start

    void start(int svc) throws ChannelException
    Starts up the channel. This can be called multiple times for individual services to start The svc parameter can be the logical or value of any constants
    Parameters:
      `svc` - one of:
      - Channel.DEFAULT - will start all services
      - Channel.MBR_RX_SEQ - starts the membership receiver
      - Channel.MBR_TX_SEQ - starts the membership broadcaster
      - Channel.SND_TX_SEQ - starts the replication transmitter
      - Channel.SND_RX_SEQ - starts the replication receiver
    Throws:
      `ChannelException` - if a startup error occurs or the service is already started.
    See Also:
      - `Channel`

  - ### stop

    void stop(int svc) throws ChannelException
    Shuts down the channel. This can be called multiple times for individual services to shut down. The svc parameter can be the logical or value of any constants
    Parameters:
      `svc` - one of:
      - Channel.DEFAULT - will shut down all services
      - Channel.MBR_RX_SEQ - stops the membership receiver
      - Channel.MBR_TX_SEQ - stops the membership broadcaster
      - Channel.SND_TX_SEQ - stops the replication transmitter
      - Channel.SND_RX_SEQ - stops the replication receiver
    Throws:
      `ChannelException` - if a shutdown error occurs or the service is already stopped.
    See Also:
      - `Channel`

  - ### fireInterceptorEvent

    void fireInterceptorEvent(ChannelInterceptor.InterceptorEvent event)
    Fire an event.
    Parameters:
      `event` - the event

  - ### getChannel

    Channel getChannel()
    Return the channel that is related to this interceptor
    Returns:
      Channel

  - ### setChannel

    void setChannel(Channel channel)
    Set the channel that is related to this interceptor
    Parameters:
      `channel` - The channel