class AcknowledgementsBuffer extends java.lang.Object implements ChannelDataStore, java.io.Serializable
create
methods of One2OneChannel
etc.
The getState method returns EMPTY or NONEMPTYFULL, but never FULL.
An initial size for the buffer can be specified during construction.
This buffer will save memory by changing multiple ChannelMessage.Ack messages into AcknowledgementsBuffer.Acks.
InfiniteBuffer
Modifier and Type | Class and Description |
---|---|
(package private) static class |
AcknowledgementsBuffer.Acks
Compressed form of one or more acknowledgements.
|
Modifier and Type | Field and Description |
---|---|
private AcknowledgementsBuffer.Acks |
acks
The Acks which is currently in the buffer.
|
private java.lang.Object[] |
buffer
The storage for the buffered Objects
|
private int |
counter
The number of Objects stored in the InfiniteBuffer
|
private static int |
DEFAULT_SIZE
The default size of the buffer
|
private int |
firstIndex
The index of the first element
|
private int |
initialSize
The initial size of the buffer
|
private int |
lastIndex
The index of the last element
|
EMPTY, FULL, NONEMPTYFULL
Constructor and Description |
---|
AcknowledgementsBuffer()
Construct a new InfiniteBuffer with the default size (of 8).
|
AcknowledgementsBuffer(int initialSize)
Construct a new AcknowledgementsBuffer with the specified initial size.
|
Modifier and Type | Method and Description |
---|---|
java.lang.Object |
clone()
Returns a new (and EMPTY) AcknowledgementsBuffer with the same
creation parameters as this one.
|
void |
endGet()
Ends an extended read on the buffer.
|
java.lang.Object |
get()
Returns the oldest Object from the InfiniteBuffer and removes it.
|
int |
getState()
Returns the current state of the AcknowledgementsBuffer.
|
void |
put(java.lang.Object value)
Puts a new Object into the InfiniteBuffer.
|
void |
removeAll()
Deletes all items in the buffer, leaving it empty.
|
java.lang.Object |
startGet()
Begins an extended read on the buffer, returning the data for the extended read.
|
private static final int DEFAULT_SIZE
private int initialSize
private java.lang.Object[] buffer
private int counter
private int firstIndex
private int lastIndex
private AcknowledgementsBuffer.Acks acks
AcknowledgementsBuffer()
AcknowledgementsBuffer(int initialSize)
initialSize
- the number of Objects
the AcknowledgementsBuffer can initially storepublic java.lang.Object get()
Pre-condition: getState must not currently return EMPTY.
get
in interface ChannelDataStore
public java.lang.Object startGet()
ChannelDataStore
Pre-condition: getState must not currently return EMPTY.
The exact behaviour of this method depends on your buffer. When a process performs an
extended rendezvous on a buffered channel, it will first call this method, then the
ChannelDataStore.endGet()
method.
A FIFO buffer would implement this method as returning the value from the front of the buffer and the next call would remove the value. An overflowing buffer would do the same.
However, for an overwriting buffer it is more complex. Refer to the documentation for
OverWritingBuffer.startGet()
and OverWriteOldestBuffer.startGet()
for details
startGet
in interface ChannelDataStore
ChannelDataStore.endGet()
public void endGet()
ChannelDataStore
startGet
call.
During the period between startGet
and
endGet
, it is possible that
put
will be called, but not get
.endGet
in interface ChannelDataStore
ChannelDataStore.startGet()
public void put(java.lang.Object value)
Implementation note: if InfiniteBuffer is full, a new internal buffer with double the capacity is constructed and the old data copied across.
put
in interface ChannelDataStore
value
- the Object to put into the InfiniteBufferpublic int getState()
getState
in interface ChannelDataStore
public java.lang.Object clone()
Note: Only the initial size and structure of the AcknowledgementsBuffer is cloned, not any stored data.
clone
in interface ChannelDataStore
clone
in class java.lang.Object
public void removeAll()
ChannelDataStore
removeAll
in interface ChannelDataStore