org.apache.catalina.tribes.io

## Class ChannelData

- java.lang.Object
- - org.apache.catalina.tribes.io.ChannelData

All Implemented Interfaces:
  Serializable, 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.

Author:
  Peter Rossbach, Filip Hanik
See Also:
  Serialized Form

### Field Summary

Fields
`static ChannelData[]` `EMPTY_DATA_ARRAY`
`static boolean` `USE_SECURE_RANDOM_FOR_UUID`

### Constructor Summary

Constructors
Constructor and Description
`ChannelData()` 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

Methods
`static String` `bToS(byte[] data)`
`Object` `clone()` Create a shallow clone, only the data gets recreated
`Object` `deepclone()` Complete clone
`boolean` `equals(Object o)` Compares to ChannelData objects, only compares on getUniqueId().equals(o.getUniqueId())
`void` `generateUUID()` Generates a UUID and invokes setUniqueId
`Member` `getAddress()` Returns the source or reply-to address
`static ChannelData` `getDataFromPackage(byte[] b)`
`static ChannelData` `getDataFromPackage(XByteBuffer xbuf)` Deserializes a ChannelData object from a byte array
`byte[]` `getDataPackage()` Serializes the ChannelData object into a byte[] array
`byte[]` `getDataPackage(byte[] data, int offset)`
`int` `getDataPackageLength()`
`XByteBuffer` `getMessage()` returns the byte buffer that contains the actual message payload
`int` `getOptions()` The message options is a 32 bit flag set that triggers interceptors and message behavior.
`long` `getTimestamp()` Timestamp of when the message was created.
`byte[]` `getUniqueId()` Each message must have a globally unique Id.
`int` `hashCode()`
`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
`void` `setMessage(XByteBuffer message)` The byte buffer that contains the actual message payload
`void` `setOptions(int options)` Sets the message options.
`void` `setTimestamp(long timestamp)` Sets the timestamp of this message
`void` `setUniqueId(byte[] uniqueId)`
`String` `toString()`

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

`finalize, getClass, notify, notifyAll, wait, wait, wait`

### Field Detail

#### EMPTY_DATA_ARRAY

    public static final ChannelData[] EMPTY_DATA_ARRAY

#### USE_SECURE_RANDOM_FOR_UUID

    public static volatile boolean USE_SECURE_RANDOM_FOR_UUID

### Constructor Detail

#### ChannelData

    public ChannelData()

Creates an empty channel data with a new unique Id

See Also:
  `ChannelData(boolean)`

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

#### 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:
  Returns the message byte buffer

#### 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` - The message to send.

#### getTimestamp

    public long getTimestamp()

Description copied from interface: `ChannelMessage`
Timestamp of when the message was created.

Specified by:
  `getTimestamp` in interface `ChannelMessage`
Returns:
  Returns the timestamp.

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

#### 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:
  Returns the uniqueId.

#### setUniqueId

    public void setUniqueId(byte[] uniqueId)

Parameters:
  `uniqueId` - The uniqueId to send.

#### 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:
  returns the message options see org.apache.catalina.tribes.Channel#sendMessage(org.apache.catalina.tribes.Member[], java.io.Serializable, int)
See Also:
  `Channel.send(Member[], Serializable, int)`, `ChannelInterceptor.getOptionFlag()`

#### setOptions

    public void setOptions(int options)

Sets the message options.

Specified by:
  `setOptions` in interface `ChannelMessage`
Parameters:
  `options` - the message options
See Also:
  `ChannelMessage.getOptions()`

#### getAddress

    public Member getAddress()

Returns the source or reply-to address

Specified by:
  `getAddress` in interface `ChannelMessage`
Returns:
  Member

#### setAddress

    public void setAddress(Member address)

Sets the source or reply-to address

Specified by:
  `setAddress` in interface `ChannelMessage`
Parameters:
  `address` - Member

#### generateUUID

    public void generateUUID()

Generates a UUID and invokes setUniqueId

#### getDataPackageLength

    public int getDataPackageLength()

#### getDataPackage

    public byte[] getDataPackage()

Serializes the ChannelData object into a byte[] array

Returns:
  byte[]

#### getDataPackage

    public byte[] getDataPackage(byte[] data,
                        int offset)

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

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

Complete clone

Specified by:
  `deepclone` in interface `ChannelMessage`
Returns:
  ClusterData

#### 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:
  `Channel.SEND_OPTIONS_USE_ACK`, `Channel.SEND_OPTIONS_SYNCHRONIZED_ACK`

#### 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:
  `Channel.SEND_OPTIONS_USE_ACK`, `Channel.SEND_OPTIONS_SYNCHRONIZED_ACK`

#### toString

    public String toString()

Overrides:
  `toString` in class `Object`

#### bToS

    public static String bToS(byte[] data)