|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectsimtools.util.PacketBuffer
public class PacketBuffer
A packet buffer collects byte buffers identified by a common key. The byte buffers are stored in a circular array. The array size is defined by a constructor value. Optionaly a timing criterion can be used to increase this initial size until an elapsed time between the first packet and the last is reached Caution : if the packet time value is allways set to zero then this criterion is never reached (if elapsed time greater than zero) and thus it will increase the packet size for ever.
Nested Class Summary | |
---|---|
static interface |
PacketBuffer.Listener
The packet listener interface |
class |
PacketBuffer.NoSuchIndex
The exception returned in case of buffer invalid access |
Field Summary | |
---|---|
protected java.nio.ByteBuffer[] |
buffers
|
protected java.lang.Object |
key
|
protected long |
lastIndex
|
protected java.util.HashSet |
listeners
|
protected double |
minDuration
|
protected int |
minSize
|
protected int |
offset
|
protected int |
size
|
protected long |
startIndex
|
protected double[] |
time
|
Constructor Summary | |
---|---|
protected |
PacketBuffer(java.lang.Object key,
int minSize,
double minDuration)
Create a new packet buffer |
Method Summary | |
---|---|
int |
add(java.nio.ByteBuffer bb)
Add a new packet |
void |
addListener(PacketBuffer.Listener l)
Add a listener to be notified on packet reception |
java.nio.ByteBuffer |
getBuffer(long index)
Get the packet buffer |
java.lang.Object |
getKey()
Get the key common to all these packets |
long |
getLastIndex()
Last packet valid index |
int |
getOffset()
|
long |
getStartIndex()
Oldest packet valid index |
double |
getTime(long index)
Get the packet time |
void |
removeListener(PacketBuffer.Listener l)
Remove a listener |
protected void |
reset()
Reset the buffer indexes The packet ring buffer is empty after this call |
protected void |
setTime(int index,
java.nio.ByteBuffer byteBuffer)
Method setTime. |
protected void |
validation(int index)
To be overiden to provide a validation of the packet content |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected final java.lang.Object key
protected int minSize
protected double minDuration
protected int size
protected long startIndex
protected long lastIndex
protected transient java.nio.ByteBuffer[] buffers
protected transient double[] time
protected transient java.util.HashSet listeners
protected int offset
Constructor Detail |
---|
protected PacketBuffer(java.lang.Object key, int minSize, double minDuration)
key
- the packet key used by the factoryminSize
- the minimum size for the bufferminDuration
- the minimum duration (to be lower than zero if not used)Method Detail |
---|
public java.lang.Object getKey()
public int getOffset()
public int add(java.nio.ByteBuffer bb) throws PacketBufferValidationError
bb
- the packet content
PacketBufferValidationError
protected void setTime(int index, java.nio.ByteBuffer byteBuffer)
index
- The index of the PacketBuffer to set the time.byteBuffer
- The byteBuffer, could be usefull to determine the time.protected void validation(int index) throws PacketBufferValidationError
index
-
PacketBufferValidationError
public long getStartIndex()
public long getLastIndex()
public double getTime(long index) throws PacketBuffer.NoSuchIndex
index
- of the packet
PacketBuffer.NoSuchIndex
public java.nio.ByteBuffer getBuffer(long index) throws PacketBuffer.NoSuchIndex
index
-
PacketBuffer.NoSuchIndex
protected void reset()
public void addListener(PacketBuffer.Listener l)
l
- the listener to addpublic void removeListener(PacketBuffer.Listener l)
l
- the lsitener to remove
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |