com.hazelcast.client.impl.protocol
Class ClientMessage

java.lang.Object
  extended by com.hazelcast.client.impl.protocol.util.Flyweight
      extended by com.hazelcast.client.impl.protocol.util.ParameterFlyweight
          extended by com.hazelcast.client.impl.protocol.ClientMessage
All Implemented Interfaces:
SocketReadable, SocketWritable
Direct Known Subclasses:
ClientRequest

public class ClientMessage
extends ParameterFlyweight
implements SocketWritable, SocketReadable

Client Message is the carrier framed data as defined below.

Any request parameter, response or event data will be carried in the payload.

 0                   1                   2                   3
 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
 |R|                      Frame Length                           |
 +-------------+---------------+---------------------------------+
 |  Version    |B|E|  Flags    |               Type              |
 +-------------+---------------+---------------------------------+
 |                       CorrelationId                           |
 +---------------------------------------------------------------+
 |R|                      PartitionId                            |
 +-----------------------------+---------------------------------+
 |        Data Offset          |                                 |
 +-----------------------------+                                 |
 |                      Message Payload Data                    ...
 |                                                              ...

 


Field Summary
static short BEGIN_AND_END_FLAGS
          Begin and End Flags
static short BEGIN_FLAG
          Begin Flag
static short END_FLAG
          End Flag
static int HEADER_SIZE
          ClientMessage Fixed Header size in bytes
static short LISTENER_EVENT_FLAG
          Listener Event Flag
static short VERSION
          Current protocol version
 
Fields inherited from class com.hazelcast.client.impl.protocol.util.Flyweight
buffer, INITIAL_BUFFER_CAPACITY
 
Constructor Summary
ClientMessage()
           
ClientMessage(boolean encode, byte[] buffer, int offset, int length)
           
ClientMessage(boolean encode, MutableDirectBuffer buffer, int offset)
           
 
Method Summary
 ClientMessage addFlag(short flags)
          Sets the flags field value.
static ClientMessage create()
           
static ClientMessage createForDecode(byte[] buffer, int offset, int length)
           
static ClientMessage createForDecode(int initialCapacity)
           
static ClientMessage createForDecode(MutableDirectBuffer buffer, int offset)
           
static ClientMessage createForEncode(byte[] buffer, int offset, int length)
           
static ClientMessage createForEncode(int initialCapacity)
           
 int getCorrelationId()
          Returns the correlation id field.
 int getDataOffset()
          Returns the setDataOffset field.
 short getFlags()
          Returns the flags field value.
 int getFrameLength()
          Returns the frame length field.
 int getMessageType()
          Returns the message type field.
 int getPartitionId()
          Returns the partition id field.
 ClientMessage getPayloadData(byte[] payload)
          Reads from the ClientMessage payload data region and writes into the payload array.
 short getVersion()
          Returns the version field value.
 boolean isComplete()
          Checks the frame size and total data size to validate the message size.
 boolean isFlagSet(short flag)
           
 boolean isUrgent()
          Checks if this SocketWritable is urgent.
 ClientMessage putPayloadData(byte[] payload)
          Copy data into the payload data region located at data Offset.
 boolean readFrom(ByteBuffer source)
           
 ClientMessage setCorrelationId(int correlationId)
          Sets the correlation id field.
 ClientMessage setDataOffset(int dataOffset)
          Sets the dataOffset field.
 ClientMessage setFrameLength(int length)
          Sets the frame length field.
 ClientMessage setMessageType(int type)
          Sets the message type field.
 ClientMessage setPartitionId(int partitionId)
          Sets the partition id field.
 ClientMessage setVersion(short version)
          Sets the version field value.
 String toString()
           
 ClientMessage updateFrameLength()
           
 void wrapForDecode(byte[] buffer, int offset, int length)
           
 void wrapForEncode(byte[] buffer, int offset, int length)
           
 boolean writeTo(ByteBuffer destination)
          Asks the SocketWritable to write its content to the destination ByteBuffer.
 
Methods inherited from class com.hazelcast.client.impl.protocol.util.ParameterFlyweight
getBoolean, getByte, getByteArray, getData, getDataList, getDataSet, getDouble, getFloat, getInt, getLong, getShort, getStringUtf8, index, index, set, set, set, set, set, set, set, set, set, set, set, wrap, wrap
 
Methods inherited from class com.hazelcast.client.impl.protocol.util.Flyweight
buffer, ensureCapacity, offset, offset, uint16Get, uint16Put, uint32Get, uint32Put, uint8Get, uint8Put, wrap, wrap
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

VERSION

public static final short VERSION
Current protocol version

See Also:
Constant Field Values

BEGIN_FLAG

public static final short BEGIN_FLAG
Begin Flag

See Also:
Constant Field Values

END_FLAG

public static final short END_FLAG
End Flag

See Also:
Constant Field Values

BEGIN_AND_END_FLAGS

public static final short BEGIN_AND_END_FLAGS
Begin and End Flags

See Also:
Constant Field Values

LISTENER_EVENT_FLAG

