Class TupleSpace
- java.lang.Object
-
- astra.core.Module
-
- astra.util.TupleSpace
-
public class TupleSpace extends Module
This class implements an in JVM tuple space.Tuple spaces are shared spaces are an alternative (to message passing) mechanism for implementing coordination mechanisms in multi-agent systems. This class implements an in JVM tuple space.
To use this class, you will need to import this class and add it as a module:
package ts;
import astra.util.TupleSpace;
agent Template {
module TupleSpace ts;
}
- Author:
- Rem Collier
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class astra.core.Module
Module.ACTION, Module.EVENT, Module.FORMULA, Module.SENSOR, Module.SUPPRESS_NOTIFICATIONS, Module.TERM
-
-
Constructor Summary
Constructors Constructor Description TupleSpace()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description BooleangetBoolean(String id, String key)Term to retrieve a boolean from a space stored under a given keychargetChar(String id, String key)Term to retrieve a char from a space stored under a given keyDoublegetDouble(String id, String key)Term to retrieve a double from a space stored under a given keyFloatgetFloat(String id, String key)Term to retrieve a float from a space stored under a given keyIntegergetInt(String id, String key)Term to retrieve an int from a space stored under a given keyListTermgetList(String id, String key)Term to retrieve a list from a space stored under a given keyLonggetLong(String id, String key)Term to retrieve a long from a space stored under a given keyObjectgetObject(String id, String key)Term to retrieve an object from a space stored under a given keyListTermgetSpaceList()Return a list of the spaces that the agent has joined.StringgetString(String id, String key)Term to retrieve a string from a space stored under a given keyFormulahasSpace(String id)Formula to check whether a space existsFormulahasTuple(String id, String key)Formula to check whether a space contains a keybooleanjoin(String id)Action that lets the agent join a tuple spacebooleanleave(String id)Action for an agent to leave a tuple spacebooleanpost(String id, String key, boolean value)Action to post a boolean to the specified space.booleanpost(String id, String key, char value)Action to post a char to the specified space.booleanpost(String id, String key, double value)Action to post an double to the specified space.booleanpost(String id, String key, float value)Action to post an float bject to the specified space.booleanpost(String id, String key, int value)Action to post an int to the specified space.booleanpost(String id, String key, long value)Action to post an long to the specified space.booleanpost(String id, String key, ListTerm value)Action to post an list to the specified space.booleanpost(String id, String key, Object value)Action to post an object to the specified space.booleanpost(String id, String key, String value)Action to post a string to the specified space.
-
-
-
Method Detail
-
join
public boolean join(String id)
Action that lets the agent join a tuple spaceThis action should be used to connect an agent to a tuple space. If a tuple space with the given id exists, then the agent joins that space, alternatively, the space is first created and then the agent joins it.
- Parameters:
id- the id of the tuple space that the agent is to join.- Returns:
- true if the action succeeds, false otherwise
-
leave
public boolean leave(String id)
Action for an agent to leave a tuple spaceThis action should be used when an agent wants to leave a tuple space. If the tuple space is empty after the agent has left, then the space is deleted.
This action fails if:
- The space does not exist.
- The agent is not in the space.
- Parameters:
id- the id of the space.- Returns:
- true if the action succeeds, false otherwise
-
post
public boolean post(String id, String key, Object value)
Action to post an object to the specified space.This action will fail if the space does not exist.
- Parameters:
id- the space idkey- the key that the object will be stored undervalue- the object- Returns:
- true if the action succeeds, false otherwise
-
post
public boolean post(String id, String key, String value)
Action to post a string to the specified space.This action will fail if the space does not exist.
- Parameters:
id- the space idkey- the key that the string will be stored undervalue- the string- Returns:
- true if the action succeeds, false otherwise
-
post
public boolean post(String id, String key, int value)
Action to post an int to the specified space.This action will fail if the space does not exist.
- Parameters:
id- the space idkey- the key that the int will be stored undervalue- the int- Returns:
- true if the action succeeds, false otherwise
-
post
public boolean post(String id, String key, long value)
Action to post an long to the specified space.This action will fail if the space does not exist.
- Parameters:
id- the space idkey- the key that the long will be stored undervalue- the long- Returns:
- true if the action succeeds, false otherwise
-
post
public boolean post(String id, String key, float value)
Action to post an float bject to the specified space.This action will fail if the space does not exist.
- Parameters:
id- the space idkey- the key that the float will be stored undervalue- the float- Returns:
- true if the action succeeds, false otherwise
-
post
public boolean post(String id, String key, double value)
Action to post an double to the specified space.This action will fail if the space does not exist.
- Parameters:
id- the space idkey- the key that the double will be stored undervalue- the double- Returns:
- true if the action succeeds, false otherwise
-
post
public boolean post(String id, String key, char value)
Action to post a char to the specified space.This action will fail if the space does not exist.
- Parameters:
id- the space idkey- the key that the char will be stored undervalue- the char- Returns:
- true if the action succeeds, false otherwise
-
post
public boolean post(String id, String key, boolean value)
Action to post a boolean to the specified space.This action will fail if the space does not exist.
- Parameters:
id- the space idkey- the key that the boolean will be stored undervalue- the boolean- Returns:
- true if the action succeeds, false otherwise
-
post
public boolean post(String id, String key, ListTerm value)
Action to post an list to the specified space.This action will fail if the space does not exist.
- Parameters:
id- the space idkey- the key that the list will be stored undervalue- the list- Returns:
- true if the action succeeds, false otherwise
-
getString
public String getString(String id, String key)
Term to retrieve a string from a space stored under a given keyThis term fails if there is not tuple space with the given id.
- Parameters:
id- the space idkey- the key that the value is stored under- Returns:
- the value associated with key
-
getInt
public Integer getInt(String id, String key)
Term to retrieve an int from a space stored under a given keyThis term fails if there is not tuple space with the given id.
- Parameters:
id- the space idkey- the key that the value is stored under- Returns:
- the value associated with key
-
getLong
public Long getLong(String id, String key)
Term to retrieve a long from a space stored under a given keyThis term fails if there is not tuple space with the given id.
- Parameters:
id- the space idkey- the key that the value is stored under- Returns:
- the value associated with key
-
getFloat
public Float getFloat(String id, String key)
Term to retrieve a float from a space stored under a given keyThis term fails if there is not tuple space with the given id.
- Parameters:
id- the space idkey- the key that the value is stored under- Returns:
- the value associated with key
-
getDouble
public Double getDouble(String id, String key)
Term to retrieve a double from a space stored under a given keyThis term fails if there is not tuple space with the given id.
- Parameters:
id- the space idkey- the key that the value is stored under- Returns:
- the value associated with key
-
getList
public ListTerm getList(String id, String key)
Term to retrieve a list from a space stored under a given keyThis term fails if there is not tuple space with the given id.
- Parameters:
id- the space idkey- the key that the value is stored under- Returns:
- the value associated with key
-
getObject
public Object getObject(String id, String key)
Term to retrieve an object from a space stored under a given keyThis term fails if there is not tuple space with the given id.
- Parameters:
id- the space idkey- the key that the value is stored under- Returns:
- the value associated with key
-
getChar
public char getChar(String id, String key)
Term to retrieve a char from a space stored under a given keyThis term fails if there is not tuple space with the given id.
- Parameters:
id- the space idkey- the key that the value is stored under- Returns:
- the value associated with key
-
getBoolean
public Boolean getBoolean(String id, String key)
Term to retrieve a boolean from a space stored under a given keyThis term fails if there is not tuple space with the given id.
- Parameters:
id- the space idkey- the key that the value is stored under- Returns:
- the value associated with key
-
hasTuple
public Formula hasTuple(String id, String key)
Formula to check whether a space contains a key- Parameters:
id- the space idkey- the key- Returns:
- returns formuala TRUE if the tuple space has the given key, the formula FALSE otherwise
-
hasSpace
public Formula hasSpace(String id)
Formula to check whether a space exists- Parameters:
id- the space id- Returns:
- returns formuala TRUE if the tuple space exists, the formula FALSE otherwise
-
getSpaceList
public ListTerm getSpaceList()
Return a list of the spaces that the agent has joined.- Returns:
- returns an ASTRA list of tuple space ids
-
-