Class Var<T>
- java.lang.Object
-
- co.paralleluniverse.strands.dataflow.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 newVar
with 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 theVar
s referenced byf
change 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 theVar
s referenced byf
change value.Var(FiberScheduler scheduler, SuspendableCallable<T> f)
Creates a newVar
with 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 theVar
s referenced byf
change value.Var(SuspendableCallable<T> f)
Creates a newVar
with 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 theVar
s referenced byf
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 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 theVar
s referenced byf
change value.- Parameters:
history
- how many historical values to maintain for each strand reading the var.scheduler
- theFiberScheduler
to 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 theVar
s referenced byf
change value. The fiber runningf
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 off
- See Also:
get()
-
Var
public Var(SuspendableCallable<T> f)
Creates a newVar
with 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 theVar
s referenced byf
change value. The fiber runningf
will 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 newVar
with 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 theVar
s referenced byf
change value.- Parameters:
scheduler
- theFiberScheduler
to 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 newVar
with 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:
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
-
-