Package astra.util

Class 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
    • Constructor Detail

      • TupleSpace

        public TupleSpace()
    • Method Detail

      • join

        public boolean join​(String id)
        Action that lets the agent join a tuple space

        This 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 space

        This 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:

        1. The space does not exist.
        2. 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 id
        key - the key that the object will be stored under
        value - 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 id
        key - the key that the string will be stored under
        value - 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 id
        key - the key that the int will be stored under
        value - 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 id
        key - the key that the long will be stored under
        value - 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 id
        key - the key that the float will be stored under
        value - 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 id
        key - the key that the double will be stored under
        value - 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 id
        key - the key that the char will be stored under
        value - 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 id
        key - the key that the boolean will be stored under
        value - 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 id
        key - the key that the list will be stored under
        value - 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 key

        This term fails if there is not tuple space with the given id.

        Parameters:
        id - the space id
        key - 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 key

        This term fails if there is not tuple space with the given id.

        Parameters:
        id - the space id
        key - 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 key

        This term fails if there is not tuple space with the given id.

        Parameters:
        id - the space id
        key - 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 key

        This term fails if there is not tuple space with the given id.

        Parameters:
        id - the space id
        key - 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 key

        This term fails if there is not tuple space with the given id.

        Parameters:
        id - the space id
        key - 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 key

        This term fails if there is not tuple space with the given id.

        Parameters:
        id - the space id
        key - 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 key

        This term fails if there is not tuple space with the given id.

        Parameters:
        id - the space id
        key - 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 key

        This term fails if there is not tuple space with the given id.

        Parameters:
        id - the space id
        key - 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 key

        This term fails if there is not tuple space with the given id.

        Parameters:
        id - the space id
        key - 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 id
        key - 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