public static final short LISTENER_EVENT_FLAG
Listener Event Flag

See Also:
Constant Field Values

HEADER_SIZE

public static final int HEADER_SIZE
ClientMessage Fixed Header size in bytes

Constructor Detail

ClientMessage

public ClientMessage()

ClientMessage

public ClientMessage(boolean encode,
                     byte[] buffer,
                     int offset,
                     int length)

ClientMessage

public ClientMessage(boolean encode,
                     MutableDirectBuffer buffer,
                     int offset)
Method Detail

create

public static ClientMessage create()

createForEncode

public static ClientMessage createForEncode(int initialCapacity)

createForDecode

public static ClientMessage createForDecode(int initialCapacity)

createForEncode

public static ClientMessage createForEncode(byte[] buffer,
                                            int offset,
                                            int length)

createForDecode

public static ClientMessage createForDecode(byte[] buffer,
                                            int offset,
                                            int length)

createForDecode

public static ClientMessage createForDecode(MutableDirectBuffer buffer,
                                            int offset)

wrapForEncode

public void wrapForEncode(byte[] buffer,
                          int offset,
                          int length)

wrapForDecode

public void wrapForDecode(byte[] buffer,
                          int offset,
                          int length)

getVersion

public short getVersion()
Returns the version field value.

Returns:
The version field value.

setVersion

public ClientMessage setVersion(short version)
Sets the version field value.

Parameters:
version - The value to set in the version field.
Returns:
The ClientMessage with the new version field value.

isFlagSet

public boolean isFlagSet(short flag)
Parameters:
flag - Check this flag to see if it is set.
Returns:
true if the given flag is set, false otherwise.

getFlags

public short getFlags()
Returns the flags field value.

Returns:
The flags field value.

addFlag

public ClientMessage addFlag(short flags)
Sets the flags field value.

Parameters:
flags - The value to set in the flags field.
Returns:
The ClientMessage with the new flags field value.

getMessageType

public int getMessageType()
Returns the message type field.

Returns:
The message type field value.

setMessageType

public ClientMessage setMessageType(int type)
Sets the message type field.

Parameters:
type - The value to set in the message type field.
Returns:
The ClientMessage with the new message type field value.

getFrameLength

public int getFrameLength()
Returns the frame length field.

Returns:
The frame length field.

setFrameLength

public ClientMessage setFrameLength(int length)
Sets the frame length field.

Parameters:
length - The value to set in the frame length field.
Returns:
The ClientMessage with the new frame length field value.

getCorrelationId

public int getCorrelationId()
Returns the correlation id field.

Returns:
The correlation id field.

setCorrelationId

public ClientMessage setCorrelationId(int correlationId)
Sets the correlation id field.

Parameters:
correlationId - The value to set in the correlation id field.
Returns:
The ClientMessage with the new correlation id field value.

getPartitionId

public int getPartitionId()
Returns the partition id field.

Returns:
The partition id field.

setPartitionId

public ClientMessage setPartitionId(int partitionId)
Sets the partition id field.

Parameters:
partitionId - The value to set in the partitions id field.
Returns:
The ClientMessage with the new partitions id field value.

getDataOffset

public int getDataOffset()
Returns the setDataOffset field.

Returns:
The setDataOffset type field value.

setDataOffset

public ClientMessage setDataOffset(int dataOffset)
Sets the dataOffset field.

Parameters:
dataOffset - The value to set in the dataOffset field.
Returns:
The ClientMessage with the new dataOffset field value.

putPayloadData

public ClientMessage putPayloadData(byte[] payload)
Copy data into the payload data region located at data Offset.

Parameters:
payload - The data being copied into the ClientMessage payload data region.
Returns:
The ClientMessage with the new data in its payload data region.

getPayloadData

public ClientMessage getPayloadData(byte[] payload)
Reads from the ClientMessage payload data region and writes into the payload array.

Parameters:
payload - The payload array into which the payload data region in the ClientMessage will be copied.
Returns:
The ClientMessage from which its payload data region is copied into the payload array.

updateFrameLength

public ClientMessage updateFrameLength()

writeTo

public boolean writeTo(ByteBuffer destination)
Description copied from interface: SocketWritable
Asks the SocketWritable to write its content to the destination ByteBuffer.

Specified by:
writeTo in interface SocketWritable
Parameters:
destination - the ByteBuffer to write to.
Returns:
todo: unclear what return value means.

readFrom

public boolean readFrom(ByteBuffer source)
Specified by:
readFrom in interface SocketReadable

isComplete

public boolean isComplete()
Checks the frame size and total data size to validate the message size.

Returns:
true if the message is constructed.

isUrgent

public boolean isUrgent()
Description copied from interface: SocketWritable
Checks if this SocketWritable is urgent. SocketWritable that are urgent, have priority above regular SocketWritable. This is useful to implement System Operations so that they can be send faster than regular operations; especially when the system is under load you want these operations have precedence.

Specified by:
isUrgent in interface SocketWritable
Returns:
true if urgent, false otherwise.

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2015 Hazelcast, Inc.. All Rights Reserved.