Class Var<T>


  • public class Var<T>
    extends java.lang.Object
    A dataflow variable. Represents a variable whose value can be set multiple times and by multiple strands, and whose changing values can be monitored and propagated.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static co.paralleluniverse.common.monitoring.FlightRecorder RECORDER  
    • Constructor Summary

      Constructors 
      Constructor Description
      Var()
      Creates a new Var with no history.
      Var​(int history)
      Creates a new Var.
      Var​(int history, FiberScheduler scheduler, SuspendableCallable<T> f)
      Creates a new Var, whose value is set to the value returned by the given function f; the function will be re-applied, and the Var's value re-set, whenever any of the Vars referenced by f change value.
      Var​(int history, SuspendableCallable<T> f)
      Creates a new Var, whose value is set to the value returned by the given function f; the function will be re-applied, and the Var's value re-set, whenever any of the Vars referenced by f change value.
      Var​(FiberScheduler scheduler, SuspendableCallable<T> f)
      Creates a new Var with no history, whose value is set to the value returned by the given function f; the function will be re-applied, and the Var's value re-set, whenever any of the Vars referenced by f change value.
      Var​(SuspendableCallable<T> f)
      Creates a new Var with no history, whose value is set to the value returned by the given function f; the function will be re-applied, and the Var's value re-set, whenever any of the Vars referenced by f change value.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      T get()
      Returns the Var's current value (more precisely: it returns the oldest value in the maintained history that has not yet been returned), unless this Var does not yet have a value; only in that case will this method block.
      T getNext()
      Blocks until a new value has been set and returns it.
      void set​(T val)
      Sets a new value for this Var.
      • Methods inherited from class java.lang.Object

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

      • RECORDER

        public static final co.paralleluniverse.common.monitoring.FlightRecorder RECORDER
    • Constructor Detail

      • Var

        public Var​(int history,
                   FiberScheduler scheduler,
                   SuspendableCallable<T> f)
        Creates a new Var, whose value is set to the value returned by the given function f; the function will be re-applied, and the Var's value re-set, whenever any of the Vars referenced by f change value.
        Parameters:
        history - how many historical values to maintain for each strand reading the var.
        scheduler - the FiberScheduler to use to schedule the fiber that will run, and re-run f.
        f - this var's value is set to the return value of f
        See Also:
        get()
      • Var

        public Var​(int history,
                   SuspendableCallable<T> f)
        Creates a new Var, whose value is set to the value returned by the given function f; the function will be re-applied, and the Var's value re-set, whenever any of the Vars referenced by f change value. The fiber running f will be scheduled by the default fiber scheduler.
        Parameters:
        history - how many historical values to maintain for each strand reading the var.
        f - this var's value is set to the return value of f
        See Also:
        get()
      • Var

        public Var​(SuspendableCallable<T> f)
        Creates a new Var with no history, whose value is set to the value returned by the given function f; the function will be re-applied, and the Var's value re-set, whenever any of the Vars referenced by f change value. The fiber running f will be scheduled by the default fiber scheduler.
        Parameters:
        f - this var's value is set to the return value of f
        See Also:
        get()
      • Var

        public Var​(FiberScheduler scheduler,
                   SuspendableCallable<T> f)
        Creates a new Var with no history, whose value is set to the value returned by the given function f; the function will be re-applied, and the Var's value re-set, whenever any of the Vars referenced by f change value.
        Parameters:
        scheduler - the FiberScheduler to use to schedule the fiber that will run, and re-run f.
        f - this var's value is set to the return value of f
        See Also:
        get()
      • Var

        public Var​(int history)
        Creates a new Var.
        Parameters:
        history - how many historical values to maintain for each strand reading the var.
        See Also:
        get()
      • Var

        public Var()
        Creates a new Var with no history.
    • Method Detail

      • set

        public void set​(T val)
        Sets a new value for this Var. The Var can be set multiple times and by multiple strands.
        Parameters:
        val - the new value.
      • get

        public T get()
              throws SuspendExecution,
                     java.lang.InterruptedException
        Returns the Var's current value (more precisely: it returns the oldest value in the maintained history that has not yet been returned), unless this Var does not yet have a value; only in that case will this method block.
        Throws:
        SuspendExecution
        java.lang.InterruptedException
      • getNext

        public T getNext()
                  throws SuspendExecution,
                         java.lang.InterruptedException
        Blocks until a new value has been set and returns it.
        Throws:
        SuspendExecution
        java.lang.InterruptedException