public class ByteBufferItem
extends java.lang.Object
ByteBufferSupply
class
to provide a very fast supply of ByteBuffer objects for reuse. Objects of
this class are used to populate the ring buffer in ByteBufferSupply.
Uses the Disruptor software package.Modifier and Type | Field and Description |
---|---|
int |
myIndex
Auxiliary integer storage.
|
Constructor and Description |
---|
ByteBufferItem(java.nio.ByteBuffer templateBuf,
boolean orderedRelease,
int myId)
Constructor used to initially fill each ByteBufferItem of a ByteBufferSupply
with a copy of a template buffer.
|
ByteBufferItem(int bufferSize,
java.nio.ByteOrder order,
boolean direct,
boolean orderedRelease,
int myId)
Constructor.
|
ByteBufferItem(int bufferSize,
java.nio.ByteOrder order,
boolean direct,
boolean orderedRelease,
int myId,
java.lang.Object auxObject,
int auxIndex)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
addUsers(int additionalUsers)
If a reference to this ByteBufferItem is copied, then it is necessary to increase
the number of users.
|
(package private) boolean |
decrementCounter()
Called by buffer user by way of
ByteBufferSupply.release(ByteBufferItem)
if no longer using it so it may be reused later. |
void |
ensureCapacity(int capacity)
Make sure the buffer is the size needed.
|
java.nio.ByteBuffer |
getBuffer()
Get the contained ByteBuffer.
|
java.nio.ByteBuffer |
getBufferAsIs()
Get the contained ByteBuffer without any modifications.
|
int |
getBufferSize()
Get the size in bytes of the contained ByteBuffer.
|
long |
getConsumerSequence()
Get the sequence of this item for consumer.
|
boolean |
getForce()
Get the flag used to suggest a forced write to a consumer.
|
int |
getMyId()
Get the unique id of this object.
|
java.lang.Object |
getMyObject()
Get the auxiliary object.
|
long |
getProducerSequence()
Get the sequence of this item for producer.
|
boolean |
getUserBoolean()
Get the user boolean.
|
int |
getUserInt()
Get the user integer.
|
int |
getUsers()
Get the number of users of this buffer.
|
boolean |
isDirect()
Is this a direct buffer or not?
|
boolean |
isFromConsumerGet()
Was this item obtained through a call to consumerGet()?
|
void |
reset()
Method to reset this item each time it is retrieved from the supply.
|
void |
setConsumerSequence(long sequence)
Set the sequence of this item for consumer.
|
void |
setForce(boolean force)
Set the flag used to suggest a forced write to a consumer.
|
void |
setFromConsumerGet(boolean fromConsumerGet)
Set whether this item was obtained through a call to consumerGet().
|
void |
setMyObject(java.lang.Object obj)
Set the auxiliary object.
|
void |
setProducerSequence(long sequence)
Set the sequence of this item for producer.
|
void |
setUserBoolean(boolean bool)
Set user boolean.
|
void |
setUserInt(int i)
Set the user integer.
|
void |
setUsers(int users)
Set the number of users of this buffer.
|
ByteBufferItem(int bufferSize, java.nio.ByteOrder order, boolean direct, boolean orderedRelease, int myId)
bufferSize
- size in bytes of ByteBuffer to construct.order
- byte order of ByteBuffer to construct.direct
- is the buffer direct (in memory not managed by JVM) or not.orderedRelease
- if true, release ByteBufferItems in same order as acquired.myId
- unique id of this object.ByteBufferItem(int bufferSize, java.nio.ByteOrder order, boolean direct, boolean orderedRelease, int myId, java.lang.Object auxObject, int auxIndex)
bufferSize
- size in bytes of ByteBuffer to construct.order
- byte order of ByteBuffer to construct.direct
- is the buffer direct (in memory not managed by JVM) or not.orderedRelease
- if true, release ByteBufferItems in same order as acquired.myId
- unique id of this object.auxObject
- auxiliary object to store.auxIndex
- auxiliary integer to store.ByteBufferItem(java.nio.ByteBuffer templateBuf, boolean orderedRelease, int myId)
templateBuf
- this item's buffer is a copy this of template ByteBuffer.orderedRelease
- if true, release ByteBufferItems in same order as acquired.myId
- unique id of this object.public void reset()
public int getMyId()
public java.lang.Object getMyObject()
public void setMyObject(java.lang.Object obj)
obj
- auxiliary object.public boolean isDirect()
true
if direct buffer, else false
.public boolean getForce()
public void setForce(boolean force)
force
- flag used to suggest a forced write to a consumer.public boolean isFromConsumerGet()
true
only if item obtained through a call to consumerGet().public void setFromConsumerGet(boolean fromConsumerGet)
fromConsumerGet
- true
only if item obtained through
a call to consumerGet().public int getUserInt()
public void setUserInt(int i)
i
- user integer.public boolean getUserBoolean()
public void setUserBoolean(boolean bool)
bool
- user boolean.public long getProducerSequence()
public void setProducerSequence(long sequence)
sequence
- sequence of this item for producer.public long getConsumerSequence()
public void setConsumerSequence(long sequence)
sequence
- sequence of this item for consumer.public int getBufferSize()
public java.nio.ByteBuffer getBuffer()
public java.nio.ByteBuffer getBufferAsIs()
public void ensureCapacity(int capacity)
capacity
- minimum necessary size of buffer in bytes.public void setUsers(int users)
users
- number of buffer userspublic int getUsers()
boolean decrementCounter()
ByteBufferSupply.release(ByteBufferItem)
if no longer using it so it may be reused later.true
if no one using buffer now, else false
.public void addUsers(int additionalUsers)
additionalUsers
- number of users to add