Class RawMessage

java.lang.Object
de.hybris.platform.cluster.RawMessage
All Implemented Interfaces:
Serializable

public class RawMessage extends Object implements 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

    Fields
    Modifier and Type
    Field
    Description
    static final int
    The size of the header of this message object.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
     
    RawMessage(byte[] binaryMessageBytes)
    Creates a message object from the given byte array.
     
    RawMessage(byte[] binaryMessageBytes, int offset)
    Same as RawMessage(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.
    protected
    RawMessage(RawMessage original, int numberOfPackets, int currentPacketNumber, int offset, int length)
    Constructor used for message splitting.
  • Method Summary

    Modifier and Type
    Method
    Description
     
    long
     
    int
    Return the current packet number which is never greater than getNumberOfPackets().
    byte[]
     
    long
    Cluster island PK + dynamic node ID is unique for identifying a single node in several clusters.
    int
    The kind of this RawMessage.
    Returns the message key which is an unique identifier for all messages in all clusters
    int
    Cluster island PK + dynamic node ID + message number is unique for identifying a single message in several clusters with many nodes.
    int
    Indicates if this RawMessage is a splitted message (value > 1) or not.
     
    int
    Returns 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.
    boolean
    matches(int version, long clusterisland)
    TODO apidoc
    boolean
    TODO apidoc
    boolean
    mustSplit(int packetsize)
    Returns true if the resulting RawMessage (data+header) exceed the given packet size.
    void
    setBroadcastMethod(String broadcastMethod)
     
    void
    setPacketSplitInfo(int currentPacketNumber, int numberOfPackets)
    Sets the header information when the message is splitted into several parts.
    void
    TODO apidoc
    void
     
    void
    setSenderTransportData(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[]
     
    [broadcastMethod://remoteAddress|ver:version|clusterislandid-dynamicnodeid-< /b> messageid| kind|packetnummerofpackets (content: contentlength bytes)]

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • HEADER_SIZE

      public static final int HEADER_SIZE
      The 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 packets
      currentPacketNumber - the new current packet number
      offset - the starting point for copying the original data into this object
      length - 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 as RawMessage(byte[]) but from the given byte array the offset (starting part) is ignored.
      Parameters:
      binaryMessageBytes - the byte array which includes the header and the content
      offset - 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 object
      offset - start point of the message object in the byte array
      length - 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 message
      clusterIsland - the cluster island ID
      dynamicNodeID - the dynamic node ID
      messageNumber - 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

      public void setReceiverTransportData(InetAddress remoteAdress)
      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. See DefaultBroadcastService.CUR_VERSION
      int 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 this RawMessage is 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 than getNumberOfPackets(). 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
      Depending on other implementation of the BroadcastMessageListener interface 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

      public boolean matches(RawMessage other)
      TODO apidoc
      Parameters:
      other -
      Returns:
      boolean
    • toString

      public String toString()
      [broadcastMethod://remoteAddress|ver:version|clusterislandid-dynamicnodeid-< /b> messageid| kind|packetnummerofpackets (content: contentlength bytes)]
      Overrides:
      toString in class Object
    • getRemoteAddress

      public InetAddress getRemoteAddress()
      Returns:
      the remoteAddress
    • setRemoteAddress

      public void setRemoteAddress(InetAddress remoteAddress)
      Parameters:
      remoteAddress - the remoteAddress to set
    • getBroadcastMethod

      public String getBroadcastMethod()
      Returns:
      the broadcastMethod
    • setBroadcastMethod

      public void setBroadcastMethod(String broadcastMethod)
      Parameters:
      broadcastMethod - the broadcastMethod to set
    • getMessageKey

      public Object 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)
      Returns true if the resulting RawMessage (data+header) exceed the given packet size.
      Parameters:
      packetsize - the packet size
      Returns:
      false otherwise
    • split

      public List<RawMessage> 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. 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 ArrayList which contains the splitted RawMessage, each message is in the size of the given packet size.
    • join

      public RawMessage join(Collection<RawMessage> messageparts)
      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 null or empty
    • toRawByteArray

      public byte[] toRawByteArray()
      Returns:
      this rawmessage into a byte array which can be sent.