com.hazelcast.nio
Class Packet

java.lang.Object
  extended by com.hazelcast.nio.serialization.DataAdapter
      extended by com.hazelcast.nio.Packet
All Implemented Interfaces:
SocketReadable, SocketWritable

public final class Packet
extends DataAdapter
implements SocketWritable, SocketReadable

A Packet is a piece of data send over the line.


Field Summary
static int HEADER_BIND
           
static int HEADER_EVENT
           
static int HEADER_OP
           
static int HEADER_RESPONSE
           
static int HEADER_URGENT
           
static int HEADER_WAN_REPLICATION
           
static byte VERSION
           
 
Fields inherited from class com.hazelcast.nio.serialization.DataAdapter
context, data
 
Constructor Summary
Packet(Data value, int partitionId, PortableContext context)
           
Packet(Data value, PortableContext context)
           
Packet(PortableContext context)
           
 
Method Summary
 Connection getConn()
          Gets the Connection this Packet was send with.
 short getHeader()
          Returns the header of the Packet.
 int getPartitionId()
          Returns the partition id of this packet.
 boolean isHeaderSet(int bit)
           
 boolean isUrgent()
          Checks if this SocketWritable is urgent.
 boolean readFrom(ByteBuffer source)
           
 void setConn(Connection conn)
          Sets the Connection this Packet is send with.
 void setHeader(int bit)
           
 int size()
          Returns an estimation of the packet, including its payload, in bytes.
 String toString()
           
 boolean writeTo(ByteBuffer destination)
          Asks the SocketWritable to write its content to the destination ByteBuffer.
 
Methods inherited from class com.hazelcast.nio.serialization.DataAdapter
done, getData, getDataSize, isStatusSet, reset, setData, setStatus
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

VERSION

public static final byte VERSION
See Also:
Constant Field Values

HEADER_OP

public static final int HEADER_OP
See Also:
Constant Field Values

HEADER_RESPONSE

public static final int HEADER_RESPONSE
See Also:
Constant Field Values

HEADER_EVENT

public static final int HEADER_EVENT
See Also:
Constant Field Values

HEADER_WAN_REPLICATION

public static final int HEADER_WAN_REPLICATION
See Also:
Constant Field Values

HEADER_URGENT

public static final int HEADER_URGENT
See Also:
Constant Field Values

HEADER_BIND

public static final int HEADER_BIND
See Also:
Constant Field Values
Constructor Detail

Packet

public Packet(PortableContext context)

Packet

public Packet(Data value,
              PortableContext context)

Packet

public Packet(Data value,
              int partitionId,
              PortableContext context)
Method Detail

getConn

public Connection getConn()
Gets the Connection this Packet was send with.

Returns:
the Connection. Could be null.

setConn

public void setConn(Connection conn)
Sets the Connection this Packet is send with.

This is done on the reading side of the Packet to make it possible to retrieve information about the sender of the Packet.

Parameters:
conn - the connection.

setHeader

public void setHeader(int bit)

isHeaderSet

public boolean isHeaderSet(int bit)

getHeader

public short getHeader()
Returns the header of the Packet. The header is used to figure out what the content is of this Packet before the actual payload needs to be processed.

Returns:
the header.

getPartitionId

public int getPartitionId()
Returns the partition id of this packet. If this packet is not for a particular partition, -1 is returned.

Returns:
the partition id.

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
Overrides:
isUrgent in class DataAdapter
Returns:
true if urgent, false otherwise.

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
Overrides:
writeTo in class DataAdapter
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
Overrides:
readFrom in class DataAdapter

size

public int size()
Returns an estimation of the packet, including its payload, in bytes.

Returns:
the size of the packet.

toString

public String toString()
Overrides:
toString in class Object


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