Class Rendezvous<T,​V>

java.lang.Object
org.jspace.util.Rendezvous<T,​V>
Type Parameters:
T - data type for tags
V - data type for values

public class Rendezvous<T,​V>
extends java.lang.Object
This class supports the coordination of threads activities based on rendezvous data synchronization. This mechanism allows two threads to exchange a single datum while synchronizing. One thread try to receive a value (call(T)) for a given tag and waits until another thread provides a datum with a matching tag (set(T,V)). Then, the waiting thread is awaked and the provided value is returned. The tag is deleted just after the synchronization is completed. Finally, it is assumed that two synchronizations with the same tag cannot be performed. In case, a IllegalStateException is thrown.
  • Field Summary

    Fields
    Modifier and Type Field Description
    protected java.util.HashMap<T,​org.jspace.util.Rendezvous.DataWrapper> data
    Internally tags are mapped to a Rendezvous.DataWrapper.
    protected java.util.HashSet<java.lang.Thread> waitingThreads
    Set of threads currently waiting for incoming messages.
  • Constructor Summary

    Constructors
    Constructor Description
    Rendezvous()
    Creates a new synchronization map.
  • Method Summary

    Modifier and Type Method Description
    V call​(T tag)
    Calls for a value associated with tag.
    boolean canCall​(T tag)  
    boolean canSet​(T tag)  
    boolean containsTag​(T tag)
    Checks if the tag is registered in the Rendezvous.
    void interruptAll()
    Interrupts all currently waiting threads and clears their requests.
    void set​(T tag, V value)
    Provides a value associated with a tag.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • data

      protected final java.util.HashMap<T,​org.jspace.util.Rendezvous.DataWrapper> data
      Internally tags are mapped to a Rendezvous.DataWrapper. This is an inner class that is used as a wrapper for values.
    • waitingThreads

      protected final java.util.HashSet<java.lang.Thread> waitingThreads
      Set of threads currently waiting for incoming messages.
  • Constructor Details

    • Rendezvous

      public Rendezvous()
      Creates a new synchronization map.
  • Method Details

    • call

      public V call​(T tag) throws java.lang.InterruptedException
      Calls for a value associated with tag. Current thread is suspended until another thread provides a datum with a matching tag (set(T,V)).
      Parameters:
      tag - the tag identifying the requested value
      Returns:
      the value to which the specified tag is mapped.
      Throws:
      java.lang.InterruptedException - if any thread interrupted the current thread before or while the current thread was waiting for a value.
    • set

      public void set​(T tag, V value)
      Provides a value associated with a tag. All the threads that are waiting for a value on that tag are notified. An IllegalStateException is thrown if the tag has not registered in the data structure.
      Parameters:
      tag - the tag associated with a query
      value - the value
      Throws:
      java.lang.IllegalArgumentException - if the tag is not registered in the data structure
    • containsTag

      public boolean containsTag​(T tag)
      Checks if the tag is registered in the Rendezvous.
      Parameters:
      tag - a tag
      Returns:
      true if the tag is registered in the Rendezvous.
    • canCall

      public boolean canCall​(T tag)
    • canSet

      public boolean canSet​(T tag)
    • interruptAll

      public void interruptAll()
      Interrupts all currently waiting threads and clears their requests. Intended to be called when closing a KeepClientGate (via a RemoteSpace).