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 toBytesMessage.- Since:
- 5.0.0
- Author:
- Bela Ban
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.jgroups.Message
Message.Flag, Message.TransientFlag
-
-
Field Summary
Fields Modifier and Type Field Description protected longvalue-
Fields inherited from class org.jgroups.BaseMessage
dest, flags, headers, sender, transient_flags
-
Fields inherited from interface org.jgroups.Message
BYTES_MSG, COMPOSITE_MSG, EARLYBATCH_MSG, EMPTY_MSG, FRAG_MSG, LONG_MSG, NIO_MSG, OBJ_MSG
-
-
Constructor Summary
Constructors Constructor Description LongMessage()LongMessage(Address dest, long v)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected MessagecopyPayload(Message copy)Copies the payloadjava.util.function.Supplier<? extends Message>create()Creates an instance of the class implementing this interfacebyte[]getArray()Returns a reference to the payload (byte array).intgetLength()Returns the length of the byte[] array payload.<T> TgetObject()Gets an object from the payload.intgetOffset()Returns the offset of the byte[] array at which user data starts.shortgetType()Returns the type of the message, e.g.longgetValue()booleanhasArray()Returns true if this message has a byte[] array as payload (even if it's null!), false otherwisebooleanhasPayload()Returns true if the message has a payload, e.g.protected intpayloadSize()voidreadPayload(java.io.DataInput in)LongMessagesetArray(byte[] b, int o, int l)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 typeBytesMessage.LongMessagesetArray(ByteArray b)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 typeBytesMessage.LongMessagesetObject(java.lang.Object obj)Sets the valueLongMessagesetValue(long v)java.lang.StringtoString()voidwritePayload(java.io.DataOutput out)-
Methods inherited from class org.jgroups.BaseMessage
clearFlag, clearFlag, clearHeaders, copy, createHeaders, getDest, getFlags, getHeader, getHeaders, getNumHeaders, getPayload, getSrc, headers, headers, isFlagSet, isFlagSet, printHeaders, putHeader, putHeader, putHeaderIfAbsent, readFrom, serializedSize, setDest, setFlag, setFlag, setFlag, setFlagIfAbsent, setPayload, setSrc, size, sizeNoAddrs, writeTo, writeToNoAddrs
-
-
-
-
Constructor Detail
-
LongMessage
public LongMessage()
-
LongMessage
public LongMessage(Address dest, long v)
-
-
Method Detail
-
getValue
public long getValue()
-
setValue
public LongMessage setValue(long v)
-
getType
public short getType()
Description copied from interface:MessageReturns the type of the message, e.g. BYTES_MSG, OBJ_MSG etc
-
hasPayload
public boolean hasPayload()
Description copied from interface:MessageReturns true if the message has a payload, e.g. a byte[] array in aBytesMessageor an object in anObjectMessage. This is more generic thanMessage.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:MessageReturns 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:MessageReturns 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 typeBytesMessage. It is recommended to downcast aMessageto the correct subtype and use the methods available there to get/set the payload.
-
getOffset
public int getOffset()
Description copied from interface:MessageReturns the offset of the byte[] array at which user data starts. Throws an exception if the message does not have a byte[] array payload (ifMessage.hasArray()is false).
Note that this is a convenience method, as most messages are of typeBytesMessage.
-
getLength
public int getLength()
Description copied from interface:MessageReturns 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:MessageSets 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 typeBytesMessage. It is recommended to downcast aMessageto the correct subtype and use the methods available there to get/set the payload.
-
setArray
public LongMessage setArray(ByteArray b)
Description copied from interface:MessageSets 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 typeBytesMessage. It is recommended to downcast aMessageto the correct subtype and use the methods available there to get/set the payload.
-
getObject
public <T> T getObject()
Description copied from interface:MessageGets an object from the payload. If the payload is a byte[] array (e.g. as inBytesMessage), 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 inObjectMessage), the object will be returned directly.
-
setObject
public LongMessage setObject(java.lang.Object obj)
Sets the value- Parameters:
obj- Has to be a Number (int or long)
-
create
public java.util.function.Supplier<? extends Message> create()
Description copied from interface:ConstructableCreates an instance of the class implementing this interface
-
copyPayload
protected Message copyPayload(Message copy)
Description copied from class:BaseMessageCopies the payload- Overrides:
copyPayloadin classBaseMessage
-
writePayload
public void writePayload(java.io.DataOutput out) throws java.io.IOException- Throws:
java.io.IOException
-
readPayload
public void readPayload(java.io.DataInput in) throws java.io.IOException, java.lang.ClassNotFoundException- Throws:
java.io.IOExceptionjava.lang.ClassNotFoundException
-
payloadSize
protected int payloadSize()
- Specified by:
payloadSizein classBaseMessage
-
toString
public java.lang.String toString()
- Overrides:
toStringin classBaseMessage
-
-