Skip to content

SequentialSpace Class

Shane McLean edited this page Oct 13, 2017 · 1 revision

Concrete implementation of a tuplespace datastructure. Represents a strongly typed set of tuples that can be access through pattern matching. Provides methods to query and manipulate the set. This class imposes fifo ordering on the underlying tuples.

Inheritance Hierarchy

Object > SpaceBase

Syntax

public sealed class SequentialSpace : SpaceBase, ISpace

Constructors

Name                                                     Description
SequentialSpace(ITupleFactory) Initializes a new instance of the SequentialSpace class. All tuples will be created using the provided tuple factory; if none is provided the default TupleFactory will be used.

Methods

Name                             Description
GetIndex(Int32) Returns the last index contained within the space to force fifo ordering.
Get(IPattern) Retrieves and removes the first tuple from the Space, matching the specified pattern. The operation will block if no elements match.
Get(Object[]) Retrieves and removes the first tuple from the Space, matching the specified pattern. The operation will block if no elements match.
GetP(IPattern) Retrieves and removes the first tuple from the Space, matching the specified pattern. The operation is non-blocking. The operation will return null if no elements match.
GetP(Object[]) Retrieves and removes the first tuple from the Space, matching the specified pattern. The operation is non-blocking. The operation will return null if no elements match.
GetAll(IPattern) Retrieves and removes all tuples from the Space matching the specified pattern. The operation is non-blocking. The operation will return an empty set if no elements match.
GetAll(Object[]) Retrieves and removes all tuples from the Space matching the specified pattern. The operation is non-blocking. The operation will return an empty set if no elements match.
Query(IPattern) Retrieves a clone of the first tuple from the Space, matching the specified pattern. The operation will block if no elements match.
Query(Object[]) Retrieves a clone of the first tuple from the Space, matching the specified pattern. The operation will block if no elements match.
QueryP(IPattern) Retrieves a clone of the first tuple from the Space, matching the specified pattern. The operation is non-blocking. The operation will return null if no elements match.
QueryP(Object[]) Retrieves a clone of the first tuple from the Space, matching the specified pattern.The operation is non-blocking.The operation will return null if no elements match.
QueryAll(IPattern) Retrieves clones of all tuples from the Space matching the specified pattern. The operation is non-blocking. The operation will return an empty set if no elements match.
QueryAll(Object[]) Retrieves clones of all tuples from the Space matching the specified pattern. The operation is non-blocking. The operation will return an empty set if no elements match.
Put(ITuple) Inserts the tuple passed as argument into the Space.
Put(Object[]) Inserts the tuple passed as argument into the Space.

Remarks

The SequentialSpace class is a threadsafe data structure. It implements the ISpace interface.
You can add tuples to a Space by using the Put methods. Conversely, tuples can be fetched through Query, QueryP, QueryAll, Get, GetP and GetAll.

Please note that:

  • All variants of the Get operations not only fetches the tuple(s), but also removes them from the space.
  • All variants of the Query operations returns a clone of the tuple stored in the Space, and not a referenced tuple.

Performance Considerations
The SequentialSpace class utilizes an internal hashmap for partitioning. Upon insertion of a Tuple, the hashvalue of the tuple is computed by the tuple signature. The tuple is then placed in a partition matching the hashvalue. This means that for each unique tuple signature, a partition is created. Subsequently, the searching time is reduced to the partition size. When fetching tuples, the underlying parition in the tuple space is searched linearly. The worstcase runtime is thus O(n) where n is number of elements in the partition.

The SequentialSpace class utilizes a Readers-Writer-locking mechanism. This means that the multiple concurrent Query operations is possible. Furthermore, because the underlying set is partitioned, multiple Get and Put are possible, as long they are performed on seperate partitions.

Tuples are retrieved by FIFO ordering with respect to the underlying partitions.

Examples

The following example shows how the ordering effect transactions when using a FIFO based space.

    static void Main(string[] args)
    {
        ISpace fifoOrdered = new SequentialSpace();
        Console.WriteLine("Putting and getting tuple's using FIFO ordering:");

        for(int cnt=0; cnt<10; cnt++)
        {
            fifoOrdered.Put(cnt);
        }

        for (int cnt = 0; cnt < 10; cnt++)
        {
            ITuple tuple = fifoOrdered.Get(typeof(int));
            Console.WriteLine(tuple);
        }
        Console.Read();
    }

    /*
    The following is printed to the console:
    Putting and getting tuple's using FIFO ordering:
    <0>
    <1>
    <2>
    <3>
    <4>
    <5>
    <6>
    <7>
    <8>
    <9>
    */

See Also

SpaceBase, ISpace, ITupleFactory, IPattern, ITuple

Clone this wiki locally