|
|||||||||
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. |
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 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. |
PktBody |
getBody()
Get the packet body. |
PktHeader |
getHeader()
Get the packet header. |
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. |
com.neeve.util.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. |
com.neeve.util.UtlReferenceTracker |
referenceTracker()
|
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(com.neeve.util.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 com.neeve.util.UtlReferenceTracker referenceTracker()
referenceTracker
in interface com.neeve.util.UtlReferenceTracker.HasReferenceTracker
public final PktPacket fork()
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 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 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
public final int getSerializedLength()
PktSerializable.getSerializedLength()
.
getSerializedLength
in class PktSerializable
public final PktPacket init()
init
in interface com.neeve.util.UtlPool.Item<PktPacket>
public final PktPacket setPool(com.neeve.util.UtlPool<PktPacket> pool)
setPool
in interface com.neeve.util.UtlPool.Item<PktPacket>
public final com.neeve.util.UtlPool<PktPacket> getPool()
getPool
in interface com.neeve.util.UtlPool.Item<PktPacket>
public final String toString()
toString
in class Object
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |