Package org.apache.catalina.tribes.io
Class ChannelData
- java.lang.Object
-
- org.apache.catalina.tribes.io.ChannelData
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.Cloneable,ChannelMessage
public class ChannelData extends java.lang.Object implements ChannelMessage
TheChannelDataobject 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:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static ChannelData[]EMPTY_DATA_ARRAYEmpty array to avoid reinstantiating arrays.static booleanUSE_SECURE_RANDOM_FOR_UUIDFlag to control whether secure random is used for UUID generation.
-
Constructor Summary
Constructors Constructor Description ChannelData()Creates an empty channel data with a new unique IdChannelData(boolean generateUUID)Create an empty channel data objectChannelData(byte[] uniqueId, XByteBuffer message, long timestamp)Creates a new channel data object with data
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static java.lang.StringbToS(byte[] data)Converts a byte array to a string representation.ChannelDataclone()Create a shallow clone, only the data gets recreatedjava.lang.Objectdeepclone()Deep clone, all fields MUST get clonedbooleanequals(java.lang.Object o)Compares to ChannelData objects, only compares on getUniqueId().equals(o.getUniqueId())voidgenerateUUID()Generates a UUID and invokes setUniqueIdMembergetAddress()Get the address that this message originated from.static ChannelDatagetDataFromPackage(byte[] b)Deserializes a ChannelData object from a byte array.static ChannelDatagetDataFromPackage(XByteBuffer xbuf)Deserializes a ChannelData object from a byte arraybyte[]getDataPackage()Serializes the ChannelData object into a byte[] arraybyte[]getDataPackage(byte[] data, int offset)Serializes the ChannelData object into the specified byte array at the given offset.intgetDataPackageLength()Returns the length of the data package when serialized.XByteBuffergetMessage()returns the byte buffer that contains the actual message payloadintgetOptions()The message options is a 32 bit flag set that triggers interceptors and message behavior.longgetTimestamp()Timestamp of when the message was created.byte[]getUniqueId()Each message must have a globally unique Id. interceptors heavily depend on this id for message processinginthashCode()static booleansendAckAsync(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 processedstatic booleansendAckSync(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 processedvoidsetAddress(Member address)Sets the source or reply-to address of this messagevoidsetMessage(XByteBuffer message)The byte buffer that contains the actual message payloadvoidsetOptions(int options)sets the option bits for this messagevoidsetTimestamp(long timestamp)Sets the timestamp of this message.voidsetUniqueId(byte[] uniqueId)Sets the unique identifier for this message.java.lang.StringtoString()
-
-
-
Field Detail
-
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 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 idmessage- - message datatimestamp- - message timestamp
-
-
Method Detail
-
getMessage
public XByteBuffer getMessage()
Description copied from interface:ChannelMessagereturns the byte buffer that contains the actual message payload- Specified by:
getMessagein interfaceChannelMessage- Returns:
- XByteBuffer
-
setMessage
public void setMessage(XByteBuffer message)
Description copied from interface:ChannelMessageThe byte buffer that contains the actual message payload- Specified by:
setMessagein interfaceChannelMessage- Parameters:
message- XByteBuffer
-
getTimestamp
public long getTimestamp()
Description copied from interface:ChannelMessageTimestamp of when the message was created.- Specified by:
getTimestampin interfaceChannelMessage- Returns:
- long timestamp in milliseconds
-
setTimestamp
public void setTimestamp(long timestamp)
Description copied from interface:ChannelMessageSets the timestamp of this message.- Specified by:
setTimestampin interfaceChannelMessage- Parameters:
timestamp- The timestamp
-
getUniqueId
public byte[] getUniqueId()
Description copied from interface:ChannelMessageEach message must have a globally unique Id. interceptors heavily depend on this id for message processing- Specified by:
getUniqueIdin interfaceChannelMessage- 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:ChannelMessageThe message options is a 32 bit flag set that triggers interceptors and message behavior.- Specified by:
getOptionsin interfaceChannelMessage- Returns:
- int - the option bits set for this message
- See Also:
Channel.send(Member[], Serializable, int),ChannelInterceptor.getOptionFlag()
-
setOptions
public void setOptions(int options)
Description copied from interface:ChannelMessagesets the option bits for this message- Specified by:
setOptionsin interfaceChannelMessage- Parameters:
options- int- See Also:
ChannelMessage.getOptions()
-
getAddress
public Member getAddress()
Description copied from interface:ChannelMessageGet the address that this message originated from. Almost alwaysChannel.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:
getAddressin interfaceChannelMessage- Returns:
- the source or reply-to address of this message
-
setAddress
public void setAddress(Member address)
Description copied from interface:ChannelMessageSets the source or reply-to address of this message- Specified by:
setAddressin interfaceChannelMessage- 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 intooffset- 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:
hashCodein classjava.lang.Object
-
equals
public boolean equals(java.lang.Object o)
Compares to ChannelData objects, only compares on getUniqueId().equals(o.getUniqueId())- Overrides:
equalsin classjava.lang.Object- Parameters:
o- Object- Returns:
- boolean
-
clone
public ChannelData clone()
Create a shallow clone, only the data gets recreated- Specified by:
clonein interfaceChannelMessage- Overrides:
clonein classjava.lang.Object- Returns:
- ClusterData
-
deepclone
public java.lang.Object deepclone()
Description copied from interface:ChannelMessageDeep clone, all fields MUST get cloned- Specified by:
deepclonein interfaceChannelMessage- 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:
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 java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
bToS
public static java.lang.String bToS(byte[] data)
Converts a byte array to a string representation.- Parameters:
data- The byte array- Returns:
- the string representation
-
-