Class ChannelData

java.lang.Object
org.apache.catalina.tribes.io.ChannelData
All Implemented Interfaces:
Serializable, Cloneable, ChannelMessage

public class ChannelData extends Object implements ChannelMessage
The ChannelData object is used to transfer a message through the channel interceptor stack and eventually out on a transport to be sent to another node. While the message is being processed by the different interceptors, the message data can be manipulated as each interceptor seems appropriate.
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final ChannelData[]
    Empty array to avoid reinstantiating arrays.
    static boolean
    Flag to control whether secure random is used for UUID generation.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates an empty channel data with a new unique Id
    ChannelData(boolean generateUUID)
    Create an empty channel data object
    ChannelData(byte[] uniqueId, XByteBuffer message, long timestamp)
    Creates a new channel data object with data
  • Method Summary

    Modifier and Type
    Method
    Description
    static String
    bToS(byte[] data)
    Converts a byte array to a string representation.
    Create a shallow clone, only the data gets recreated
    Deep clone, all fields MUST get cloned
    boolean
    Compares to ChannelData objects, only compares on getUniqueId().equals(o.getUniqueId())
    void
    Generates a UUID and invokes setUniqueId
    Get the address that this message originated from.
    Deserializes a ChannelData object from a byte array.
    Deserializes a ChannelData object from a byte array
    byte[]
    Serializes the ChannelData object into a byte[] array
    byte[]
    getDataPackage(byte[] data, int offset)
    Serializes the ChannelData object into the specified byte array at the given offset.
    int
    Returns the length of the data package when serialized.
    returns the byte buffer that contains the actual message payload
    int
    The message options is a 32 bit flag set that triggers interceptors and message behavior.
    long
    Timestamp of when the message was created.
    byte[]
    Each message must have a globally unique Id. interceptors heavily depend on this id for message processing
    int
     
    static boolean
    sendAckAsync(int options)
    Utility method, returns true if the options flag indicates that an ack is to be sent after the message has been received but not yet processed
    static boolean
    sendAckSync(int options)
    Utility method, returns true if the options flag indicates that an ack is to be sent after the message has been received and processed
    void
    setAddress(Member address)
    Sets the source or reply-to address of this message
    void
    The byte buffer that contains the actual message payload
    void
    setOptions(int options)
    sets the option bits for this message
    void
    setTimestamp(long timestamp)
    Sets the timestamp of this message.
    void
    setUniqueId(byte[] uniqueId)
    Sets the unique identifier for this message.
     

    Methods inherited from class Object

    finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

    • EMPTY_DATA_ARRAY

      public static final ChannelData[] EMPTY_DATA_ARRAY
      Empty array to avoid reinstantiating arrays.
    • USE_SECURE_RANDOM_FOR_UUID

      public static volatile boolean USE_SECURE_RANDOM_FOR_UUID
      Flag to control whether secure random is used for UUID generation.
  • Constructor Details

    • ChannelData

      public ChannelData()
      Creates an empty channel data with a new unique Id
      See Also:
    • ChannelData

      public ChannelData(boolean generateUUID)
      Create an empty channel data object
      Parameters:
      generateUUID - boolean - if true, a unique Id will be generated
    • ChannelData

      public ChannelData(byte[] uniqueId, XByteBuffer message, long timestamp)
      Creates a new channel data object with data
      Parameters:
      uniqueId - - unique message id
      message - - message data
      timestamp - - message timestamp
  • Method Details

    • getMessage

      public XByteBuffer getMessage()
      Description copied from interface: ChannelMessage
      returns the byte buffer that contains the actual message payload
      Specified by:
      getMessage in interface ChannelMessage
      Returns:
      XByteBuffer
    • setMessage

      public void setMessage(XByteBuffer message)
      Description copied from interface: ChannelMessage
      The byte buffer that contains the actual message payload
      Specified by:
      setMessage in interface ChannelMessage
      Parameters:
      message - XByteBuffer
    • getTimestamp

      public long getTimestamp()
      Description copied from interface: ChannelMessage
      Timestamp of when the message was created.
      Specified by:
      getTimestamp in interface ChannelMessage
      Returns:
      long timestamp in milliseconds
    • setTimestamp

      public void setTimestamp(long timestamp)
      Description copied from interface: ChannelMessage
      Sets the timestamp of this message.
      Specified by:
      setTimestamp in interface ChannelMessage
      Parameters:
      timestamp - The timestamp
    • getUniqueId

      public byte[] getUniqueId()
      Description copied from interface: ChannelMessage
      Each message must have a globally unique Id. interceptors heavily depend on this id for message processing
      Specified by:
      getUniqueId in interface ChannelMessage
      Returns:
      byte
    • setUniqueId

      public void setUniqueId(byte[] uniqueId)
      Sets the unique identifier for this message.
      Parameters:
      uniqueId - The unique identifier
    • getOptions

      public int getOptions()
      Description copied from interface: ChannelMessage
      The message options is a 32 bit flag set that triggers interceptors and message behavior.
      Specified by:
      getOptions in interface ChannelMessage
      Returns:
      int - the option bits set for this message
      See Also:
    • setOptions

      public void setOptions(int options)
      Description copied from interface: ChannelMessage
      sets the option bits for this message
      Specified by:
      setOptions in interface ChannelMessage
      Parameters:
      options - int
      See Also:
    • getAddress

      public Member getAddress()
      Description copied from interface: ChannelMessage
      Get the address that this message originated from. Almost always Channel.getLocalMember(boolean). This would be set to a different address if the message was being relayed from a host other than the one that originally sent it.
      Specified by:
      getAddress in interface ChannelMessage
      Returns:
      the source or reply-to address of this message
    • setAddress

      public void setAddress(Member address)
      Description copied from interface: ChannelMessage
      Sets the source or reply-to address of this message
      Specified by:
      setAddress in interface ChannelMessage
      Parameters:
      address - Member
    • generateUUID

      public void generateUUID()
      Generates a UUID and invokes setUniqueId
    • getDataPackageLength

      public int getDataPackageLength()
      Returns the length of the data package when serialized.
      Returns:
      the data package length
    • getDataPackage

      public byte[] getDataPackage()
      Serializes the ChannelData object into a byte[] array
      Returns:
      byte[]
    • getDataPackage

      public byte[] getDataPackage(byte[] data, int offset)
      Serializes the ChannelData object into the specified byte array at the given offset.
      Parameters:
      data - The byte array to serialize into
      offset - The offset in the byte array
      Returns:
      the byte array
    • getDataFromPackage

      public static ChannelData getDataFromPackage(XByteBuffer xbuf)
      Deserializes a ChannelData object from a byte array
      Parameters:
      xbuf - byte[]
      Returns:
      ChannelData
    • getDataFromPackage

      public static ChannelData getDataFromPackage(byte[] b)
      Deserializes a ChannelData object from a byte array.
      Parameters:
      b - The byte array to deserialize from
      Returns:
      the ChannelData object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object o)
      Compares to ChannelData objects, only compares on getUniqueId().equals(o.getUniqueId())
      Overrides:
      equals in class Object
      Parameters:
      o - Object
      Returns:
      boolean
    • clone

      public ChannelData clone()
      Create a shallow clone, only the data gets recreated
      Specified by:
      clone in interface ChannelMessage
      Overrides:
      clone in class Object
      Returns:
      ClusterData
    • deepclone

      public Object deepclone()
      Description copied from interface: ChannelMessage
      Deep clone, all fields MUST get cloned
      Specified by:
      deepclone in interface ChannelMessage
      Returns:
      ChannelMessage
    • sendAckSync

      public static boolean sendAckSync(int options)
      Utility method, returns true if the options flag indicates that an ack is to be sent after the message has been received and processed
      Parameters:
      options - int - the options for the message
      Returns:
      boolean
      See Also:
    • sendAckAsync

      public static boolean sendAckAsync(int options)
      Utility method, returns true if the options flag indicates that an ack is to be sent after the message has been received but not yet processed
      Parameters:
      options - int - the options for the message
      Returns:
      boolean
      See Also:
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • bToS

      public static String bToS(byte[] data)
      Converts a byte array to a string representation.
      Parameters:
      data - The byte array
      Returns:
      the string representation