Class AcknowledgementsBuffer
- java.lang.Object
-
- org.jcsp.net.AcknowledgementsBuffer
-
- All Implemented Interfaces:
java.io.Serializable
,java.lang.Cloneable
,ChannelDataStore
class AcknowledgementsBuffer extends java.lang.Object implements ChannelDataStore, java.io.Serializable
This is used to create a buffered object channel that always accepts and never loses any input.Description
AcknowledgementsBuffer is an implementation of ChannelDataStore that yields a FIFO buffered semantics for a channel. When empty, the channel blocks readers. However, its capacity is infinite (expanding to whatever is needed so far as the underlying memory system will permit). So, it never gets full and blocks a writer. See the staticcreate
methods ofOne2OneChannel
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.
- See Also:
InfiniteBuffer
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static class
AcknowledgementsBuffer.Acks
Compressed form of one or more acknowledgements.
-
Field Summary
Fields Modifier and Type Field Description private AcknowledgementsBuffer.Acks
acks
The Acks which is currently in the buffer.private java.lang.Object[]
buffer
The storage for the buffered Objectsprivate int
counter
The number of Objects stored in the InfiniteBufferprivate static int
DEFAULT_SIZE
The default size of the bufferprivate int
firstIndex
The index of the first elementprivate int
initialSize
The initial size of the bufferprivate int
lastIndex
The index of the last element-
Fields inherited from interface org.jcsp.util.ChannelDataStore
EMPTY, FULL, NONEMPTYFULL
-
-
Constructor Summary
Constructors Constructor Description AcknowledgementsBuffer()
Construct a new InfiniteBuffer with the default size (of 8).AcknowledgementsBuffer(int initialSize)
Construct a new AcknowledgementsBuffer with the specified initial size.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method 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.
-
-
-
Field Detail
-
DEFAULT_SIZE
private static final int DEFAULT_SIZE
The default size of the buffer- See Also:
- Constant Field Values
-
initialSize
private int initialSize
The initial size of the buffer
-
buffer
private java.lang.Object[] buffer
The storage for the buffered Objects
-
counter
private int counter
The number of Objects stored in the InfiniteBuffer
-
firstIndex
private int firstIndex
The index of the first element
-
lastIndex
private int lastIndex
The index of the last element
-
acks
private AcknowledgementsBuffer.Acks acks
The Acks which is currently in the buffer.
-
-
Constructor Detail
-
AcknowledgementsBuffer
AcknowledgementsBuffer()
Construct a new InfiniteBuffer with the default size (of 8).
-
AcknowledgementsBuffer
AcknowledgementsBuffer(int initialSize)
Construct a new AcknowledgementsBuffer with the specified initial size.- Parameters:
initialSize
- the number of Objects the AcknowledgementsBuffer can initially store
-
-
Method Detail
-
get
public java.lang.Object get()
Returns the oldest Object from the InfiniteBuffer and removes it.Pre-condition: getState must not currently return EMPTY.
- Specified by:
get
in interfaceChannelDataStore
- Returns:
- the oldest Object from the InfiniteBuffer
-
startGet
public java.lang.Object startGet()
Description copied from interface:ChannelDataStore
Begins an extended read on the buffer, returning the data for the extended read.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()
andOverWriteOldestBuffer.startGet()
for details- Specified by:
startGet
in interfaceChannelDataStore
- Returns:
- The object to be read from the channel at the beginning of the extended rendezvous
- See Also:
ChannelDataStore.endGet()
-
endGet
public void endGet()
Description copied from interface:ChannelDataStore
Ends an extended read on the buffer. The channels guarantee that this method will be called exactly once after each
call. During the period betweenstartGet
andstartGet
, it is possible thatendGet
will be called, but notput
.get
- Specified by:
endGet
in interfaceChannelDataStore
- See Also:
ChannelDataStore.startGet()
-
put
public void put(java.lang.Object value)
Puts a new Object into the InfiniteBuffer.Implementation note: if InfiniteBuffer is full, a new internal buffer with double the capacity is constructed and the old data copied across.
- Specified by:
put
in interfaceChannelDataStore
- Parameters:
value
- the Object to put into the InfiniteBuffer
-
getState
public int getState()
Returns the current state of the AcknowledgementsBuffer.- Specified by:
getState
in interfaceChannelDataStore
- Returns:
- the current state of the AcknowledgementsBuffer (EMPTY or NONEMPTYFULL)
-
clone
public java.lang.Object clone()
Returns a new (and EMPTY) AcknowledgementsBuffer with the same creation parameters as this one.Note: Only the initial size and structure of the AcknowledgementsBuffer is cloned, not any stored data.
- Specified by:
clone
in interfaceChannelDataStore
- Overrides:
clone
in classjava.lang.Object
- Returns:
- the cloned instance of this AcknowledgementsBuffer.
-
removeAll
public void removeAll()
Description copied from interface:ChannelDataStore
Deletes all items in the buffer, leaving it empty.- Specified by:
removeAll
in interfaceChannelDataStore
-
-