public class BasicExecutionContext extends AbstractExecutionContext
Executor
and also supply ExecutorService.submit(Callable)
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
ENTITY_IDS |
static java.lang.String |
TASK_ID |
Constructor and Description |
---|
BasicExecutionContext(ExecutionManager executionManager) |
BasicExecutionContext(ExecutionManager executionManager,
java.lang.Iterable<?> tagsForThisContext)
Creates an execution context which wraps
ExecutionManager
adding the given tags to all tasks submitted through this context. |
BasicExecutionContext(java.util.Map<?,?> flags,
ExecutionManager executionManager)
Deprecated.
since 1.0.0 use
BasicExecutionContext(ExecutionManager, Iterable) |
Modifier and Type | Method and Description |
---|---|
<T> T |
get(TaskAdaptable<T> task)
Efficient implementation of common case when
ExecutionContext.submit(TaskAdaptable) is followed by an immediate Task#get() . |
static BasicExecutionContext |
getCurrentExecutionContext() |
ExecutionManager |
getExecutionManager() |
<T> Maybe<T> |
getImmediately(java.lang.Object callableOrSupplier)
performs execution without spawning a new task thread, though it does temporarily set a fake task for the purpose of getting context;
currently supports
Supplier , Callable , Runnable , or Task instances;
with tasks if it is submitted or in progress,
it fails if not completed; with unsubmitted, unqueued tasks, it gets the Callable job and
uses that; with such a job, or any other callable/supplier/runnable, it runs that
in an InterruptingImmediateSupplier , with as much metadata as possible (eg task name if
given a task) set temporarily in the current thread context |
<T> Maybe<T> |
getImmediately(Task<T> callableOrSupplier)
As
ExecutionContext.getImmediately(Object) but strongly typed for a task. |
java.util.Set<Task<?>> |
getTasks()
returns tasks started by this context (or tasks which have all the tags on this object)
|
boolean |
isShutdown() |
static BasicExecutionContext |
setPerThreadExecutionContext(BasicExecutionContext ec)
For use if external code wants to subsequently use an
ExecutionContext but cannot submit via one. |
java.lang.String |
toString() |
public static final java.lang.String ENTITY_IDS
public static final java.lang.String TASK_ID
public BasicExecutionContext(ExecutionManager executionManager)
@Deprecated public BasicExecutionContext(java.util.Map<?,?> flags, ExecutionManager executionManager)
BasicExecutionContext(ExecutionManager, Iterable)
BasicExecutionContext(ExecutionManager, Iterable)
but taking a flags map.
Supported flags are tag
and tags
public BasicExecutionContext(ExecutionManager executionManager, java.lang.Iterable<?> tagsForThisContext)
ExecutionManager
adding the given tags to all tasks submitted through this context.public static BasicExecutionContext getCurrentExecutionContext()
public ExecutionManager getExecutionManager()
public java.util.Set<Task<?>> getTasks()
public <T> T get(TaskAdaptable<T> task)
ExecutionContext
ExecutionContext.submit(TaskAdaptable)
is followed by an immediate Task#get()
.
This is efficient in that it may typically attempt to execute in the current thread,
with appropriate configuration to make it look like it is in a sub-thread,
ie registering this as a task and allowing context methods on tasks to see the given sub-task.
However it will normally be non-blocking which reduces overhead and
is permissible within a ExecutionContext.getImmediately(Object)
task
If the argument has already been submitted it simply blocks on it
(i.e. no additional execution, and in that case would fail within a ExecutionContext.getImmediately(Object)
).
task
- the task whose result is being soughtpublic <T> Maybe<T> getImmediately(Task<T> callableOrSupplier)
ExecutionContext
ExecutionContext.getImmediately(Object)
but strongly typed for a task.public <T> Maybe<T> getImmediately(java.lang.Object callableOrSupplier)
Supplier
, Callable
, Runnable
, or Task
instances;
with tasks if it is submitted or in progress,
it fails if not completed; with unsubmitted, unqueued tasks, it gets the Callable
job and
uses that; with such a job, or any other callable/supplier/runnable, it runs that
in an InterruptingImmediateSupplier
, with as much metadata as possible (eg task name if
given a task) set temporarily in the current thread contextpublic static BasicExecutionContext setPerThreadExecutionContext(BasicExecutionContext ec)
ExecutionContext
but cannot submit via one.
Caller should store the result and reset it back afterwards, in case a task may be running
in the same thread as a synchronous submitter.public boolean isShutdown()
public java.lang.String toString()
toString
in class java.lang.Object