|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectsimtools.util.StreamMemoryBuffer
public class StreamMemoryBuffer
A memory buffer to be filled by one writer and read by several readers The readers do not empty the buffer, they acces data in it using an index The writer is filling the circular buffer it writes at a given index and increments a minimum index value to prevent access from the readers on overwritten data due to the cyclic buffer. Thus the writer is never constrained by the readers. The readers have to be fast enough to read the buffer. The buffer is allocated into native memory and thus can be quite large. This implementation is based on the assumption that packets size has a maximum value and that the minimum value is not too much different from the maximum value. If not efficient in terms of memory usage, it is assumed that a subclass will manage it.
Nested Class Summary | |
---|---|
class |
StreamMemoryBuffer.StreamReader
A buffer reader |
Field Summary | |
---|---|
protected java.nio.ByteBuffer |
buffer
The memory circular buffer |
protected long |
bufferSize
The size of the circular buffer= number of packets in memory |
protected int |
counter
The numbe of times the circular buffer is filled (starting at 1) |
protected long |
index
The index of the next packet to be written |
protected int[] |
lengths
A circular array with packets length |
protected long |
minIndex
The last availble packet index (-1 at the beginning) |
protected int |
streamMaxSize
The maximum size for one packet |
protected java.lang.Object |
synchro
A syncho to allow readers to synchrosize on the buffer updates |
Constructor Summary | |
---|---|
StreamMemoryBuffer(int bufferSize,
int streamMaxSize)
Create a new memory buffer |
Method Summary | |
---|---|
void |
clean()
Clean the StreamMemoryBuffer |
StreamMemoryBuffer.StreamReader |
createReader()
Create a reader on this buffer This method is overwritten to implement specific readers |
long |
write(byte[] b,
int offset,
int length)
Write a packet into the buffer |
long |
write(java.nio.ByteBuffer b)
Write a byte buffer into the buffer |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected java.nio.ByteBuffer buffer
protected int[] lengths
protected final long bufferSize
protected final int streamMaxSize
protected long index
protected long minIndex
protected int counter
protected java.lang.Object synchro
Constructor Detail |
---|
public StreamMemoryBuffer(int bufferSize, int streamMaxSize)
bufferSize
- the number of packets to storestreamMaxSize
- the max size for one packetMethod Detail |
---|
public long write(byte[] b, int offset, int length)
b
- The array from which bytes are to be readoffset
- The offset within the array of the first byte to be readlength
- The number of bytes to be read from the given array
public long write(java.nio.ByteBuffer b)
b
- the byte buffer
public StreamMemoryBuffer.StreamReader createReader()
public void clean()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |