CSP for Java
(JCSP) 1.0-rc4

jcsp.util
Class Buffer

java.lang.Object
  |
  +--jcsp.util.Buffer
All Implemented Interfaces:
ChannelDataStore, Cloneable, Serializable

public class Buffer
extends Object
implements ChannelDataStore, Serializable

This is used to create a buffered object channel that never loses data.

Description

Buffer is an implementation of ChannelDataStore that yields a blocking FIFO buffered semantics for a channel. See the static create methods of One2OneChannel etc.

The getState method returns EMPTY, NONEMPTYFULL or FULL according to the state of the buffer.

Author:
P.D.Austin
See Also:
ZeroBuffer, OverWriteOldestBuffer, OverWritingBuffer, OverFlowingBuffer, InfiniteBuffer, One2OneChannel, Any2OneChannel, One2AnyChannel, Any2AnyChannel, Serialized Form

Fields inherited from interface jcsp.util.ChannelDataStore
EMPTY, FULL, NONEMPTYFULL
 
Constructor Summary
Buffer(int size)
          Construct a new Buffer with the specified size.
 
Method Summary
 Object clone()
          Returns a new (and EMPTY) Buffer with the same creation parameters as this one.
 Object get()
          Returns the oldest Object from the Buffer and removes it.
 int getState()
          Returns the current state of the Buffer.
 void put(Object value)
          Puts a new Object into the Buffer.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Buffer

public Buffer(int size)
Construct a new Buffer with the specified size.
Parameters:
size - the number of Objects the Buffer can store.
Throws:
BufferSizeError - if size is negative. Note: no action should be taken to try/catch this exception - application code generating it is in error and needs correcting.
Method Detail

get

public Object get()
Returns the oldest Object from the Buffer and removes it.

Pre-condition: getState must not currently return EMPTY.

Specified by:
get in interface ChannelDataStore
Returns:
the oldest Object from the Buffer

put

public void put(Object value)
Puts a new Object into the Buffer.

Pre-condition: getState must not currently return FULL.

Specified by:
put in interface ChannelDataStore
Parameters:
value - the Object to put into the Buffer

getState

public int getState()
Returns the current state of the Buffer.
Specified by:
getState in interface ChannelDataStore
Returns:
the current state of the Buffer (EMPTY, NONEMPTYFULL or FULL)

clone

public Object clone()
Returns a new (and EMPTY) Buffer with the same creation parameters as this one.

Note: Only the size and structure of the Buffer is cloned, not any stored data.

Specified by:
clone in interface ChannelDataStore
Overrides:
clone in class Object
Returns:
the cloned instance of this Buffer

CSP for Java
(JCSP) 1.0-rc4

Submit a bug or feature to jcsp-team@ukc.ac.uk
Version 1.0-rc4 of the JCSP API Specification (Copyright 1997-2000 P.D.Austin and P.H.Welch - All Rights Reserved)
Java is a trademark or registered trademark of Sun Microsystems, Inc. in the US and other countries.