public final class PktPacket extends UtlListElement implements UtlPool.Item<PktPacket>, UtlReferenceTracker.HasReferenceTracker
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.
count, head, next, prev| Modifier and Type | Method and Description |
|---|---|
PktPacket |
acquire()
Increase a packet's ownership count.
|
int |
deserialize(ByteBuffer buf,
int bufOffset)
Deserialize a packet from a byte buffer
This method invokes putFrom(buf, bufOffset) followed by desync()
|
int |
deserialize(IOBuffer iobuf,
int iobufOffset)
Deserialize a packet from an IO buffer
This method invokes
deserialize(iobuf, iobufOffset, false, false)
|
int |
deserialize(IOBuffer iobuf,
int iobufOffset,
boolean wrap)
Deserialize a packet from an IO buffer
This method invokes deserialize(iobuf, iobufOffset, wrap, wrap)
|
int |
deserialize(IOBuffer iobuf,
int iobufOffset,
boolean wrapHeader,
boolean wrapBody)
Deserialize a packet from an IO buffer
This method invokes putFrom(iobuf, iobufOffset, wrapHeader, wrapBody) followed by desync()
|
int |
deserialize(long addr,
int addrOffset)
Deserialize a packet from a native memory region
This method invokes putFrom(addr, addrOffset) followed by desync()
|
int |
deserialize(PktPacket packet)
Deserialize a packet from another packet
|
void |
desync()
Desync the early desync contents of a packet body's backing buffer
|
void |
dispose()
Dispose of a packet.
|
PktBody |
getBody()
Get the packet body.
|
PktHeader |
getHeader()
Get the packet header.
|
int |
getOwnerCount()
Get a packet's ownership count.
|
UtlPool<PktPacket> |
getPool()
Implementation of UtlPool.Item#getPool.
|
int |
getSerializedLength()
Get the serialized length of a packet
|
Object |
getTag(int id)
Get a packet tag.
|
int |
getTo(byte[] array,
int arrayOffset)
Copy the contents of a packet's header and body buffers to a byte array
This method invokes
return getTo(array, arrayOffset, true)
|
int |
getTo(byte[] array,
int arrayOffset,
boolean withMagic)
Copy the contents of a packet's header and body buffers to a byte array
|
int |
getTo(ByteBuffer buf)
Copy the contents of a packet's header and body buffers to a byte buffer
This method invokes
return getTo(buf, true)
|
int |
getTo(ByteBuffer buf,
boolean withMagic)
Copy the contents of a packet's header and body buffers to a byte buffer
This method invokes
return getTo(buf, buf.position(), withMagic)
|
int |
getTo(ByteBuffer buf,
int bufOffset)
Copy the contents of a packet's header and body buffers to a byte buffer
This method invokes
return getTo(buf, bufOffset, true)
|
int |
getTo(ByteBuffer buf,
int bufOffset,
boolean withMagic)
Copy the contents of a packet's header and body buffers to a byte buffer
|
int |
getTo(IOBuffer iobuf,
int iobufOffset)
Copy the contents of a packet's header and body buffers to an
IOBuffer
This method invokes return getTo(iobuf, iobufOffset, true)
|
int |
getTo(IOBuffer iobuf,
int iobufOffset,
boolean withMagic)
Copy the contents of a packet's header and body buffers to an
IOBuffer |
int |
getTo(IOElasticBuffer iobuf,
int iobufOffset)
Copy the contents of a packet's header and body buffers to an
IOElasticBuffer
This method invokes return getTo(iobuf, iobufOffset, true)
|
int |
getTo(IOElasticBuffer iobuf,
int iobufOffset,
boolean withMagic)
Copy the contents of a packet's header and body buffers to an
IOElasticBuffer |
int |
getTo(long addr,
int addrOffset)
Copy the contents of a packet's header and body buffers to a native memory region
This method invokes
return getTo(addr, addrOffset, true)
|
int |
getTo(long addr,
int addrOffset,
boolean withMagic)
Copy the contents of a packet's header and body buffers to a native memory region
|
PktPacket |
init()
Implementation of UtlPool.Item#init.
|
int |
putFrom(ByteBuffer buf,
int bufOffset)
Copy the contents of a packet's header and body buffers from a byte buffer
|
int |
putFrom(IOBuffer iobuf,
int iobufOffset)
Copy the contents of a packet's header and body buffers from an
IOBuffer
This method invokes putFrom(iobuf, iobufOffset, false, false)
|
int |
putFrom(IOBuffer iobuf,
int iobufOffset,
boolean wrap)
Copy the contents of a packet's header and body buffers from an
IOBuffer
This method invokes putFrom(iobuf, iobufOffset, wrap, wrap)
|
int |
putFrom(IOBuffer iobuf,
int iobufOffset,
boolean wrapHeader,
boolean wrapBody)
Copy the contents of a packet's header and body buffers from an
IOBuffer |
int |
putFrom(long addr,
int addrOffset)
Copy the contents of a packet's header and body buffers from a native memory region
|
int |
putFrom(PktPacket packet)
Copy from a packet
|
UtlReferenceTracker |
referenceTracker()
Get an object's reference tracker.
|
PktPacket |
reset(boolean initBackingBuffers)
Reset a packet
|
int |
serialize(byte[] array,
int arrayOffset)
Serialize a packet to a byte array
This method invokes
serialize(array, arrayOffset, true)
|
int |
serialize(byte[] array,
int arrayOffset,
boolean withMagic)
Serialize a packet to a byte array
This method invokes syncf().getTo(array, arrayOffset, withMagic)
|
int |
serialize(ByteBuffer buf)
Serialize a packet to a byte buffer
This method invokes
serialize(buf, true)
|
int |
serialize(ByteBuffer buf,
boolean withMagic)
Serialize a packet to a byte buffer
This method invokes
serialize(buf, buf.position(), withMagic)
|
int |
serialize(ByteBuffer buf,
int bufOffset)
Serialize a packet to a byte buffer
This method invokes
serialize(buf, bufOffset, true)
|
int |
serialize(ByteBuffer buf,
int bufOffset,
boolean withMagic)
Serialize a packet to a byte buffer
This method invokes syncf().getTo(buf, bufOffset, withMagic)
|
int |
serialize(IOBuffer iobuf,
int iobufOffset)
Serialize a packet to an IO buffer
This method invokes
serialize(iobuf, iobufOffset, true)
|
int |
serialize(IOBuffer iobuf,
int iobufOffset,
boolean withMagic)
Serialize a packet to an IO buffer
This method invokes syncf().getTo(iobuf, iobufOffset, withMagic)
|
int |
serialize(IOElasticBuffer iobuf,
int iobufOffset)
Serialize a packet to an elastic IO buffer
This method invokes
serialize(iobuf, iobufOffset, true)
|
int |
serialize(IOElasticBuffer iobuf,
int iobufOffset,
boolean withMagic)
Serialize a packet to an elastic IO buffer
This method invokes syncf().getTo(iobuf, iobufOffset, withMagic)
|
int |
serialize(long addr,
int addrOffset)
Serialize a packet to a native memory region
This method invokes
serialize(addr, addrOffset, true)
|
int |
serialize(long addr,
int addrOffset,
boolean withMagic)
Serialize a packet to a native memory region
This method invokes syncf().getTo(addr, addrOffset, withMagic)
|
PktPacket |
setPool(UtlPool<PktPacket> pool)
Implementation of UtlPool.Item#setPool.
|
void |
setTag(int id,
Object tag)
Set a packet tag.
|
int |
sync()
Sync a packet's header and body
|
PktPacket |
syncf()
Sync method for use with fluent programming
|
String |
toString()
Return a string representation of the object.
|
count, insertAfter, insertBefore, isLinked, next, previous, unlink, wipepublic final PktHeader getHeader()
public final PktBody getBody()
public final void setTag(int id,
Object tag)
public final Object getTag(int id)
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.HasReferenceTrackerpublic final int getSerializedLength()
public final int sync()
Invoking this method ensures that a packet is fully serialized to it backing buffers and can be copied out
public final void desync()
public final PktPacket syncf()
This method is the same as sync() except it return this
object instead of length for fluent invocation chaining
public final int getTo(ByteBuffer buf, int bufOffset, boolean withMagic)
buf - The byte buffer to copy tobufOffset - The offset into the buffer where the serialized contents
of the packet needs to copiedwithMagic - Whether to copy the magic number or notThis method copies the contents of a packet' header and body buffers to a byte buffer. It 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 buffer.
Note:Since this method does not change any markers of the target buffer, the caller needs to ensure the buffer has enough capacity to accommodate the packet's contents. The caller can invokegetSerializedLength() to get
the length of the header's contents and use that to set the target buffer's
capacity before invoking this method.
Note:This method does not invoke sync() before doing the
copy. The caller needs to ensure that sync() is invoked prior to invoking
this method.
public final int getTo(ByteBuffer buf, int bufOffset)
This method invokes return getTo(buf, bufOffset, true)
public final int getTo(ByteBuffer buf, boolean withMagic)
This method invokes return getTo(buf, buf.position(), withMagic)
public final int getTo(ByteBuffer buf)
This method invokes return getTo(buf, true)
public final int getTo(byte[] array,
int arrayOffset,
boolean withMagic)
array - The byte array to copy toarrayOffset - The offset into the array where the serialized contents
of the packet needs to be copiedwithMagic - Whether to copy the magic number or notThis method copies the contents of a packet' header and body buffers to a byte array.
Note:The caller needs to ensure the target array has enough capacity to accommodate the packet's serialized contents. The caller can invoke thegetSerializedLength() method to get the length of the header's contents
to ensure the target array is sized correctly
Note:This method does not invoke sync() before doing the
copy. The caller needs to ensure that sync() is invoked prior to invoking
this method.
public final int getTo(byte[] array,
int arrayOffset)
This method invokes return getTo(array, arrayOffset, true)
public final int getTo(IOBuffer iobuf, int iobufOffset, boolean withMagic)
IOBufferiobuf - The IO buffer to copy toiobufOffset - The offset into the IO buffer where the serialized contents
of the packet needs to be serialized copiedwithMagic - Whether to copy the magic number or not
This method copies the contents of a packet' header and body buffers to
an IOBuffer.
getSerializedLength() method to get the length of the header's contents
to ensure the target buffer is sized correctly
Note:This method does not invoke sync() before doing the
copy. The caller needs to ensure that sync() is invoked prior to invoking
this method.
public final int getTo(IOBuffer iobuf, int iobufOffset)
IOBuffer
This method invokes return getTo(iobuf, iobufOffset, true)
public final int getTo(IOElasticBuffer iobuf, int iobufOffset, boolean withMagic)
IOElasticBufferiobuf - The IO buffer to copy toiobufOffset - The offset into the IO buffer where the serialized contents
of the packet needs to be copiedwithMagic - Whether to copy the magic number or not
This method copies the contents of a packet' header and body buffers to
an IOElasticBuffer.
sync() before doing the
copy. The caller needs to ensure that sync() is invoked prior to invoking
this method.
public final int getTo(IOElasticBuffer iobuf, int iobufOffset)
IOElasticBuffer
This method invokes return getTo(iobuf, iobufOffset, true)
public final int getTo(long addr,
int addrOffset,
boolean withMagic)
addr - The address of the native memory region to copy toaddrOffset - The offset into the memory region where the serialized
contents of the packet should be copy to.withMagic - Whether to copy the magic number or notThis method copies the contents of a packet' header and body buffers to a native memory region
Note:The caller needs to ensure the target buffer has enough capacity to accommodate the packet's serialized contents. The caller can invoke thegetSerializedLength() method to get the length of the header's contents
to ensure the target buffer is sized correctly
Note:This method does not invoke sync() before doing the
copy. The caller needs to ensure that sync() is invoked prior to invoking
this method.
public final int getTo(long addr,
int addrOffset)
This method invokes return getTo(addr, addrOffset, true)
public final int putFrom(ByteBuffer buf, int bufOffset)
buf - The byte buffer to copy frombufOffset - The offset into the buffer where the serialized packet startsThis method copies the serialized form of a packet from a byte buffer. The method first copies data from the supplied buffer to the packet header's buffer followed by to the packet body's buffer.
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.getSerializedPacketLength(java.nio.ByteBuffer, int, int)
public final int putFrom(IOBuffer iobuf, int iobufOffset, boolean wrapHeader, boolean wrapBody)
IOBufferiobuf - The IO buffer to copy fromiobufOffset - The offset into the IO buffer where the serialized packet
startswrapHeader - If true, then the deserialization process will wrap the packet header
around the supplied IO bufferwrapBody - If true, then the deserialization process will wrap the packet body's
buffer around the supplied IO buffer
This method copies the serialized form of a packet from an IOBuffer. The
method first copies data from the supplied buffer to the packet header's buffer
followed by to the packet body's buffer.
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.getSerializedPacketLength(java.nio.ByteBuffer, int, int)
public final int putFrom(IOBuffer iobuf, int iobufOffset, boolean wrap)
IOBuffer
This method invokes putFrom(iobuf, iobufOffset, wrap, wrap)
public final int putFrom(IOBuffer iobuf, int iobufOffset)
IOBuffer
This method invokes putFrom(iobuf, iobufOffset, false, false)
public final int putFrom(long addr,
int addrOffset)
addr - The address of the memory region containing the serialized packetaddrOffset - The offset into the region where the serialized packet startsThis method copies the serialized form of a packet from a native memory region. The method first copies data from the supplied region to the packet header's buffer followed by to the packet body's buffer.
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.getSerializedPacketLength(java.nio.ByteBuffer, int, int)
public final int putFrom(PktPacket packet)
This method assumes that the source packet has already been sync'd
public final int serialize(ByteBuffer buf, int bufOffset, boolean withMagic)
This method invokes syncf().getTo(buf, bufOffset, withMagic)
public final int serialize(ByteBuffer buf, int bufOffset)
This method invokes serialize(buf, bufOffset, true)
public final int serialize(ByteBuffer buf, boolean withMagic)
This method invokes serialize(buf, buf.position(), withMagic)
public final int serialize(ByteBuffer buf)
This method invokes serialize(buf, true)
public final int serialize(byte[] array,
int arrayOffset,
boolean withMagic)
This method invokes syncf().getTo(array, arrayOffset, withMagic)
public final int serialize(byte[] array,
int arrayOffset)
This method invokes serialize(array, arrayOffset, true)
public final int serialize(IOBuffer iobuf, int iobufOffset, boolean withMagic)
This method invokes syncf().getTo(iobuf, iobufOffset, withMagic)
public final int serialize(IOBuffer iobuf, int iobufOffset)
This method invokes serialize(iobuf, iobufOffset, true)
public final int serialize(IOElasticBuffer iobuf, int iobufOffset, boolean withMagic)
This method invokes syncf().getTo(iobuf, iobufOffset, withMagic)
public final int serialize(IOElasticBuffer iobuf, int iobufOffset)
This method invokes serialize(iobuf, iobufOffset, true)
public final int serialize(long addr,
int addrOffset,
boolean withMagic)
This method invokes syncf().getTo(addr, addrOffset, withMagic)
public final int serialize(long addr,
int addrOffset)
This method invokes serialize(addr, addrOffset, true)
public final int deserialize(ByteBuffer buf, int bufOffset)
This method invokes putFrom(buf, bufOffset) followed by desync()
public final int deserialize(IOBuffer iobuf, int iobufOffset, boolean wrapHeader, boolean wrapBody)
This method invokes putFrom(iobuf, iobufOffset, wrapHeader, wrapBody) followed by desync()
public final int deserialize(PktPacket packet)
public final int deserialize(IOBuffer iobuf, int iobufOffset, boolean wrap)
This method invokes deserialize(iobuf, iobufOffset, wrap, wrap)
public final int deserialize(IOBuffer iobuf, int iobufOffset)
This method invokes deserialize(iobuf, iobufOffset, false, false)
public final int deserialize(long addr,
int addrOffset)
This method invokes putFrom(addr, addrOffset) followed by desync()
public final PktPacket reset(boolean initBackingBuffers)
initializeBuffer - Whether to wipe and initialize the backing bufferpublic 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<T>)Copyright © 2019 N5 Technologies, Inc. All Rights Reserved.