|
Errai 3.0.1-SNAPSHOT | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.jboss.errai.bus.server.io.buffers.TransmissionBuffer
public class TransmissionBuffer
A ring-based buffer implementation that provides contention-free writing of 1..n colors. In this case, colors refer to the unique attribute that separates one topic of data from another. Global data, which is visible to all topics may also be written to this buffer.
Given the ring-buffer design, data is never de-allocated from the buffer when it is no longer needed. Instead, it is assumed that old data will be consumed from the buffer before that space in the buffer is reclaimed. Since this is a multi-colored buffer, it has multiple tails -- one for each color. The amount of free space available in the buffer at any time is the delta between the head and maximum physical extent of the buffer, plus the delta from the beginning of the physical buffer in memory to the closest tail.
BufferColor
,
BufferFilter
Field Summary | |
---|---|
static int |
DEFAULT_SEGMENT_SIZE
|
static long |
STARTING_SEQUENCE
|
Method Summary | |
---|---|
void |
clear()
Clear the current buffer. |
static TransmissionBuffer |
create()
Creates a transmission buffer with the default segment and buffer size, using a regular heap allocated buffer. |
static TransmissionBuffer |
create(int segmentSize,
int segments)
Creates a heap allocated transmission buffer with a specified segment size and segments. |
static TransmissionBuffer |
createDirect()
Creates a transmission buffer with the default segment and buffer size, using a direct memory buffer. |
static TransmissionBuffer |
createDirect(int segmentSize,
int segments)
Creates a direct allocated transmission buffer with a custom segment size and segments. |
void |
dumpSegments(PrintWriter writer)
|
List<String> |
dumpSegmentsAsList()
|
int |
getBufferSize()
|
int |
getHeadPositionBytes()
|
long |
getHeadSequence()
|
int |
getSegmentSize()
|
int |
getTotalSegments()
|
boolean |
read(ByteWriteAdapter outputStream,
BufferColor bufferColor)
Reads all the available data of the specified color from the buffer into the provided OutputStream |
boolean |
read(ByteWriteAdapter outputStream,
BufferColor bufferColor,
BufferFilter callback)
Reads all the available data of the specified color from the buffer into the provided OutputStream with a provided BufferFilter . |
boolean |
read(ByteWriteAdapter outputStream,
BufferColor bufferColor,
BufferFilter callback,
long sequence)
Reads all the available data of the specified color from the buffer into the provided OutputStream with a provided BufferFilter . |
boolean |
readWait(ByteWriteAdapter outputStream,
BufferColor bufferColor)
Reads from the buffer into the provided OutputStream, waiting indefinitely for data to arrive that is relavent to the specified BufferColor |
boolean |
readWait(ByteWriteAdapter outputStream,
BufferColor bufferColor,
BufferFilter callback)
Reads from the buffer into the provided OutputStream, waiting indefinitely for data of the specified color to become available. |
boolean |
readWait(TimeUnit unit,
long time,
ByteWriteAdapter outputStream,
BufferColor bufferColor)
Reads from the buffer into the provided OutputStream, waiting up to the specified wait time for data of the specified color to become available. |
boolean |
readWait(TimeUnit unit,
long time,
ByteWriteAdapter outputStream,
BufferColor bufferColor,
BufferFilter callback)
Reads from the buffer into the provided OutputStream, waiting indefinitely for data of the specified color to become available with the provided callback. |
void |
write(InputStream inputStream,
BufferColor bufferColor)
Writes from the InputStream into the buffer. |
void |
write(int writeSize,
InputStream inputStream,
BufferColor bufferColor)
Writes from an InputStream into the buffer using the specified to allocate space
in the buffer. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final long STARTING_SEQUENCE
public static final int DEFAULT_SEGMENT_SIZE
Method Detail |
---|
public static TransmissionBuffer create()
public static TransmissionBuffer createDirect()
public static TransmissionBuffer create(int segmentSize, int segments)
segmentSize
- the size of individual segmentssegments
- the total number of segments
public static TransmissionBuffer createDirect(int segmentSize, int segments)
segmentSize
- the size of the individual segmentssegments
- the total number of segments
public void write(InputStream inputStream, BufferColor bufferColor) throws IOException
InputStream
into the buffer. Space is allocated and the data expected to be written
by checking the InputStream.available()
value.
write
in interface Buffer
inputStream
- the input stream to read into the buffer.bufferColor
- the color of the data to be inserted.
IOException
public void write(int writeSize, InputStream inputStream, BufferColor bufferColor) throws IOException
InputStream
into the buffer using the specified to allocate space
in the buffer.
write
in interface Buffer
writeSize
- the size in bytes to be allocated.inputStream
- the input stream to read into the buffer.bufferColor
- the color of the data to be inserted.
IOException
public boolean read(ByteWriteAdapter outputStream, BufferColor bufferColor) throws IOException
read
in interface Buffer
outputStream
- the OutputStream to read into.bufferColor
- the buffer color
IOException
public boolean read(ByteWriteAdapter outputStream, BufferColor bufferColor, BufferFilter callback) throws IOException
BufferFilter
.
read
in interface Buffer
outputStream
- the OutputStream to read into.bufferColor
- the buffer colorcallback
- a callback to be used during the read operation.
IOException
public boolean read(ByteWriteAdapter outputStream, BufferColor bufferColor, BufferFilter callback, long sequence) throws IOException
BufferFilter
.
read
in interface Buffer
outputStream
- the OutputStream to read into.bufferColor
- the buffer color.callback
- a callback to be used during the read operation.sequence
- the sequence number to seek from in the buffer.
IOException
public boolean readWait(ByteWriteAdapter outputStream, BufferColor bufferColor) throws InterruptedException, IOException
BufferColor
readWait
in interface Buffer
outputStream
- the OutputStream to read into.bufferColor
- the buffer color
IOException
- an IOException is thrown if there is an inability to read from the buffer or write to
the specified OuputStream
InterruptedException
- thrown if the monitor is interrupted while waiting to receive dta.public boolean readWait(TimeUnit unit, long time, ByteWriteAdapter outputStream, BufferColor bufferColor) throws IOException, InterruptedException
readWait
in interface Buffer
unit
- the unit of time that will be used as the basis for waitingtime
- the amount of time to wait in the specified unitsoutputStream
- the OutputStream to write to.bufferColor
- the buffer color
IOException
- an IOException is thrown if there is an inability to read from the buffer or write to
the specified OuputStream
InterruptedException
- thrown if the monitor is interrupted while waiting to receive dta.public boolean readWait(ByteWriteAdapter outputStream, BufferColor bufferColor, BufferFilter callback) throws IOException, InterruptedException
readWait
in interface Buffer
outputStream
- the OutputStream to write to.bufferColor
- the buffer color
IOException
- an IOException is thrown if there is an inability to read from the buffer or write to
the specified OutputStream
InterruptedException
- thrown if the monitor is interrupted while waiting to receive dta.public boolean readWait(TimeUnit unit, long time, ByteWriteAdapter outputStream, BufferColor bufferColor, BufferFilter callback) throws IOException, InterruptedException
readWait
in interface Buffer
outputStream
- the OutputStream to write to.bufferColor
- the buffer color
IOException
- an IOException is thrown if there is an inability to read from the buffer or write to
the specified OutputStream
InterruptedException
- thrown if the monitor is interrupted while waiting to receive dta.public long getHeadSequence()
getHeadSequence
in interface Buffer
public int getHeadPositionBytes()
getHeadPositionBytes
in interface Buffer
public int getBufferSize()
getBufferSize
in interface Buffer
public int getTotalSegments()
getTotalSegments
in interface Buffer
public int getSegmentSize()
getSegmentSize
in interface Buffer
public void clear()
public void dumpSegments(PrintWriter writer)
public List<String> dumpSegmentsAsList()
|
Errai 3.0.1-SNAPSHOT | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |