S - self-type. Subclasses must parameterize AbstractExecutionContext
with themselves, and return themselves in instance(). This forces
a compiler check on the type of instanced contexts, ensuring (if
no foolish cast is used) that restricted contexts have all the
methods available in the main ExecutionContext. For
instance, if your class is MyContext, it should be written as
MyContext extends AbstractExecutionContext<MyContext>.public abstract class AbstractExecutionContext<S extends AbstractExecutionContext<S>> extends java.lang.Object implements ExecutionContext
| Modifier | Constructor and Description |
|---|---|
protected |
AbstractExecutionContext(ExecutionEnvironment execenv,
NetworkManager netmgr)
Create a new AbstractExecutionContext with a default, time-efficient code path factory.
|
protected |
AbstractExecutionContext(ExecutionEnvironment executionEnvironment,
NetworkManager networkManager,
CodePathFactory codePathFactory)
Create a new AbstractExecutionContext with the specified
CodePathFactory. |
| Modifier and Type | Method and Description |
|---|---|
<T,R> Field<R> |
buildField(java.util.function.Function<T,R> computeValue,
T localValue)
Builds a new
Field, fetching data from all the aligned neighbors. |
<T,R> Field<R> |
buildFieldDeferred(java.util.function.Function<T,R> computeValue,
T currentLocal,
java.util.function.Supplier<T> toBeSent)
Builds a new
Field, fetching data from all the aligned neighbors. |
void |
commit()
Called just after the VM is executed, to finalize information of the
execution for the environment.
|
protected void |
commitRecursively()
recursively commits on restricted contexts.
|
java.lang.Number |
getDeltaTime() |
ExecutionEnvironment |
getExecutionEnvironment() |
protected java.util.Map<Reference,?> |
getFunctions()
Support for first-class functions by returning the set of currently
accessible functions.
|
protected NetworkManager |
getNetworkManager()
Accessor for abstract network interface.
|
<P> P |
getPersistent(java.util.function.Supplier<P> ifAbsent)
Gets a value that survives across rounds.
|
java.util.Map<CodePath,java.lang.Object> |
getStoredState() |
java.lang.Object |
getVariable(Reference name)
Look up the value of a variable from the local environment.
|
protected abstract S |
instance()
Produce a child execution context, for encapsulated evaluation of
sub-programs.
|
void |
newCallStackFrame(byte... id) |
void |
newCallStackFrame(int... id) |
void |
putMultipleVariables(java.util.Map<Reference,?> map)
Pushes multiple variables.
|
void |
putVariable(Reference name,
java.lang.Object value)
Puts a variable value, overwriting the previous one, if any.
|
S |
restrictDomain(Field<?> f)
Give a field, returns a new
ExecutionContext whose domain is the same of the field one. |
void |
returnFromCallFrame()
returns from the last frame.
|
<T> T |
runInNewStackFrame(int id,
java.util.function.Function<ExecutionContext,T> operation) |
void |
setGloballyAvailableReferences(java.util.Map<Reference,?> knownFunctions)
Used internally to support first-class functions by make the functions of
a program accessible for reflection at runtime.
|
void |
setPersistent(java.lang.Object o)
Stores a value to be used in future rounds via getPersistent.
|
void |
setup()
Called just before the VM is executed, to enable and preparations needed
in the environment.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitgetCurrentTime, getDeviceUID, nextRandomDoubleprotected AbstractExecutionContext(ExecutionEnvironment execenv, NetworkManager netmgr)
execenv - The execution environmentnetmgr - Abstract network interface to be usedprotected AbstractExecutionContext(ExecutionEnvironment executionEnvironment, NetworkManager networkManager, CodePathFactory codePathFactory)
CodePathFactory. Subclasses which want to use hashing or other means
to encode CodePaths can call this constructor, e.g.:
super(executionEnvironment, networkManager, new HashingCodePathFactory(Hashing.sha256()));
executionEnvironment - The execution environmentnetworkManager - Abstract network interface to be usedcodePathFactory - The code path factory to usepublic final <T,R> Field<R> buildField(java.util.function.Function<T,R> computeValue, T localValue)
ExecutionContextField, fetching data from all the aligned neighbors.
A neighbor is considered to be aligned it it has reached the exact same
DefaultTimeEfficientCodePath. The field will always contain at least one value,
namely the value of the local device.buildField in interface ExecutionContextT - the type of the inputR - the type of the outputcomputeValue - a function that will be applied to localValue and the
equivalents shared from neighbors in the process of
constructing this field: the field consists of the values
returned from applying computeValue to each of device's valuelocalValue - the local value for this fieldField containing the local device value and the
values for any of the aligned neighborspublic final <T,R> Field<R> buildFieldDeferred(java.util.function.Function<T,R> computeValue, T currentLocal, java.util.function.Supplier<T> toBeSent)
ExecutionContextField, fetching data from all the aligned neighbors.
A neighbor is considered to be aligned it it has reached the exact same
DefaultTimeEfficientCodePath. The field will always contain at least one value,
namely the value of the local device. The deferred version does not immediately schedule
the local value for being sent away. Rather, it schedules the provided Supplier
to be executed at the end of the round for obtaining the value to be shared. This
function is the base upon which the ShareCall
is built.buildFieldDeferred in interface ExecutionContextT - the type of the inputR - the type of the outputcomputeValue - a function that will be applied to localValue and the
equivalents shared from neighbors in the process of
constructing this field: the field consists of the values
returned from applying computeValue to each of device's valuecurrentLocal - the value to be used as local for this fieldtoBeSent - a Supplier which will be used to compute the local
value for this field that will get exported at the end of the roundField containing the local device value and the
values for any of the aligned neighborspublic final void commit()
ExecutionContextcommit in interface ExecutionContextprotected final void commitRecursively()
public java.lang.Number getDeltaTime()
getDeltaTime in interface ExecutionContextpublic final ExecutionEnvironment getExecutionEnvironment()
getExecutionEnvironment in interface ExecutionContextExecutionEnvironmentprotected final java.util.Map<Reference,?> getFunctions()
protected final NetworkManager getNetworkManager()
public final <P> P getPersistent(java.util.function.Supplier<P> ifAbsent)
ExecutionContextgetPersistent in interface ExecutionContextP - type of the valueifAbsent - replacementpublic final java.lang.Object getVariable(Reference name)
ExecutionContextgetVariable in interface ExecutionContextname - The variable to be looked uppublic final java.util.Map<CodePath,java.lang.Object> getStoredState()
protected abstract S instance()
public final void newCallStackFrame(byte... id)
newCallStackFrame in interface ExecutionContextid - stack frame typepublic final void newCallStackFrame(int... id)
newCallStackFrame in interface ExecutionContextid - stack frame typepublic final void putMultipleVariables(java.util.Map<Reference,?> map)
ExecutionContextputMultipleVariables in interface ExecutionContextmap - the variables to pushpublic final void putVariable(Reference name, java.lang.Object value)
ExecutionContextputVariable in interface ExecutionContextname - variable referencevalue - variable valuepublic final S restrictDomain(@Nonnull Field<?> f)
ExecutionContextExecutionContext whose domain is the same of the field one.restrictDomain in interface ExecutionContextf - the fieldpublic final void returnFromCallFrame()
ExecutionContextreturnFromCallFrame in interface ExecutionContextpublic final <T> T runInNewStackFrame(int id,
java.util.function.Function<ExecutionContext,T> operation)
runInNewStackFrame in interface ExecutionContextT - the return typeid - stack frame typeoperation - the operation to run in the new contextpublic final void setGloballyAvailableReferences(java.util.Map<Reference,?> knownFunctions)
ExecutionContextsetGloballyAvailableReferences in interface ExecutionContextknownFunctions - Collection of accessible functions, associating function name
and value.public final void setPersistent(java.lang.Object o)
ExecutionContextsetPersistent in interface ExecutionContexto - the value to storepublic final void setup()
ExecutionContextsetup in interface ExecutionContext