Package org.jcsp.util
Class ZeroBuffer<T>
- java.lang.Object
-
- org.jcsp.util.ZeroBuffer<T>
-
- All Implemented Interfaces:
Serializable
,Cloneable
,ChannelDataStore<T>
public class ZeroBuffer<T> extends Object implements ChannelDataStore<T>, Serializable
This is used to create a zero-buffered object channel that never loses data.Description
ZeroBuffer is an implementation of ChannelDataStore that yields the standard CSP semantics for a channel -- that is zero buffered with direct synchronisation between reader and writer. Unless specified otherwise, this is the default behaviour for channels. See the static construction methods ofChannel
(Channel.one2one(org.jcsp.util.ChannelDataStore)
etc.).The getState method will return FULL if there is an output waiting on the channel and EMPTY if there is not.
- Author:
- P.D. Austin
- See Also:
Buffer
,OverWriteOldestBuffer
,OverWritingBuffer
,OverFlowingBuffer
,InfiniteBuffer
,One2OneChannelImpl
,Any2OneChannelImpl
,One2AnyChannelImpl
,Any2AnyChannelImpl
, Serialized Form
-
-
Field Summary
-
Fields inherited from interface org.jcsp.util.ChannelDataStore
EMPTY, FULL, NONEMPTYFULL
-
-
Constructor Summary
Constructors Constructor Description ZeroBuffer()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Object
clone()
Returns a new (and EMPTY) ZeroBuffer with the same creation parameters as this one.void
endGet()
Ends the extended rendezvous by clearing the buffer.T
get()
Returns the Object from the ZeroBuffer.int
getState()
Returns the current state of the ZeroBuffer.void
put(T value)
Puts a new Object into the ZeroBuffer.void
removeAll()
Deletes all items in the buffer, leaving it empty.T
startGet()
Begins an extended rendezvous - simply returns the next object in the buffer.
-
-
-
Method Detail
-
get
public T get()
Returns the Object from the ZeroBuffer.Pre-condition: getState must not currently return EMPTY.
- Specified by:
get
in interfaceChannelDataStore<T>
- Returns:
- the Object from the ZeroBuffer
-
startGet
public T startGet()
Begins an extended rendezvous - simply returns the next object in the buffer. This function does not remove the object. Pre-condition: getState must not currently return EMPTY.- Specified by:
startGet
in interfaceChannelDataStore<T>
- Returns:
- The object in the buffer.
- See Also:
ChannelDataStore.endGet()
-
endGet
public void endGet()
Ends the extended rendezvous by clearing the buffer.- Specified by:
endGet
in interfaceChannelDataStore<T>
- See Also:
ChannelDataStore.startGet()
-
put
public void put(T value)
Puts a new Object into the ZeroBuffer.Pre-condition: getState must not currently return FULL.
- Specified by:
put
in interfaceChannelDataStore<T>
- Parameters:
value
- the Object to put into the ZeroBuffer
-
getState
public int getState()
Returns the current state of the ZeroBuffer.- Specified by:
getState
in interfaceChannelDataStore<T>
- Returns:
- the current state of the ZeroBuffer (EMPTY or FULL)
-
clone
public Object clone()
Returns a new (and EMPTY) ZeroBuffer with the same creation parameters as this one.Note: Only the size and structure of the ZeroBuffer is cloned, not any stored data.
- Specified by:
clone
in interfaceChannelDataStore<T>
- Overrides:
clone
in classObject
- Returns:
- the cloned instance of this ZeroBuffer.
-
removeAll
public void removeAll()
Description copied from interface:ChannelDataStore
Deletes all items in the buffer, leaving it empty.- Specified by:
removeAll
in interfaceChannelDataStore<T>
-
-