net.sf.tuplespace.simple
Class SimpleTupleSpace

java.lang.Object
  extended bynet.sf.tuplespace.simple.SimpleTupleSpace
All Implemented Interfaces:
TupleSpace

public final class SimpleTupleSpace
extends Object
implements TupleSpace

Implements an unbounded TupleSpace.

Objects can be added until memory is exhausted. The space is implemented as a LinkedList.

This implementation does not guarantee object liveliness or content. You should use external synchronization if this might be a problem.


Field Summary
protected  org.apache.commons.logging.Log logger
           
 
Constructor Summary
SimpleTupleSpace()
           
 
Method Summary
 void addToSpace(Tuple tuple)
          Adds tuple to the space.
static void checkTemplate(Template template)
          Assert that the Template is non-null.
static void checkTuple(Tuple tuple)
          Assert that the Tuple is non-null.
 Tuple readAndRemove(Template template)
          Blocks until a Tuple matching Template is available.
 Tuple readAndRemoveWithTimeout(Template template, long timeout)
          Blocks for a maximum of timeout milliseconds, until a Tuple matching Template is available.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

protected final org.apache.commons.logging.Log logger
Constructor Detail

SimpleTupleSpace

public SimpleTupleSpace()
Method Detail

addToSpace

public void addToSpace(Tuple tuple)
Description copied from interface: TupleSpace
Adds tuple to the space.

When this method returns, the tuple will have been made available to other objects waiting for a Template matching this tuple.

This method does not block.

Specified by:
addToSpace in interface TupleSpace
Parameters:
tuple - The tuple being offered to other objects.

readAndRemove

public Tuple readAndRemove(Template template)
                    throws InterruptedWhileWaitingException
Description copied from interface: TupleSpace
Blocks until a Tuple matching Template is available.

Specified by:
readAndRemove in interface TupleSpace
Parameters:
template - A template, describing what the caller would like to retrieve from the space.
Returns:
The tuple retrieved from the space.
Throws:
InterruptedWhileWaitingException - When an InterruptedException is thrown while waiting.

readAndRemoveWithTimeout

public Tuple readAndRemoveWithTimeout(Template template,
                                      long timeout)
                               throws InterruptedWhileWaitingException
Description copied from interface: TupleSpace
Blocks for a maximum of timeout milliseconds, until a Tuple matching Template is available.

If timeout is lower than or equal to zero, the method will not block, and will immediately return the tuple, or null.

Since Java's time resolution is poor, the actual timeout might be different. Implementors should guarantee a minimum timeout at least equal to timeout, but might not be able to guarantee the actual maximum time.

Specified by:
readAndRemoveWithTimeout in interface TupleSpace
Parameters:
template - A template, describing what the caller would like to retrieve from the space.
timeout - The maximum number of milliseconds to block.
Returns:
The tuple retrieved from the space, or null if none could be found before the timeout was reached.
Throws:
InterruptedWhileWaitingException - When an InterruptedException is thrown while waiting.
See Also:
TupleSpace.readAndRemove(net.sf.tuplespace.Template)

checkTuple

public static final void checkTuple(Tuple tuple)
Assert that the Tuple is non-null.

Parameters:
tuple - The tuple to check.
Throws:
IllegalArgumentException - If tuple is null.

checkTemplate

public static final void checkTemplate(Template template)
Assert that the Template is non-null.

Parameters:
template - The template to check.
Throws:
IllegalArgumentException - If template is null.