Package org.jgroups

Class LongMessage

java.lang.Object
org.jgroups.BaseMessage
org.jgroups.LongMessage
All Implemented Interfaces:
Constructable<Message>, Message, SizeStreamable, Streamable

public class LongMessage extends BaseMessage
Message with a long as payload. Can be used to send int- or long values, without having to resort to BytesMessage.
Since:
5.0.0
  • Field Details

    • value

      protected long value
  • Constructor Details

    • LongMessage

      public LongMessage()
    • LongMessage

      public LongMessage(Address dest, long v)
  • Method Details

    • getValue

      public long getValue()
    • setValue

      public LongMessage setValue(long v)
    • getType

      public short getType()
      Description copied from interface: Message
      Returns the type of the message, e.g. BYTES_MSG, OBJ_MSG etc
    • hasPayload

      public boolean hasPayload()
      Description copied from interface: Message
      Returns true if the message has a payload, e.g. a byte[] array in a BytesMessage or an object in an ObjectMessage. This is more generic than Message.hasArray(), as it is not just applicable to a byte array.
      Returns:
      True if the message has a payload
    • hasArray

      public boolean hasArray()
      Description copied from interface: Message
      Returns true if this message has a byte[] array as payload (even if it's null!), false otherwise
    • getArray

      public byte[] getArray()
      Description copied from interface: Message
      Returns a reference to the payload (byte array). Note that this array should not be modified as we do not copy the array on copy() or clone(): the array of the copied message is simply a reference to the old array.

      Even if offset and length are used: we return the entire array, not a subset.

      Throws an exception if the message does not have a byte[] array payload (Message.hasArray() is false).

      Note that this is a convenience method, as most messages are of type BytesMessage. It is recommended to downcast a Message to the correct subtype and use the methods available there to get/set the payload.

    • getOffset

      public int getOffset()
      Description copied from interface: Message
      Returns the offset of the byte[] array at which user data starts. Throws an exception if the message does not have a byte[] array payload (if Message.hasArray() is false).

      Note that this is a convenience method, as most messages are of type BytesMessage.

    • getLength

      public int getLength()
      Description copied from interface: Message
      Returns the length of the byte[] array payload. If the message does not have a byte[] array payload (Message.hasArray() is false), then the serialized size may be returned, or an implementation may choose to throw an exception
    • setArray

      public LongMessage setArray(byte[] b, int o, int l)
      Description copied from interface: Message
      Sets the byte array in a message.

      Throws an exception if the message does not have a byte[] array payload (Message.hasArray() is false).

      Note that this is a convenience method, as most messages are of type BytesMessage. It is recommended to downcast a Message to the correct subtype and use the methods available there to get/set the payload.

    • setArray

      public LongMessage setArray(ByteArray b)
      Description copied from interface: Message
      Sets the byte array in a message.

      Throws an exception if the message does not have a byte[] array payload (Message.hasArray() is false).

      Note that this is a convenience method, as most messages are of type BytesMessage. It is recommended to downcast a Message to the correct subtype and use the methods available there to get/set the payload.

    • getObject

      public <T> T getObject()
      Description copied from interface: Message
      Gets an object from the payload. If the payload is a byte[] array (e.g. as in BytesMessage), an attempt to de-serialize the array into an object is made, and the object returned.

      If the payload is an object (e.g. as is the case in ObjectMessage), the object will be returned directly.

    • setObject

      public LongMessage setObject(Object obj)
      Sets the value
      Parameters:
      obj - Has to be a Number (int or long)
    • create

      public Supplier<? extends Message> create()
      Description copied from interface: Constructable
      Creates an instance of the class implementing this interface
    • copyPayload

      protected Message copyPayload(Message copy)
      Description copied from class: BaseMessage
      Copies the payload
      Overrides:
      copyPayload in class BaseMessage
    • writePayload

      public void writePayload(DataOutput out) throws IOException
      Throws:
      IOException
    • readPayload

      public void readPayload(DataInput in) throws IOException, ClassNotFoundException
      Throws:
      IOException
      ClassNotFoundException
    • size

      public int size()
      Description copied from interface: Message
      Returns the exact size of the marshalled message
      Specified by:
      size in interface Message
      Overrides:
      size in class BaseMessage
      Returns:
      The number of bytes for the marshalled message
    • toString

      public String toString()
      Overrides:
      toString in class BaseMessage