public class Engine extends Object implements Orchestrator
| Modifier and Type | Method and Description |
|---|---|
void |
activate(long timeoutMs,
CompletableFuture<?>... futures)
Variant of
Orchestrator.activate(CompletableFuture[]) that will timeout according to the TimeoutStrategy
* in effect. |
<T> CompletableFuture<T> |
activate(long timeoutMs,
CompletableFuture<T> future) |
void |
activateAndWait(long timeoutMs,
CompletableFuture<?>... futures)
Variant of
Orchestrator.activateAndWait(CompletableFuture[]) that will timeout according to the TimeoutStrategy
in effect. |
<T> CompletableFuture<T> |
activateAndWait(long timeoutMs,
CompletableFuture<T> future) |
<T> List<T> |
activateAndWait(long timeoutMs,
List<CompletableFuture<T>> futures)
Variant of
Orchestrator.activateAndWait(long timeout, CompletableFuture[]) that returns a typed result
matching the supplied typed input. |
<T> void |
activateAsReady(long timeoutMs,
List<CompletableFuture<T>> futures,
TriConsumer<T,Throwable,Integer> completionFn)
Activate each supplied future and invoke the supplied completionFn callback with each result as soon as each
result becomes individually available.
|
<T> CompletableFuture<List<T>> |
activateFuture(long timeoutMs,
List<CompletableFuture<T>> futures)
Variant of
Orchestrator.activateFuture(List) that will timeout according to the TimeoutStrategy in effect |
<R> CompletableFuture<Optional<R>> |
cond(CompletableFuture<Boolean> condition,
CompletableFuture<R> thenFuture,
boolean thenActivate)
Variant of
Orchestrator.cond(CompletableFuture, CompletableFuture) with an additional boolean argument
indicating whether to proactively activate thenFuture at the same time as condition. |
<R> CompletableFuture<R> |
cond(CompletableFuture<Boolean> condition,
CompletableFuture<R> thenFuture,
boolean thenActivate,
CompletableFuture<R> elseFuture,
boolean elseActivate)
Variant of
Orchestrator.cond(CompletableFuture, CompletableFuture, CompletableFuture) with additional boolean
arguments indicating whether to proactively activate thenFuture and/or elseFuture when
condition is activated. |
CompletableFuture<Boolean> |
fate(CompletableFuture<?>... cfs)
Ties the 'fates' of the supplied CompletableFutures together, which means that as soon as there is a fault on
any one of them, back-pressure is applied to prevent any of the remaining tasks or their predecessors (as
determined recursively) from starting if they have not already been started, and forcing a
TaskNotStartedException on any CompletableFuture that was prevented
from starting in that manner. |
void |
firstInterceptWith(TaskRunner taskRunner)
Adds a TaskRunner that will be processed before any existing TaskRunner.
|
<T,U,R> SupplierTask<R> |
fnTask(CompletableFuture<T> firstInput,
CompletableFuture<U> secondInput,
BiFunction<T,U,R> fn)
Produces function task that takes two arguments.
|
<T,R> SupplierTask<R> |
fnTask(CompletableFuture<T> input,
Function<T,R> fn)
Produces function task that takes one argument.
|
<IN,R> SupplierTask<R> |
fnTask(Supplier<IN> s1,
Function<IN,R> fn)
Produces function task that takes one argument and produces one result.
|
<R> SupplierTask<R> |
fnTask(Supplier<R> fn)
Produces function task that takes no arguments and produces one result.
|
int |
getCountOfThreadsSpawned()
Returns the number of threads that have been spawned by this Orchestrator.
|
ExecutorService |
getExecutorService() |
String |
getName()
Name as set from
Orchestrator.create(String) or Orchestrator.setName(String). |
int |
getNumberOfInterceptors()
Returns the current number of interceptors, as set by
CommonConfig.firstInterceptWith(TaskRunner),
CommonConfig.lastInterceptWith(TaskRunner), or for Orchestrators as set from current global settings. |
SpawnMode |
getSpawnMode()
Gets the most recently set mode.
|
TaskMeta |
getTaskMeta(CompletableFuture<?> cf)
Returns details for any future previously registered with
Orchestrator.activate(CompletableFuture[]) (directly or
through an operation on a CompletableFuture return value). |
long |
getTimeoutMs()
Gets the current timeout.
|
TimeoutStrategy |
getTimeoutStrategy()
Gets the current timeout strategy, default is
TimeoutStrategy.PREVENT_NEW. |
void |
lastInterceptWith(TaskRunner taskRunner)
Adds a TaskRunner that will be processed after any existing TaskRunner.
|
void |
removeAllInterceptors()
Removes all interceptors from the current list.
|
void |
removeInterceptor(TaskRunner taskRunner)
Removes the given TaskRunner from the current list, if it is there.
|
void |
restoreConfigurationDefaults(Object arg)
Restore default settings.
|
void |
restoreDefaultExecutorService() |
void |
setExecutorService(ExecutorService executorService)
Resets the service used by this framework for spawning threads.
|
void |
setName(String name)
Sets name that will become part of the name for any threads spawned by this Orchestrator.
|
void |
setSpawnMode(SpawnMode mode)
Changes the thread-spawning logic to be consistent with the specified mode.
|
void |
setTimeoutMs(long ms)
Sets the current timeout.
|
void |
setTimeoutStrategy(TimeoutStrategy strategy)
Sets the strategy to apply if a timeout greater than zero is in effect and is exceeded.
|
<BASE,SUB extends TaskInterface<BASE>> |
task(SUB t)
Creates a task wrapper around any POJO class whose interface X in turn implements TaskInterface<X>.
|
String |
toString() |
<IN1,IN2> ConsumerTask |
vfnTask(CompletableFuture<IN1> cf1,
CompletableFuture<IN2> cf2,
BiConsumer<IN1,IN2> fn)
Produces function task that takes non-lambda arguments and produces no result.
|
<IN1,IN2> ConsumerTask |
vfnTask(CompletableFuture<IN1> cf1,
Supplier<IN2> s2,
BiConsumer<IN1,IN2> fn)
Produces function task that takes mixed arguments and produces no result.
|
<IN> ConsumerTask |
vfnTask(Supplier<IN> s1,
Consumer<IN> fn)
Produces function task that takes one lambda argument and produces no result.
|
<IN1,IN2> ConsumerTask |
vfnTask(Supplier<IN1> s1,
CompletableFuture<IN2> cf2,
BiConsumer<IN1,IN2> fn)
Produces function task that takes mixed arguments and produces no result.
|
<IN1,IN2> ConsumerTask |
vfnTask(Supplier<IN1> s1,
Supplier<IN2> s2,
BiConsumer<IN1,IN2> fn)
Produces function task that takes two lambda arguments and produces no result.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitactivate, activate, activate, activate, activateAndWait, activateAndWait, activateAndWait, activateAndWait, activateAndWait, activateAndWait, activateAsReady, activateAsReady, activateFuture, activateFuture, cond, cond, create, create, create, current, execute, execute, execute, executeAndWait, executeAndWait, executeAndWait, fn, fn, fn, fn, fn, fn, fn, fnTask, fnTask, fnTask, task, vfn, vfn, vfn, vfn, vfn, voidTasksetTimeoutpublic String getName()
OrchestratorOrchestrator.create(String) or Orchestrator.setName(String).getName in interface Orchestratorpublic void setName(String name)
OrchestratorsetName in interface Orchestratorname - to setpublic int getCountOfThreadsSpawned()
OrchestratorNote that a physical thread may have been returned to the thread pool and retrieved again, but these would count as separate logical threads as far as this return value is concerned.
getCountOfThreadsSpawned in interface Orchestratorpublic void restoreConfigurationDefaults(Object arg)
CommonConfigrestoreConfigurationDefaults in interface CommonConfigarg - passed from user codepublic SpawnMode getSpawnMode()
CommonConfigSpawnMode.WHEN_NEEDED. The Orchestrator
default is null, which results in using the global setting.getSpawnMode in interface CommonConfigpublic void setSpawnMode(SpawnMode mode)
CommonConfigsetSpawnMode in interface CommonConfigmode - to setpublic long getTimeoutMs()
CommonConfiggetTimeoutMs in interface CommonConfigpublic void setTimeoutMs(long ms)
CommonConfigCommonConfig.getTimeoutStrategy() will apply.setTimeoutMs in interface CommonConfigms - duration in milliseconds, zero means no timeout will be appliedpublic TimeoutStrategy getTimeoutStrategy()
CommonConfigTimeoutStrategy.PREVENT_NEW.getTimeoutStrategy in interface CommonConfigCommonConfig.setTimeoutStrategy(TimeoutStrategy)public void setTimeoutStrategy(TimeoutStrategy strategy)
CommonConfigsetTimeoutStrategy in interface CommonConfigstrategy - to setpublic ExecutorService getExecutorService()
getExecutorService in interface CommonConfigpublic void setExecutorService(ExecutorService executorService)
CommonConfigGlobalOrchestratorConfig.DEFAULT_FIXED_THREADPOOL_SIZE.setExecutorService in interface CommonConfigexecutorService - to set as new defaultpublic void restoreDefaultExecutorService()
restoreDefaultExecutorService in interface CommonConfigpublic void activate(long timeoutMs,
CompletableFuture<?>... futures)
OrchestratorOrchestrator.activate(CompletableFuture[]) that will timeout according to the TimeoutStrategy
* in effect.activate in interface OrchestratortimeoutMs - timout in millisecondsfutures - to activatepublic <T> CompletableFuture<T> activate(long timeoutMs, CompletableFuture<T> future)
activate in interface Orchestratorpublic void activateAndWait(long timeoutMs,
CompletableFuture<?>... futures)
OrchestratorOrchestrator.activateAndWait(CompletableFuture[]) that will timeout according to the TimeoutStrategy
in effect.activateAndWait in interface OrchestratortimeoutMs - timout in millisecondsfutures - to activatepublic <T> CompletableFuture<T> activateAndWait(long timeoutMs, CompletableFuture<T> future)
activateAndWait in interface Orchestratorpublic <T> List<T> activateAndWait(long timeoutMs, List<CompletableFuture<T>> futures)
OrchestratorOrchestrator.activateAndWait(long timeout, CompletableFuture[]) that returns a typed result
matching the supplied typed input.activateAndWait in interface OrchestratorT - Type of list itemstimeoutMs - timout in millisecondsfutures - to activatepublic <T> CompletableFuture<List<T>> activateFuture(long timeoutMs, List<CompletableFuture<T>> futures)
OrchestratorOrchestrator.activateFuture(List) that will timeout according to the TimeoutStrategy in effectactivateFuture in interface OrchestratorT - Type of list itemstimeoutMs - timout in millisecondsfutures - to activatepublic <T> void activateAsReady(long timeoutMs,
List<CompletableFuture<T>> futures,
TriConsumer<T,Throwable,Integer> completionFn)
OrchestratorCompletion callbacks may be done from separate threads, but synchronization is employed so that only one thread at a time is allowed to make a completion call. The calling thread does not itself wait and is therefore never one to make a completion call.
activateAsReady in interface OrchestratorT - of each each elementtimeoutMs - timout in millisecondsfutures - to activatecompletionFn - that will be called as many times as there are entries in the futures listpublic TaskMeta getTaskMeta(CompletableFuture<?> cf)
OrchestratorOrchestrator.activate(CompletableFuture[]) (directly or
through an operation on a CompletableFuture return value).getTaskMeta in interface Orchestratorcf - to mappublic <BASE,SUB extends TaskInterface<BASE>> BASE task(SUB t)
OrchestratorX that intercepts all calls on it in order
to provide alternate execution behavior where CompletableFutures are present as inputs or output:
Activating a task method implicitly activates all tasks methods supplying CompletableFutures as inputs. Once activated, a task method will be executed, possibly in a different thread, as soon as all of its CompletableFuture input arguments (if any) have completed. A task method with no CompletableFuture arguments (perhaps no arguments at all) is executed right away, though (again) possibly in a different thread.
Internally, task method suspension (as described above) involves recording dependency links between the task method and its arguments for later execution if/when activated. Those dependency links are designed to have minimal performance cost so it is generally safe to build large dependency graphs in while later incrementally choosing which elements are actually needed. Such graphs need not be defined all at once, it can be extended at any time or place by calling this or similar methods on this class, including from within other task methods, regardless of the activation state of existing task methods or the completion state of any CompletableFutures.
The userTask argument can be wrapped by this call any number of times. There is in effect a many-to- one relationship between these wrappers and any target user POJO instance. It may be desirable to share stateful POJO instances or conversely to simply reuse stateless POJO instances to avoid the overhead of creating multiple POJO instances.
task in interface OrchestratorBASE - the interface for the taskSUB - the implementing class typet - any userTask with an interface that extends TaskInterfacepublic <R> CompletableFuture<Optional<R>> cond(CompletableFuture<Boolean> condition, CompletableFuture<R> thenFuture, boolean thenActivate)
OrchestratorOrchestrator.cond(CompletableFuture, CompletableFuture) with an additional boolean argument
indicating whether to proactively activate thenFuture at the same time as condition.
Activating thenFuture in that way may be wasteful since condition may eventually evaluate to false,
but the overall result will be faster when condition evaluates to true.
Note that this method will not be activated until an access operation is performed on the return value, even though it is a void result.
cond in interface OrchestratorR - type of nested return valuecondition - to first evaluatethenFuture - to activate if condition evaluates to truethenActivate - iff true then activate at same time as conditionpublic <R> CompletableFuture<R> cond(CompletableFuture<Boolean> condition, CompletableFuture<R> thenFuture, boolean thenActivate, CompletableFuture<R> elseFuture, boolean elseActivate)
OrchestratorOrchestrator.cond(CompletableFuture, CompletableFuture, CompletableFuture) with additional boolean
arguments indicating whether to proactively activate thenFuture and/or elseFuture when
condition is activated. Activating either of those futures in that way may be wasteful since the eventual
condition result may choose the alternate, but the overall result will be faster when condition chooses
a proactively activated choice.cond in interface OrchestratorR - type of return resultcondition - to first evaluatethenFuture - chosen if condition evaluates to truethenActivate - iff true then activate thenFuture at same time as conditionelseFuture - chosen if condition evaluates to falseelseActivate - iff true then activate elseFuture at same time as conditionpublic CompletableFuture<Boolean> fate(CompletableFuture<?>... cfs)
OrchestratorTaskNotStartedException on any CompletableFuture that was prevented
from starting in that manner.
A return result of 'true' can be used to initiate compensating actions on any task that previously
completed. Any such action can know whether any previous CompletableFuture was completed or not by calling
CompletableFuture.isCompletedExceptionally().
Note that this method is only activated if the return value is activated.
fate in interface Orchestratorcfs - to tie togetherpublic <R> SupplierTask<R> fnTask(Supplier<R> fn)
OrchestratorfnTask in interface OrchestratorR - type of return resultfn - function to apply to that pojo if/when task is activatedpublic <IN,R> SupplierTask<R> fnTask(Supplier<IN> s1, Function<IN,R> fn)
OrchestratorfnTask in interface OrchestratorIN - type of inputR - type of return results1 - Supplier function (returns a value)fn - function to apply to that pojo if/when task is activatedpublic <T,R> SupplierTask<R> fnTask(CompletableFuture<T> input, Function<T,R> fn)
OrchestratorfnTask in interface OrchestratorT - unwrapped type of inputR - unwrapped type of type of function resultinput - input to functionfn - function to apply to that pojo if/when task is activatedpublic <T,U,R> SupplierTask<R> fnTask(CompletableFuture<T> firstInput, CompletableFuture<U> secondInput, BiFunction<T,U,R> fn)
OrchestratorfnTask in interface OrchestratorT - unwrapped base type of first inputU - unwrapped base type of second inputR - unwrapped type of function resultfirstInput - first inputsecondInput - second inputfn - function to apply to inputs when activatedpublic <IN> ConsumerTask vfnTask(Supplier<IN> s1, Consumer<IN> fn)
OrchestratorvfnTask in interface OrchestratorIN - type of input1s1 - provides value for fnfn - function to apply to that pojo if/when task is activatedpublic <IN1,IN2> ConsumerTask vfnTask(CompletableFuture<IN1> cf1, Supplier<IN2> s2, BiConsumer<IN1,IN2> fn)
OrchestratorvfnTask in interface OrchestratorIN1 - base type of input1IN2 - type of input2cf1 - provides first value for fns2 - provides second value for fnfn - function to apply to that pojo if/when task is activatedpublic <IN1,IN2> ConsumerTask vfnTask(CompletableFuture<IN1> cf1, CompletableFuture<IN2> cf2, BiConsumer<IN1,IN2> fn)
OrchestratorvfnTask in interface OrchestratorIN1 - base type of input1IN2 - base type of input2cf1 - provides first value for fncf2 - provides second value for fnfn - function to apply to that pojo if/when task is activatedpublic <IN1,IN2> ConsumerTask vfnTask(Supplier<IN1> s1, CompletableFuture<IN2> cf2, BiConsumer<IN1,IN2> fn)
OrchestratorvfnTask in interface OrchestratorIN1 - type of input1IN2 - base type of input2s1 - provides first value for fncf2 - provides second value for fnfn - function to apply to that pojo if/when task is activatedpublic <IN1,IN2> ConsumerTask vfnTask(Supplier<IN1> s1, Supplier<IN2> s2, BiConsumer<IN1,IN2> fn)
OrchestratorvfnTask in interface OrchestratorIN1 - type of input1IN2 - type of input2s1 - provides first value for fns2 - provides second value for fnfn - function to apply to that pojo if/when task is activatedpublic void firstInterceptWith(TaskRunner taskRunner)
CommonConfigfirstInterceptWith in interface CommonConfigtaskRunner - to addpublic void lastInterceptWith(TaskRunner taskRunner)
CommonConfiglastInterceptWith in interface CommonConfigtaskRunner - to addpublic int getNumberOfInterceptors()
CommonConfigCommonConfig.firstInterceptWith(TaskRunner),
CommonConfig.lastInterceptWith(TaskRunner), or for Orchestrators as set from current global settings.getNumberOfInterceptors in interface CommonConfigpublic void removeInterceptor(TaskRunner taskRunner)
CommonConfigremoveInterceptor in interface CommonConfigtaskRunner - to removepublic void removeAllInterceptors()
CommonConfigremoveAllInterceptors in interface CommonConfigCopyright © 2021. All rights reserved.