|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.neeve.util.UtlListElement
com.neeve.pkt.PktSerializable
com.neeve.pkt.PktPacket
public final class PktPacket
The packet.
Packets serve as the basic unit of conversation between participants
in a distributed system. Each packet flowing through the system is
logically part of a conversation between some messaging participants.
Each packet is of a specific type and defines the grammar of the packet's
contents. Structurally, a packet consists of a header, a body and a set of
tag objects. The header portion of a packet contains system information and
is used by intermediate and the participants (endpoints) of the conversation
of which the packet is a part. On the other hand, the packet body contains
information interpreted solely by the conversation participants. Packet tags
are opaque objects attached to packets as they travel within process (JVM)
boundaries. They serve as a mechanism of decoupled communication between
the various processors of a packet in its path through a process. Packet
tags are not preserved across process boundaries. Refer to PktHeader
for information on the structure of the packet header. The structure of the
packet body is defined by the packet type. A separate class exists for each
packet type. Structurally, packet tags are opaque to the packet and are
interpreted only by the packet processors.
Nested Class Summary |
---|
Nested classes/interfaces inherited from class com.neeve.pkt.PktSerializable |
---|
PktSerializable.DeserializeContext, PktSerializable.SerializeContext |
Field Summary |
---|
Fields inherited from class com.neeve.util.UtlListElement |
---|
count, head, next, prev |
Method Summary | |
---|---|
PktPacket |
acquire()
Increase a packet's ownership count. |
int |
deserialize(ByteBuffer buf,
int bufOffset)
Deserialize a packet from a byte buffer |
int |
deserialize(com.neeve.io.IOBuffer iobuf,
int iobufOffset,
boolean wrap)
Deserialize a packet from an IO buffer |
void |
deserialize(PktSerializable.DeserializeContext context,
int packetSerializedLength,
Tracer tracer)
Implementation of PktSerializable.deserialize(com.neeve.pkt.PktSerializable.DeserializeContext, int, com.neeve.trace.Tracer) . |
void |
dispose()
Dispose of a packet. |
PktPacket |
fork()
Fork a packet This method invokes fork(false)
|
PktPacket |
fork(boolean storageOnly)
Fork a packet |
PktPacket |
forkNonPooled()
Fork a packet This method is the same as fork(boolean, boolean) except that the forked packet
is created from outside of the forking packet's pool, if present. |
PktBody |
getBody()
Get the packet body. |
PktHeader |
getHeader()
Get the packet header. |
int |
getInitialBufferLength()
Implementation of IOElasticBuffer.Sizer.getInitialBufferLength() |
long |
getInTs()
Get a packet's inbound timestamp. |
long |
getOutTs()
Get a packet's outbound (pre-wire) timestamp. |
int |
getOwnerCount()
Get a packet's ownership count. |
UtlPool<PktPacket> |
getPool()
Implementation of UtlPool.Item#getPool. |
int |
getSerializedLength()
Implementation of PktSerializable.getSerializedLength() . |
Object |
getTag(int id)
Get a packet tag. |
PktPacket |
init()
Implementation of UtlPool.Item#init. |
UtlReferenceTracker |
referenceTracker()
Get an object's reference tracker. |
int |
serialize(byte[] array,
int arrayOffset)
Serialize a packet to a byte array |
int |
serialize(ByteBuffer buf)
Serialize a packet to a byte buffer |
int |
serialize(ByteBuffer buf,
int bufOffset)
Serialize a packet to a byte buffer |
int |
serialize(com.neeve.io.IOBuffer iobuf,
int iobufOffset)
Serialize a packet to an IO buffer |
int |
serialize(com.neeve.io.IOElasticBuffer iobuf,
int iobufOffset)
Serialize a packet to an elastic IO buffer |
int |
serialize(long address,
int addressOffset)
Serialize a packet to a native memory region |
void |
serialize(PktSerializable.SerializeContext context,
Tracer tracer)
Implementation of PktSerializable.serialize(com.neeve.pkt.PktSerializable.SerializeContext, com.neeve.trace.Tracer) . |
void |
setDeserializationPolicy(int policy)
Implementation of PktSerializable.setDeserializationPolicy(int) . |
void |
setInTs(long ts)
Set a packet's inbound (post-wire) timestamp. |
void |
setOutTs(ByteBuffer buffer,
int pos,
long ts)
Set a packet's outbound (pre-wire) timestamp. |
PktPacket |
setPool(UtlPool<PktPacket> pool)
Implementation of UtlPool.Item#setPool. |
void |
setSerializationPolicy(int policy)
Implementation of PktSerializable.setSerializationPolicy(int) . |
void |
setTag(int id,
Object tag)
Set a packet tag. |
String |
toString()
Return a string representation of the object. |
Methods inherited from class com.neeve.pkt.PktSerializable |
---|
deserialize, getDeserializationPolicy, getSerializationPolicy, isValidDeserializationPolicy, isValidSerializationPolicy, serialize |
Methods inherited from class com.neeve.util.UtlListElement |
---|
count, insertAfter, insertBefore, isLinked, next, previous, unlink, wipe |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Method Detail |
---|
public final PktHeader getHeader()
public final PktBody getBody()
public final void setTag(int id, Object tag)
public final Object getTag(int id)
public final void setInTs(long ts)
This method is used to stamp a packet with its pre-deserialize timestamp (in microseconds)
public final long getInTs()
public final void setOutTs(ByteBuffer buffer, int pos, long ts)
This method is used to stamp a packet with its post-serialize timestamp (in microseconds)
public final long getOutTs()
public final PktPacket acquire()
This method increments a packet's ownership count. Packet ownership
is used in conjunction with managing packet pools. If a packet is
tagged to an object pool, the packet is released back to the pool
by dispose()
when the ownership count reduces to 0. If not
tagged to a pool, change of ownership count has no side effects.
A packet's ownership count starts at 1.
public final int getOwnerCount()
public final void dispose()
This method should be invoked by the user when done with a packet. It decrements the packet's ownership count and releases it to its object pool if one is tagged to it and this method cause the ownership count to reduce to zero. If not tagged to a pool, ownership change methods have no side effects aside from just updating the ownership counter.
Upon return from this method, the caller should assume that the packet has been disposed and release uts reference to the packet.
public final UtlReferenceTracker referenceTracker()
UtlReferenceTracker.HasReferenceTracker
This method returns an object's reference tracker intended for use for
debugging purposes. An object should instantiate a tracker only if
UtlReferenceTracker.ENABLED
is true or UtlReferenceTracker.enabled(Class)
is true for the object type. The flag can be enabled via the properties nv.reftracking.enabled
or by the nv.reftracking.types=fullclassname1[|fullclassnameN].
referenceTracker
in interface UtlReferenceTracker.HasReferenceTracker
public final PktPacket fork(boolean storageOnly)
storageOnly
- If set to true, then the forking process will
only fork the packet's underlying storage. This means that packet
header contents can be accessed via the PktHeader
API on
the forked packet but the packet subheader and concrete packet body
implementation that is layered on top of the packet body storage
will not be made aware of the fact that the body storage has
legitimate contents in it. This parameter should be set to true
for situations where only the storage of the forked packet is
going to be accessed e.g. for persistence
The act of forking a packet creates a new (forked) packet of the same type as the original packet but with both packets sharing the same set of underlying IO buffers but marked as copy on write. The subheader and body elements of the original packets are sync'd to the backing buffer before the fork is performed. All other state elements of the forked packet - tags, reference count, etc - are the same as if the packet was created fresh.
public final PktPacket fork()
This method invokes fork(false)
public final PktPacket forkNonPooled()
This method is the same as fork(boolean, boolean)
except that the forked packet
is created from outside of the forking packet's pool, if present.
NOTE: THIS METHOD IS INTENDED FOR X PLATFORM INTERNAL USE AND SHOULD
NOT BE USED. PLEASE CONSULT NEEVE TECHNICAL SUPPORT BEFORE YOU
USE THIS METHOD. THIS METHOD CAN BE DEPRECATED/REMOVED/CHANGED
AT ANY TIME WIHOUT NOTICE
public final void setSerializationPolicy(int policy)
PktSerializable.setSerializationPolicy(int)
.
setSerializationPolicy
in class PktSerializable
policy
- The serialization policy to use for this entity. The
following are the permissible serialization policies:PktConstants.SERIALIZE_POLICY_HEADER_COPY_BODY_COPY
PktConstants.SERIALIZE_POLICY_HEADER_COPY_BODY_ATTACH
PktConstants.SERIALIZE_POLICY_HEADER_ATTACH_BODY_ATTACH
public final void serialize(PktSerializable.SerializeContext context, Tracer tracer) throws EPktSerializeException
PktSerializable.serialize(com.neeve.pkt.PktSerializable.SerializeContext, com.neeve.trace.Tracer)
.
This method serializes the packet into the buffers list specified
in the provided serialization context. The method serializes the packet
by invoking PktHeader.serialize(com.neeve.pkt.PktSerializable.SerializeContext, com.neeve.trace.Tracer)
and PktBody.serialize(com.neeve.pkt.PktSerializable.SerializeContext, com.neeve.trace.Tracer)
.
Refer to those methods for more detailed information on the serialization
process including how the serialization policy to use is resolved.
serialize
in class PktSerializable
context
- The context to be used by the serialization process. See
PktSerializable.SerializeContext
for more information.tracer
- Tracer used to output serialization related trace. Can be
null in which case no trace is output.
EPktSerializeException
- Thrown in case an error is encountered
during the serialization process.
This method serializes a serialiable entity into a byte array presented as a set of byte buffers. As input, this method accepts a serialization context that, among other fields, contains a list of buffers of type {link java.nio.ByteBuffer} into which the entity is to serialize itself. The serialization operation is policy driven and the policy determines whether the header is copied into space remaining in the provided buffers or whether the internal entity buffers are just appended to the provided buffer list. In case the decision is made to copy the serialized data into the provided buffers, the data is always copied into the last buffer in the list. In case the last buffer does not contain enough remaining space to accomodate all the serialized data, this method will allocate and append a new buffer that will be of the same type and capacity as the last buffer in the provided list. Read the documentation of the policy constants to understand which policies cause the header to be copied as opposed to appended (the policy constant names are also self descriptive)
public final int serialize(ByteBuffer buf)
buf
- The byte buffer to serialize to
This method serialized the contents of a packet by copying the contents of the packet's header and body buffers to a byte buffer. This method copies the contents to the target buffer starting at the target buffer's position. This method does not change any of the markers of the target buffer.
Note:Since this method does not change any markers of the target buffer, the caller needs to ensure the buffer limit is set correctly to accommodate the 's contents. The caller can invokegetSerializedLength()
to get
the length of the's contents and use that to set the target buffer's
limit before invoking this method.
public final int serialize(ByteBuffer buf, int bufOffset)
buf
- The byte buffer to serialize tobufOffset
- The offset into the buffer where the serialized contents
of the packet needs to be serialized (copied)
This method serialized the contents of a packet by copying the contents of the packet's header and body buffers to a byte buffer. This method copies the contents to the target buffer starting at the supplied buffer offset. This method does not change any of the markers of the target byte buffer.
Note:Since this method does not change any markers of the target buffer, the caller needs to ensure the buffer limit is set correctly to accommodate the contents. The caller can invokegetSerializedLength()
to get
the length of the's contents and use that to set the target buffer's
limit before invoking this method.
public final int serialize(byte[] array, int arrayOffset)
array
- The byte array to serialize toarrayOffset
- The offset into the array where the serialized contents
of the packet needs to be serialized (copied)
This method serialized the contents of a packet by copying the contents of the packet's header and body buffers to a byte array.
public final int serialize(com.neeve.io.IOBuffer iobuf, int iobufOffset)
iobuf
- The IO buffer to serialize toiobufOffset
- The offset into the IO buffer where the serialized contents
of the packet needs to be serialized (copied)
This method serialized the contents of a packet by copying the contents of the packet's header and body buffers to an IO buffer.
public final int serialize(com.neeve.io.IOElasticBuffer iobuf, int iobufOffset)
iobuf
- The IO buffer to serialize toiobufOffset
- The offset into the IO buffer where the serialized contents
of the packet needs to be serialized (copied)
This method serialized the contents of a packet by copying the contents of the packet's header and body buffers to an elastic IO buffer.
public final int serialize(long address, int addressOffset)
address
- The address of the native memory region to serialize toaddressOffset
- The offset into the memory region where the serialized
contents of the packet should be serialized to.
This method serialized the contents of a packet by copying the contents of the packet's header and body buffers to a native memory region.
public final void setDeserializationPolicy(int policy)
PktSerializable.setDeserializationPolicy(int)
.
setDeserializationPolicy
in class PktSerializable
policy
- The deserialization policy to use for this entity. The
following are the permissible serialization policies:PktConstants.DESERIALIZE_POLICY_HEADER_COPY_BODY_COPY
PktConstants.DESERIALIZE_POLICY_HEADER_COPY_BODY_SLICE
PktConstants.DESERIALIZE_POLICY_HEADER_SLICE_BODY_SLICE
public final void deserialize(PktSerializable.DeserializeContext context, int packetSerializedLength, Tracer tracer) throws EPktDeserializeException
PktSerializable.deserialize(com.neeve.pkt.PktSerializable.DeserializeContext, int, com.neeve.trace.Tracer)
.
This method deserializes the packet from the buffer specified in the
provided deserialization context. The method deserializes the packet
by invoking PktHeader.deserialize(com.neeve.pkt.PktSerializable.DeserializeContext, int, com.neeve.trace.Tracer)
and PktBody.deserialize(com.neeve.pkt.PktSerializable.DeserializeContext, int, com.neeve.trace.Tracer)
.
Refer to those methods for information more detailed information on
the deserialization process including how the deserialization policy to
use is resolved.
deserialize
in class PktSerializable
context
- The context to be used by the deserialization process.
See PktSerializable.DeserializeContext
for more information.packetSerializedLength
- This parameter is present for entities
whose serialized form does not contain the serialized length of the
entity. For such entities, the caller needs to pass in the serialized
length to the entity during deserialize time. For other entities, this
value will be ignored and should be set to -1 (some entities that
pull the length from the serialized form may indeed validate that
the passed in value is -1)tracer
- Tracer used to output deserialization related trace. Can be
null in which case no trace is output.
EPktDeserializeException
- Thrown in case an error is encountered
during the deserialization process.
This method initializes a serializable entity from a byte buffer. As
input, this method accepts a deserialization context that contains, in
addition to other fields, a ByteBuffer
from where
the entity is to be initialized. It is assumed that the caller has
validated (using some other means) that the buffer contains enough data
to initialize the entity. Upon successful return, the context is
updated with information relating to the deserialization e.g. how
many bytes were consumed from the buffer to initialize the entity
and whether a reference to the buffer is being retained by the entity
subsequent to returning from this method. Refer to the context
documentation for detailed information on how and when the fields
are updated.
Before returning from this method, the implementation must replace the buffer in the context with a sliced version of the provided buffer so that the next entity in the deserialization chain can operate out of the buffer provided to it using absolute indices i.e. relative to the beginning of the buffer rather than relative to the current buffer position.
public final int deserialize(ByteBuffer buf, int bufOffset)
buf
- The byte buffer to deserialize frombufOffset
- The offset into the buffer where the serialized packet starts
This method deserializes the packet from a byte buffer. The method deserializes the packet by first deserializing the header followed by the body.
Note: This method assumes that the supplied length is greater than or equal to
the length of the serialized packet. To ensure that the buffer does indeed contain
the full serialized packet, use PktHeader.preDeserialize(ByteBuffer, int, int)
public final int deserialize(com.neeve.io.IOBuffer iobuf, int iobufOffset, boolean wrap)
iobuf
- The IO buffer to deserialize fromiobufOffset
- The offset into the IO buffer where the serialized packet
startswrap
- Indicates whether the deserialization process should copy the
contents of the IO buffer to the packet body or wrap the packet body's
buffer around the supplied IO buffer
This method deserializes the packet from an IO buffer. The method deserializes the packet by first deserializing the header followed by the body.
public final int getSerializedLength()
PktSerializable.getSerializedLength()
.
getSerializedLength
in class PktSerializable
public final int getInitialBufferLength()
IOElasticBuffer.Sizer.getInitialBufferLength()
getInitialBufferLength
in interface com.neeve.io.IOElasticBuffer.Sizer
public final PktPacket init()
init
in interface UtlPool.Item<PktPacket>
public final PktPacket setPool(UtlPool<PktPacket> pool)
setPool
in interface UtlPool.Item<PktPacket>
public final UtlPool<PktPacket> getPool()
getPool
in interface UtlPool.Item<PktPacket>
UtlPool.Item.setPool(com.neeve.util.UtlPool)
public final String toString()
toString
in class Object
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |