Class Var<T>
- java.lang.Object
-
- co.paralleluniverse.strands.dataflow.Var<T>
-
public class Var<T> extends java.lang.ObjectA 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.FlightRecorderRECORDER
-
Constructor Summary
Constructors Constructor Description Var()Creates a newVarwith no history.Var(int history)Creates a newVar.Var(int history, FiberScheduler scheduler, SuspendableCallable<T> f)Creates a newVar, whose value is set to the value returned by the given functionf; the function will be re-applied, and theVar's value re-set, whenever any of theVars referenced byfchange value.Var(int history, SuspendableCallable<T> f)Creates a newVar, whose value is set to the value returned by the given functionf; the function will be re-applied, and theVar's value re-set, whenever any of theVars referenced byfchange value.Var(FiberScheduler scheduler, SuspendableCallable<T> f)Creates a newVarwith no history, whose value is set to the value returned by the given functionf; the function will be re-applied, and theVar's value re-set, whenever any of theVars referenced byfchange value.Var(SuspendableCallable<T> f)Creates a newVarwith no history, whose value is set to the value returned by the given functionf; the function will be re-applied, and theVar's value re-set, whenever any of theVars referenced byfchange value.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Tget()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.TgetNext()Blocks until a new value has been set and returns it.voidset(T val)Sets a new value for thisVar.
-
-
-
Constructor Detail
-
Var
public Var(int history, FiberScheduler scheduler, SuspendableCallable<T> f)Creates a newVar, whose value is set to the value returned by the given functionf; the function will be re-applied, and theVar's value re-set, whenever any of theVars referenced byfchange value.- Parameters:
history- how many historical values to maintain for each strand reading the var.scheduler- theFiberSchedulerto use to schedule the fiber that will run, and re-runf.f- this var's value is set to the return value off- See Also:
get()
-
Var
public Var(int history, SuspendableCallable<T> f)Creates a newVar, whose value is set to the value returned by the given functionf; the function will be re-applied, and theVar's value re-set, whenever any of theVars referenced byfchange value. The fiber runningfwill 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 off- See Also:
get()
-
Var
public Var(SuspendableCallable<T> f)
Creates a newVarwith no history, whose value is set to the value returned by the given functionf; the function will be re-applied, and theVar's value re-set, whenever any of theVars referenced byfchange value. The fiber runningfwill be scheduled by the default fiber scheduler.- Parameters:
f- this var's value is set to the return value off- See Also:
get()
-
Var
public Var(FiberScheduler scheduler, SuspendableCallable<T> f)
Creates a newVarwith no history, whose value is set to the value returned by the given functionf; the function will be re-applied, and theVar's value re-set, whenever any of theVars referenced byfchange value.- Parameters:
scheduler- theFiberSchedulerto use to schedule the fiber that will run, and re-runf.f- this var's value is set to the return value off- See Also:
get()
-
Var
public Var(int history)
Creates a newVar.- Parameters:
history- how many historical values to maintain for each strand reading the var.- See Also:
get()
-
Var
public Var()
Creates a newVarwith no history.
-
-
Method Detail
-
set
public void set(T val)
Sets a new value for thisVar. 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:
SuspendExecutionjava.lang.InterruptedException
-
getNext
public T getNext() throws SuspendExecution, java.lang.InterruptedException
Blocks until a new value has been set and returns it.- Throws:
SuspendExecutionjava.lang.InterruptedException
-
-