Package de.hybris.platform.cluster
Class RawMessage
java.lang.Object
de.hybris.platform.cluster.RawMessage
- All Implemented Interfaces:
Serializable
Broadcast message class which contains of a header and the content. The header includes the version of this message
class, the cluster island ID, the dynamic node ID, the message number, the kind and the message part number with
overal message part count (mostly 1 of 1).
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe size of the header of this message object. -
Constructor Summary
ConstructorsModifierConstructorDescriptionRawMessage(byte[] binaryMessageBytes) Creates a message object from the given byte array.RawMessage(byte[] binaryMessageBytes, int offset) Same asRawMessage(byte[])but from the given byte array the offset (starting part) is ignored.RawMessage(byte[] binaryMessageBytes, int offset, int length) Creates a message object by the given byte array (which includes the header).RawMessage(int kind) Creates an empty message object of a certain kind.RawMessage(int kind, byte[] data) Creates a message object of a certain kind and with the given data.protectedRawMessage(RawMessage original, int numberOfPackets, int currentPacketNumber, int offset, int length) Constructor used for message splitting. -
Method Summary
Modifier and TypeMethodDescriptionlongintReturn the current packet number which is never greater thangetNumberOfPackets().byte[]getData()longCluster island PK + dynamic node ID is unique for identifying a single node in several clusters.intgetKind()The kind of this RawMessage.Returns the message key which is an unique identifier for all messages in all clustersintCluster island PK + dynamic node ID + message number is unique for identifying a single message in several clusters with many nodes.intIndicates if thisRawMessageis a splitted message (value > 1) or not.intReturns the version of the RawMessage header.join(Collection<RawMessage> messageparts) Joins the current RawMessage (this) with the given list of RawMessages into a new joined RawMessage.booleanmatches(int version, long clusterisland) TODO apidocbooleanmatches(RawMessage other) TODO apidocbooleanmustSplit(int packetsize) Returnstrueif the resulting RawMessage (data+header) exceed the given packet size.voidsetBroadcastMethod(String broadcastMethod) voidsetPacketSplitInfo(int currentPacketNumber, int numberOfPackets) Sets the header information when the message is splitted into several parts.voidsetReceiverTransportData(InetAddress remoteAdress) TODO apidocvoidsetRemoteAddress(InetAddress remoteAddress) voidsetSenderTransportData(int version, long clusterIsland, long dynamicNodeID, int messageNumber) Sets the important header informations for this message.split(int packetSize) Splits the current RawMessage (this) into several RawMessages which are the same size or less (including the header) as the given packet size.byte[]toString()[broadcastMethod://remoteAddress|ver:version|clusterislandid-dynamicnodeid-< /b> messageid| kind|packetnummerofpackets (content: contentlength bytes)]
-
Field Details
-
HEADER_SIZE
public static final int HEADER_SIZEThe size of the header of this message object.version cluster island id dynamic node id message number kind message part number message part count 4 byte 8 byte 8 byte 4 byte 4 byte 4 byte 4 byte - See Also:
-
-
Constructor Details
-
RawMessage
protected RawMessage(RawMessage original, int numberOfPackets, int currentPacketNumber, int offset, int length) Constructor used for message splitting. The header of the original message is used for this messages header but current packet number and number of packets is replaced by the given parameters. A subset of the original data is copied into this message by using the offset (starting point) and the length.- Parameters:
original- the original message object. Contains all necessary datas.numberOfPackets- the new number of packetscurrentPacketNumber- the new current packet numberoffset- the starting point for copying the original data into this objectlength- the length of the data which is copied into this object
-
RawMessage
public RawMessage(int kind) Creates an empty message object of a certain kind.- Parameters:
kind- the kind of the message.
-
RawMessage
public RawMessage(int kind, byte[] data) Creates a message object of a certain kind and with the given data. The data will be directly set as messages data.- Parameters:
kind- the kind of the message.data- the data content
-
RawMessage
public RawMessage(byte[] binaryMessageBytes) Creates a message object from the given byte array. This parameter must include a valid message header!- Parameters:
binaryMessageBytes- the byte array which includes the header and the content
-
RawMessage
public RawMessage(byte[] binaryMessageBytes, int offset) Same asRawMessage(byte[])but from the given byte array the offset (starting part) is ignored.- Parameters:
binaryMessageBytes- the byte array which includes the header and the contentoffset- the starting point
-
RawMessage
public RawMessage(byte[] binaryMessageBytes, int offset, int length) Creates a message object by the given byte array (which includes the header). The header must be at the offset point and with the From the offset a sub array with the given length is used for creating this message object. The length must be the same size as the header size (creating message object without data) or larger (creating message object with data).- Parameters:
binaryMessageBytes- a byte array which contains a message objectoffset- start point of the message object in the byte arraylength- the length of the message object in the byte array, starting at the offset- Throws:
IllegalArgumentException- if length or offset is negative and if ayyay is smaller than offset+length
-
-
Method Details
-
setSenderTransportData
public void setSenderTransportData(int version, long clusterIsland, long dynamicNodeID, int messageNumber) Sets the important header informations for this message.- Parameters:
version- the version of the messageclusterIsland- the cluster island IDdynamicNodeID- the dynamic node IDmessageNumber- the message number
-
setPacketSplitInfo
public void setPacketSplitInfo(int currentPacketNumber, int numberOfPackets) Sets the header information when the message is splitted into several parts.- Parameters:
currentPacketNumber- the current packet number, mustn't be negative and less or equal as the number of packets. Default value is 1.numberOfPackets- the number of packets, mustn't be negative. Default value is 1.
-
setReceiverTransportData
TODO apidoc- Parameters:
remoteAdress-
-
getVersion
public int getVersion()Returns the version of the RawMessage header. If this int is displayed in hexadecimal code the current platform version becomes visible. SeeDefaultBroadcastService.CUR_VERSIONint value hexadecimal view string view 67174656 4010100 4.1.1.0 - Returns:
- the version of this header.
-
getClusterIslandPK
public long getClusterIslandPK()- Returns:
- the unique cluster island PK which shares all nodes in one cluster
-
getDynamicNodeID
public long getDynamicNodeID()Cluster island PK + dynamic node ID is unique for identifying a single node in several clusters.- Returns:
- the unique id for one node in a cluster
-
getMessageNumber
public int getMessageNumber()Cluster island PK + dynamic node ID + message number is unique for identifying a single message in several clusters with many nodes.- Returns:
- the messageNumber
-
getNumberOfPackets
public int getNumberOfPackets()Indicates if thisRawMessageis a splitted message (value > 1) or not.- Returns:
- the number of packets. Default is 1.
-
getCurrentPacketNumber
public int getCurrentPacketNumber()Return the current packet number which is never greater thangetNumberOfPackets(). Default value is 1.- Returns:
- the current packet number.
-
getKind
public int getKind()The kind of this RawMessage. Currently known:- InvalidationBroadcastHandler.KIND_INVALIDATION =1 is used for cache invalidation
- PingBroadcastHandler.KIND_PING =99 is used for ping the different nodes in a cluster system
BroadcastMessageListenerinterface more different values for this kind getter are possible.- Returns:
- the kind as int
-
getData
public byte[] getData()- Returns:
- the content of this package s byte array.
-
matches
public boolean matches(int version, long clusterisland) TODO apidoc- Parameters:
version-clusterisland-- Returns:
- boolean
-
matches
TODO apidoc- Parameters:
other-- Returns:
- boolean
-
toString
[broadcastMethod://remoteAddress|ver:version|clusterislandid-dynamicnodeid-< /b> messageid| kind|packetnummerofpackets (content: contentlength bytes)] -
getRemoteAddress
- Returns:
- the remoteAddress
-
setRemoteAddress
- Parameters:
remoteAddress- the remoteAddress to set
-
getBroadcastMethod
- Returns:
- the broadcastMethod
-
setBroadcastMethod
- Parameters:
broadcastMethod- the broadcastMethod to set
-
getMessageKey
Returns the message key which is an unique identifier for all messages in all clusters- Returns:
- an unique object
-
mustSplit
public boolean mustSplit(int packetsize) Returnstrueif the resulting RawMessage (data+header) exceed the given packet size.- Parameters:
packetsize- the packet size- Returns:
falseotherwise
-
split
Splits the current RawMessage (this) into several RawMessages which are the same size or less (including the header) as the given packet size. If the packet size is smaller than the header size or the current message is empty (only the header) than this message is returned (in a singleton list)- Parameters:
packetSize- the packet size- Returns:
- an
ArrayListwhich contains the splittedRawMessage, each message is in the size of the given packet size.
-
join
Joins the current RawMessage (this) with the given list of RawMessages into a new joined RawMessage. The RawMessage parts in the list must be from the same source.- Parameters:
messageparts- a list with other parts- Returns:
- the joined message OR this RawMessage if the given list is
nullor empty
-
toRawByteArray
public byte[] toRawByteArray()- Returns:
- this rawmessage into a byte array which can be sent.
-