aa.tool
Class TupleSpace

java.lang.Object
  extended byaa.tool.TupleSpace
Direct Known Subclasses:
PublicTupleSpace

public class TupleSpace
extends java.lang.Object

This class implements a tuple space that maintains actor tuples. An actor tuple consists of the actor name field and property fields.

History:

Version:
$Date: 2008/01/01 00:23:57 $ $Revision: 1.1 $
Author:
Myeong-Wuk Jang

Field Summary
protected  java.util.LinkedList m_llActorTuples
          A linked list of actor tuples stored in this tuple space.
 
Constructor Summary
TupleSpace()
          Constructs an tuple space.
 
Method Summary
private  boolean areTypeMatched(ActorTuple p_atTemplate, ActorTuple p_atTuple)
          Checks whether element types between the given tuple template and the given actor tuple are matched.
private  ActorTuple[] getAllImpl(ActorTuple p_atTemplate, boolean p_bRemoveFlag)
          Returns all actor tuples matched with the specified tuple template, and remove them if bRemoveFlag is true.
private  ActorTuple getImpl(ActorTuple p_atTemplate, boolean p_bRemoveFlag)
          Gets a actor tuple matched with the specified tuple template, and remove it if bRemoveFlag is true.
protected  ActorTuple[] getMatchedTupleList(ActorTuple p_atTemplate, boolean p_bActorName)
          Finds actor tuples in this tuple space matched with the specified tuple template.
private  boolean isValidDataTuple(ActorTuple p_atTuple)
          Checks whether the given actor tuple has any null element.
 ActorTuple read(ActorTuple p_atTemplate)
          Reads an actor tuple matched with the specified tuple template.
 ActorTuple[] readAll(ActorTuple p_atTemplate)
          Reads all actor tuples matched with the specified tuple template.
 void removeAll(ActorTuple p_atTemplate)
          Removes all actor tuples matched with the sepecified tuple template.
 ActorName search(ActorTuple p_atTemplate)
          Returns the actor name in an actor tuple matched with the specified tuple template.
 ActorName[] searchAll(ActorTuple p_atTemplate)
          Returns actor names in all actor tuples matched with the specified tuple template.
 ActorTuple take(ActorTuple p_atTemplate)
          Reads an actor tuple matched with the specified tuple template, and then removes it.
 ActorTuple[] takeAll(ActorTuple p_atTemplate)
          Reads all actor tuples matched with the specified tuple template, and then removes them.
 void update(ActorTuple p_atTemplate, ActorTuple p_atTuple)
          Removes actor tuples matched with the given tuple template, and then inserts an actor tuple in this tuple space.
 void write(ActorTuple p_atTuple)
          Inserts an actor tuple in this tuple space.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_llActorTuples

protected java.util.LinkedList m_llActorTuples
A linked list of actor tuples stored in this tuple space.

Constructor Detail

TupleSpace

public TupleSpace()
Constructs an tuple space.

Method Detail

isValidDataTuple

private boolean isValidDataTuple(ActorTuple p_atTuple)
Checks whether the given actor tuple has any null element.

Parameters:
p_atTuple - an actor tuple to be checked.
Returns:
true if any element of the given actur tuple is null; false otherwise.

areTypeMatched

private boolean areTypeMatched(ActorTuple p_atTemplate,
                               ActorTuple p_atTuple)
Checks whether element types between the given tuple template and the given actor tuple are matched.

Parameters:
p_atTemplate - a tuple template to be used for matching with actor tuples in this tuple space.
p_atTuple - an actor tuple to be stored in this tuple space.
Returns:
true if element types between the given tuple template and the given actor tuple are matched; false otherwise.

getMatchedTupleList

protected ActorTuple[] getMatchedTupleList(ActorTuple p_atTemplate,
                                           boolean p_bActorName)
                                    throws TupleSpaceException
Finds actor tuples in this tuple space matched with the specified tuple template.

Parameters:
p_atTemplate - a tuple template to be used for matching with actor tuples in this tuple space.
p_bActorName - the flag to decide whethter ActorName will be checked or not.
Returns:
actor tuples matched with the specified tuple tempmlate.
Throws:
TupleSpaceException - if the given tuple template is null.

getImpl

private ActorTuple getImpl(ActorTuple p_atTemplate,
                           boolean p_bRemoveFlag)
                    throws TupleSpaceException
Gets a actor tuple matched with the specified tuple template, and remove it if bRemoveFlag is true.

