com.neeve.pkt
Class PktBuffer

java.lang.Object
  extended by com.neeve.io.IOElasticBuffer
      extended by com.neeve.pkt.PktBuffer

public final class PktBuffer
extends com.neeve.io.IOElasticBuffer

Implements the buffer that backs a packet header or body.

A packet buffer serves as the backing buffer of a packet header or body. It maintains a view into an underlying IOBuffer. It holds an instance of a IOBuffer object and an offset and length that defines its window into the underlying buffer. It support 'copy on write' and 'fail on write' semantics.

A user supplied an instance of IOElasticBuffer.Sizer when creating a new packet buffer. The sizer is queried by the buffer for the entity's serialized length when it needs to create a new IO buffer. This is done implicitly by the putXXX/getXXX methods if an IO buffer has not already been created or supplied by the user via IOElasticBuffer.wrapIOBuffer(com.neeve.io.IOBuffer, int, int).

The reason why a user needs to specify whether the underlying buffer is being obtained for read or write is to to support 'copy on write' and 'fail on write' semantics. The IOElasticBuffer.setCopyOnWrite() and IOElasticBuffer.setFailOnWrite() methods mark the packet buffer as 'copy on write' and 'fail on write' respectively. A buffer marked as 'copy on write' will cause the next call to modify the length or contents of the underlying buffer to 'clone' the underlying buffer before performing the operation on it.

Threading:
As with the contained IOBuffer object, a packet buffer is not thread safe i.e. only one thread can be executing the packet buffer methods at any point in time.

Nested Class Summary
 
Nested classes/interfaces inherited from class com.neeve.io.IOElasticBuffer
com.neeve.io.IOElasticBuffer.Initializer, com.neeve.io.IOElasticBuffer.Sizer
 
Method Summary
static PktBuffer create(com.neeve.io.IOElasticBuffer.Sizer owner, int bufferLength, boolean isNative)
          Create a new packet buffer
static PktBuffer create(PktSerializable owner, int bufferLength, boolean isNative)
          Deprecated. This method has been deprecated in favor of IOElasticBuffer.create(Sizer, int, boolean)
 
Methods inherited from class com.neeve.io.IOElasticBuffer
calculateUTFLength, calculateUTFLength, clearCopyOnWrite, clearFailOnWrite, dump, ensureBackingBufferExists, fork, get, getByteOrder, getChar, getDouble, getFloat, getInitializer, getInt, getIOBuffer, getIOBufferForRead, getIOBufferForWrite, getLength, getLong, getOffset, getResumptionLength, getShort, getString, getTo, getTo, getTo, getTo, getTo, getTo, getTo, getTo, getTo, getTo, getToNative, getUnsignedByte, getUnsignedInt, getUnsignedShort, inputStream, isCopyOnWrite, isFailOnWrite, isNative, isResizeNeededFor, outputStream, put, putChar, putCharSequenceUTF, putCharUTF8, putDouble, putFloat, putFrom, putFrom, putFrom, putFrom, putFrom, putFrom, putFrom, putFrom, putFrom, putFrom, putFrom, putFromNative, putInt, putLong, putShort, putString, reset, setByteOrder, setCopyOnWrite, setFailOnWrite, setInitializer, setLength, toString, wipe, wrapIOBuffer
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

create

public static PktBuffer create(com.neeve.io.IOElasticBuffer.Sizer owner,
                               int bufferLength,
                               boolean isNative)
Create a new packet buffer

Parameters:
owner - The owner of the packet buffer
bufferLength - The length of the backing buffer. If <=0, the packet buffer will query the owner for the size.
isNative - Whether the backing IO buffer should be native or not
Returns:
Returns the created packet buffer.
Threading:
This method is safe for concurrent access by multiple threads

create

@Deprecated
public static PktBuffer create(PktSerializable owner,
                                          int bufferLength,
                                          boolean isNative)
Deprecated. This method has been deprecated in favor of IOElasticBuffer.create(Sizer, int, boolean)

Create a new packet buffer



Copyright © 2016 Neeve Research, LLC. All Rights Reserved.