Parameters:
p_atTemplate - a tuple template to be used for matching with actor tuples in this tuple space.
p_bRemoveFlag - the flag to remove a tuple after the tuple is retrieved.
Returns:
an actor tuple matched with the specified tuple template.
Throws:
TupleSpaceException - if this tuple space cannot find any actor tuple that are matched with the specified tuple template.

getAllImpl

private ActorTuple[] getAllImpl(ActorTuple p_atTemplate,
                                boolean p_bRemoveFlag)
                         throws TupleSpaceException
Returns all actor tuples matched with the specified tuple template, and remove them if bRemoveFlag is true.

Parameters:
p_atTemplate - a tuple template to be used for matching with actor tuples in this tuple space.
p_bRemoveFlag - the flag to remove actor tuples after they are retrieved.
Returns:
actor tuples matched with the specified tuple template.
Throws:
TupleSpaceException - if this tuple space cannot find any actor tuple.

write

public void write(ActorTuple p_atTuple)
           throws TupleSpaceException
Inserts an actor tuple in this tuple space.

Parameters:
p_atTuple - an actor tuple to be stored in this tuple space.
Throws:
TupleSpaceException - either if the actor tuple is invalid or if the same actor tuple already exits in this tuple space.

read

public final ActorTuple read(ActorTuple p_atTemplate)
                      throws TupleSpaceException
Reads an actor tuple matched with the specified tuple template.

Parameters:
p_atTemplate - a tuple template to be used for matching with actor tuples in this tuple space.
Returns:
an actor tuple matched with the specified tuple template.
Throws:
TupleSpaceException - if this tuple space cannot find any actor tuple that are matched with the specified tuple template.

readAll

public final ActorTuple[] readAll(ActorTuple p_atTemplate)
                           throws TupleSpaceException
Reads all actor tuples matched with the specified tuple template.

Parameters:
p_atTemplate - a tuple template to be used for matching with actor tuples in this tuple space.
Returns:
all actor tuples matched with the specified tuple template.
Throws:
TupleSpaceException - if this tuple space cannot find any actor tuple that are matched with the specified tuple template.

take

public ActorTuple take(ActorTuple p_atTemplate)
                throws TupleSpaceException
Reads an actor tuple matched with the specified tuple template, and then removes it.

Parameters:
p_atTemplate - a tuple template to be used for matching with actor tuples in this tuple space.
Returns:
an actor tuple matched with the specified tuple template.
Throws:
TupleSpaceException - if this tuple space cannot find any actor tuple that are matched with the specified tuple template.

takeAll

public ActorTuple[] takeAll(ActorTuple p_atTemplate)
                     throws TupleSpaceException
Reads all actor tuples matched with the specified tuple template, and then removes them.

Parameters:
p_atTemplate - a tuple template to be used for matching with actor tuples in this tuple space.
Returns:
actor tuples matched with the specified tuple template.
Throws:
TupleSpaceException - if this tuple space cannot find any actor tuple that are matched with the specified tuple template.

update

public void update(ActorTuple p_atTemplate,
                   ActorTuple p_atTuple)
            throws TupleSpaceException
Removes actor tuples matched with the given tuple template, and then inserts an actor tuple in this tuple space.

Parameters:
p_atTemplate - a tuple template to be used for matching with actor tuples in this tuple space.
p_atTuple - an actor tuple to be stored in this tuple space.
Throws:
TupleSpaceException - either if the actor tuple is invalid or if the type of an element in the given actor tuple is not matched with the type of the corresponding element in the given tuple template.

removeAll

public void removeAll(ActorTuple p_atTemplate)
               throws TupleSpaceException
Removes all actor tuples matched with the sepecified tuple template.

Parameters:
p_atTemplate - a tuple template to be used for matching with actor tuples in this tuple space.
Throws:
TupleSpaceException - if this tuple space cannot find any actor tuple that are matched with the specified tuple template.

search

public final ActorName search(ActorTuple p_atTemplate)
                       throws TupleSpaceException
Returns the actor name in an actor tuple matched with the specified tuple template.

Parameters:
p_atTemplate - a tuple template to be used for matching with actor tuples in this tuple space.
Returns:
the actor name in an actor tuple matched with the specified tuple template.
Throws:
TupleSpaceException - if this tuple space cannot find any actor tuple that are matched with the specified tuple template.

searchAll

public final ActorName[] searchAll(ActorTuple p_atTemplate)
                            throws TupleSpaceException
Returns actor names in all actor tuples matched with the specified tuple template.

Parameters:
p_atTemplate - a tuple template to be used for matching with actor tuples in this tuple space.
Returns:
actor names in all actor tuples matched with the specified tuple template.
Throws:
TupleSpaceException - if this tuple space cannot find any actor tuple that are matched with the specified tuple template.