public interface Orchestrator extends CommonConfig
| Modifier and Type | Method and Description |
|---|---|
<R> CompletableFuture<R> |
cond(CompletableFuture<Boolean> condition,
CompletableFuture<R> thenFuture,
boolean thenActivate,
CompletableFuture<R> elseFuture,
boolean elseActivate)
Variant of
cond(CompletableFuture, CompletableFuture, CompletableFuture) with additional boolean
arguments indicating whether to proactively start executing thenFuture and/or elseFuture when
condition is activated. |
default <R> CompletableFuture<R> |
cond(CompletableFuture<Boolean> condition,
CompletableFuture<R> thenFuture,
CompletableFuture<R> elseFuture)
Execute one of two choices depending on the result of the supplied condition.
|
default CompletableFuture<Void> |
cond(CompletableFuture<Boolean> condition,
CompletableFuture<Void> thenFuture)
Execute the supplied CompletableFuture depending on the supplied condition.
|
CompletableFuture<Void> |
cond(CompletableFuture<Boolean> condition,
CompletableFuture<Void> thenFuture,
boolean thenActivate)
Variant of
cond(CompletableFuture, CompletableFuture) with an additional boolean argument
indicating whether to proactively start executing thenFuture at the same time as condition. |
static Orchestrator |
create()
Creates an Orchestrator with no name.
|
static Orchestrator |
create(String name)
Creates a new named Orchestrator, which is the same as
|
static Orchestrator |
create(String name,
Object arg)
Creates an Orchestrator with the given name and argument.
|
default void |
execute(CompletionStage<?>... futures)
Initiates execution of the task methods behind each supplied CompletableFuture if they are not already started,
as well as the task methods needed to supply its inputs, recursively.
|
void |
execute(long timeoutMs,
CompletionStage<?>... futures)
Like
execute(CompletionStage[]), but establishes a timeout which will affect execution
as defined by the TimeoutStrategy in effect. |
default void |
execute(long timeout,
TimeUnit timeUnit,
CompletionStage<?>... futures)
Variant of
execute(long, CompletionStage[]) with TimeUnit option. |
default void |
executeAndWait(CompletableFuture<?>... futures)
Variant of
execute(CompletionStage[]) that waits for all of its arguments to complete,
ignoring any exceptions. |
void |
executeAndWait(long timeoutMs,
CompletableFuture<?>... futures)
Variant of
executeAndWait(CompletableFuture[]), but establishes a timeout which will affect
execution as defined by the TimeoutStrategy in effect. |
default void |
executeAndWait(long timeout,
TimeUnit timeUnit,
CompletableFuture<?>... futures)
Variant of
executeAndWait(long, CompletableFuture[]) with TimeUnit option. |
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. |
default <IN,R> CompletableFuture<R> |
fn(CompletableFuture<IN> in,
Function<IN,R> fn)
Produces function task value that takes one non-lambda argument and produces one result.
|
default <IN1,IN2,R> |
fn(CompletableFuture<IN1> in1,
CompletableFuture<IN2> in2,
BiFunction<IN1,IN2,R> fn)
Produces function task value that takes two non-lambda arguments and produces one result.
|
default <IN1,IN2,R> |
fn(CompletableFuture<IN1> in1,
Supplier<IN2> s2,
BiFunction<IN1,IN2,R> fn)
Produces function task value that takes mixed arguments and produces one result.
|
default <IN,R> CompletableFuture<R> |
fn(Supplier<IN> s1,
Function<IN,R> fn)
Produces function task value that takes one argument and produces one result.
|
default <IN1,IN2,R> |
fn(Supplier<IN1> s1,
CompletableFuture<IN2> in2,
BiFunction<IN1,IN2,R> fn)
Produces function task value that takes mixed arguments and produces one result.
|
default <IN1,IN2,R> |
fn(Supplier<IN1> s1,
Supplier<IN2> s2,
BiFunction<IN1,IN2,R> fn)
Produces function task value that takes two lambda arguments and produces one result.
|
default <R> CompletableFuture<R> |
fn(Supplier<R> fn)
Produces function task value that takes no arguments and produces one result.
|
default <IN,R> SupplierTask<R> |
fnTask(CompletableFuture<IN> in,
Function<IN,R> fn)
Produces function task that takes one non-lambda argument and produces one result.
|
default <IN1,IN2,R> |
fnTask(CompletableFuture<IN1> in1,
CompletableFuture<IN2> in2,
BiFunction<IN1,IN2,R> fn)
Produces function task that takes two non-lambda arguments and produces one result.
|
default <IN1,IN2,R> |
fnTask(CompletableFuture<IN1> in1,
Supplier<IN2> s2,
BiFunction<IN1,IN2,R> fn)
Produces function task that takes mixed arguments and produces one result.
|
default <IN,R> SupplierTask<R> |
fnTask(Supplier<IN> s1,
Function<IN,R> fn)
Produces function task that takes one argument and produces one result.
|
default <IN1,IN2,R> |
fnTask(Supplier<IN1> s1,
CompletableFuture<IN2> in2,
BiFunction<IN1,IN2,R> fn)
Produces function task that takes mixed arguments and produces one result.
|
default <IN1,IN2,R> |
fnTask(Supplier<IN1> s1,
Supplier<IN2> s2,
BiFunction<IN1,IN2,R> fn)
Produces function task that takes two lambda arguments and produces one result.
|
default <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, which is a non-deterministic result
since the inherent timing variations across threads may result in different spawning decisions on different
runs of the same execution request.
|
String |
getName()
Name as set from
create(String) or setName(String). |
TaskMeta |
getTaskMeta(CompletableFuture<?> cf)
Returns details for any future previously registered with
execute(CompletionStage[]) (directly or
through an operation on a CompletableFuture return value). |
void |
setName(String name)
Sets name that will become part of the name for any threads spawned by this Orchestrator.
|
<BASE,SUB extends TaskInterface<BASE>> |
task(SUB userTask)
Creates a task wrapper around any user POJO with the requirement that that POJO implements an interface X
that in turn implements TaskInterface<X>.The result is a wrapper object that has the same signature
as its pojo argument, such that any CompletableFuture-returning task methods invoked on this wrapper are not
executed right away --they will be executed if/when any read operation on the returned CompletableFuture is
performed or by passing that CompletableFuture to
execute(CompletionStage[]) or any of its variants. |
default <TASK,R> CompletableFuture<R> |
task(TASK userTask,
Function<TASK,R> fn)
Creates a task wrapper on any user pojo task method.
|
default <IN1,IN2> CompletableFuture<Void> |
vfn(CompletableFuture<IN1> cf1,
CompletableFuture<IN2> cf2,
BiConsumer<IN1,IN2> fn)
Produces function task value that takes non-lambda arguments and produces no result.
|
default <IN1,IN2> CompletableFuture<Void> |
vfn(CompletableFuture<IN1> cf1,
Supplier<IN2> s2,
BiConsumer<IN1,IN2> fn)
Produces function task value that takes mixed arguments and produces no result.
|
default <IN> CompletableFuture<Void> |
vfn(Supplier<IN> s1,
Consumer<IN> fn)
Produces function task value that takes one lambda argument and produces no result.
|
default <IN1,IN2> CompletableFuture<Void> |
vfn(Supplier<IN1> s1,
CompletableFuture<IN2> cf2,
BiConsumer<IN1,IN2> fn)
Produces function task value that takes mixed arguments and produces no result.
|
default <IN1,IN2> CompletableFuture<Void> |
vfn(Supplier<IN1> s1,
Supplier<IN2> s2,
BiConsumer<IN1,IN2> fn)
Produces function task value that takes two lambda arguments and produces no result.
|
default <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.
|
default <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.
|
default <IN> ConsumerTask |
vfnTask(Supplier<IN> s1,
Consumer<IN> fn)
Produces function task that takes one lambda argument and produces no result.
|
default <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.
|
default <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.
|
default <TASK> CompletableFuture<Void> |
voidTask(TASK userTask,
Consumer<TASK> fn)
Adds a task wrapper on any user pojo task method with a void result.
|
firstInterceptWith, getExecutorService, getNumberOfInterceptors, getSpawnMode, getTimeoutMs, getTimeoutStrategy, lastInterceptWith, removeAllTaskRunners, removeInterceptor, restoreConfigurationDefaults, restoreDefaultExecutorService, setExecutorService, setSpawnMode, setTimeout, setTimeoutMs, setTimeoutStrategystatic Orchestrator create()
static Orchestrator create(String name)
create().setName(name);
static Orchestrator create(String name, Object arg)
name - optional / possibly null for this orchestrator, useful for loggingarg - to pass to GlobalOrchestratorConfig.Config.updateConfigurationOn(Orchestrator, Object).String getName()
create(String) or setName(String).void setName(String name)
name - to setTaskMeta getTaskMeta(CompletableFuture<?> cf)
execute(CompletionStage[]) (directly or
through an operation on a CompletableFuture return value).cf - to mapint getCountOfThreadsSpawned()
Note 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.
default void execute(CompletionStage<?>... futures)
Each task method will only be executed once even it is passed multiple times to this method. As this method
is called implicitly for any operation (such as CompletableFuture.get() on a single future returned
from a task, this method call is only needed to start multiple futures at the same time, or for starting tasks
whose purpose is to a side-effect that occurs without any call to get a value from it, or for any other
situation where an access of its value is not possible nor desirable.
This call only starts ('activates') but does not necessarily wait for any of the started tasks to complete.
More specifically, it does not wait on any threads that are spawned to complete. Access a value on any
BT-managed CompletableFuture or call executeAndWait(CompletableFuture[]) to force waiting.
futures - to executedefault void execute(long timeout,
TimeUnit timeUnit,
CompletionStage<?>... futures)
execute(long, CompletionStage[]) with TimeUnit option.timeout - to settimeUnit - unitsfutures - to executvoid execute(long timeoutMs,
CompletionStage<?>... futures)
execute(CompletionStage[]), but establishes a timeout which will affect execution
as defined by the TimeoutStrategy in effect.timeoutMs - timout in millisecondsfutures - to executedefault void executeAndWait(CompletableFuture<?>... futures)
execute(CompletionStage[]) that waits for all of its arguments to complete,
ignoring any exceptions. After this call, any call on the supplied futures will not block since
they have already completed (successfully or exceptionally).futures - to execute and then wait ondefault void executeAndWait(long timeout,
TimeUnit timeUnit,
CompletableFuture<?>... futures)
executeAndWait(long, CompletableFuture[]) with TimeUnit option.timeout - to settimeUnit - unitsfutures - to executvoid executeAndWait(long timeoutMs,
CompletableFuture<?>... futures)
executeAndWait(CompletableFuture[]), but establishes a timeout which will affect
execution as defined by the TimeoutStrategy in effect.timeoutMs - timout in millisecondsfutures - to executeCompletableFuture<Boolean> fate(CompletableFuture<?>... cfs)
TaskNotStartedException 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.
cfs - to tie togetherdefault CompletableFuture<Void> cond(CompletableFuture<Boolean> condition, CompletableFuture<Void> thenFuture)
condition - to first evaluatethenFuture - to execute if condition evaluates to trueCompletableFuture<Void> cond(CompletableFuture<Boolean> condition, CompletableFuture<Void> thenFuture, boolean thenActivate)
cond(CompletableFuture, CompletableFuture) with an additional boolean argument
indicating whether to proactively start executing thenFuture at the same time as condition.
Executing 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.
condition - to first evaluatethenFuture - to execute if condition evaluates to truethenActivate - iff true then start executing at same time as conditiondefault <R> CompletableFuture<R> cond(CompletableFuture<Boolean> condition, CompletableFuture<R> thenFuture, CompletableFuture<R> elseFuture)
R - type of return resultcondition - to first evaluatethenFuture - chosen if condition evaluates to trueelseFuture - chosen if condition evaluates to false<R> CompletableFuture<R> cond(CompletableFuture<Boolean> condition, CompletableFuture<R> thenFuture, boolean thenActivate, CompletableFuture<R> elseFuture, boolean elseActivate)
cond(CompletableFuture, CompletableFuture, CompletableFuture) with additional boolean
arguments indicating whether to proactively start executing thenFuture and/or elseFuture when
condition is activated. Executing 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.R - type of return resultcondition - to first evaluatethenFuture - chosen if condition evaluates to truethenActivate - iff true then start executing at same time as conditionelseFuture - chosen if condition evaluates to falseelseActivate - iff true then start executing at same time as condition<BASE,SUB extends TaskInterface<BASE>> BASE task(SUB userTask)
execute(CompletionStage[]) or any of its variants.
Because of that lazy evaluation, tasks can be added with little performance penalty while only later choosing
which ones are actually needed.
The userTask argument can be freely wrapped any number of times by calling this method (as well as similar methods). In other words, there is a many-to-one relationship between these wrappers and the target user POJO, which may be of interest for stateful user POJO tasks or simply for avoiding the overhead of repeatedly creating user task instances. In the following example, 4 task wrappers around the same user POJO task instance are created:
MyTask myTask = new MyTask();
CompletableFuture f1 = $.task(myTask).doSomething();
CompletableFuture f2 = $.task(myTask).doSomething(); // or doSomethingElse()
MyTask wrapper = $.task(myTask);
CompletableFuture f3 = wrapper.doSomething();
CompletableFuture f4 = wrapper.doSomething(); // or doSomethingElse()
Note that a 'read operation' in this context refers to standard CompletableFuture access operations that
initiate execution. This includes simple operations such as CompletableFuture.get() as well as any
composition operations such as CompletableFuture.thenApply(Function) with the exception of the
'compose' variations such as CompletableFuture.thenCompose(Function) whose _fn_ argument can only be
started with execute(CompletionStage[]).
If a task method returns anything other than a CompletableFuture, it is executed right away, with any predecessors executed in the same thread-spawning manner as occurs when CompletableFutures are activated.
BASE - the interface for the taskSUB - the implementing class typeuserTask - any userTask with an interface that extends TaskInterfacedefault <TASK,R> CompletableFuture<R> task(TASK userTask, Function<TASK,R> fn)
CompletableFuture<String> cf = $.task(new Pojo(),p->p.anyMethod());
return cf.get();
</pre>
This is a modest improvement over simply using the function-task alternatives defined below:
<pre>
CompletableFuture<String> cf = $.fn(new Pojo().anyMethod());
return cf.get();
TASK - pojo's classR - type of return resultuserTask - pojo taskfn - function to apply to that pojo if/when task is activateddefault <TASK> CompletableFuture<Void> voidTask(TASK userTask, Consumer<TASK> fn)
TASK - type of user taskuserTask - pojo taskfn - Consumer function (returns no value)default <R> SupplierTask<R> fnTask(Supplier<R> fn)
R - type of return resultfn - function to apply to that pojo if/when task is activateddefault <R> CompletableFuture<R> fn(Supplier<R> fn)
R - type of return resultfn - function to apply to that pojo if/when task is activateddefault <IN,R> SupplierTask<R> fnTask(Supplier<IN> s1, Function<IN,R> fn)
IN - type of inputR - type of return results1 - Supplier function (returns a value)fn - function to apply to that pojo if/when task is activateddefault <IN,R> CompletableFuture<R> fn(Supplier<IN> s1, Function<IN,R> fn)
IN - type of inputR - type of return results1 - Supplier function (returns a value)fn - function to apply to that pojo if/when task is activateddefault <IN,R> SupplierTask<R> fnTask(CompletableFuture<IN> in, Function<IN,R> fn)
IN - base type of inputR - type of return resultin - provides result to be applied to functionfn - function to apply to that pojo if/when task is activateddefault <IN,R> CompletableFuture<R> fn(CompletableFuture<IN> in, Function<IN,R> fn)
IN - base type of inputR - type of return resultin - provides result to be applied to functionfn - function to apply to that pojo if/when task is activateddefault <IN1,IN2,R> SupplierTask<R> fnTask(CompletableFuture<IN1> in1, CompletableFuture<IN2> in2, BiFunction<IN1,IN2,R> fn)
IN1 - base type of input1IN2 - base type of input2R - type of return resultin1 - provides first value for fnin2 - provides second value for fnfn - function to apply to that pojo if/when task is activateddefault <IN1,IN2,R> CompletableFuture<R> fn(CompletableFuture<IN1> in1, CompletableFuture<IN2> in2, BiFunction<IN1,IN2,R> fn)
IN1 - base type of input1IN2 - base type of input2R - type of return resultin1 - provides first value for fnin2 - provides second value for fnfn - function to apply to that pojo if/when task is activateddefault <IN1,IN2,R> SupplierTask<R> fnTask(Supplier<IN1> s1, CompletableFuture<IN2> in2, BiFunction<IN1,IN2,R> fn)
IN1 - type of input1IN2 - base type of input2R - type of return results1 - provides first value for fnin2 - provides second value for fnfn - function to apply to that pojo if/when task is activateddefault <IN1,IN2,R> CompletableFuture<R> fn(Supplier<IN1> s1, CompletableFuture<IN2> in2, BiFunction<IN1,IN2,R> fn)
IN1 - type of input1IN2 - base type of input2R - type of return results1 - provides first value for fnin2 - provides second value for fnfn - function to apply to that pojo if/when task is activateddefault <IN1,IN2,R> SupplierTask<R> fnTask(CompletableFuture<IN1> in1, Supplier<IN2> s2, BiFunction<IN1,IN2,R> fn)
IN1 - base type of input1IN2 - type of input2R - type of return resultin1 - provides first value for fns2 - provides second value for fnfn - function to apply to that pojo if/when task is activateddefault <IN1,IN2,R> CompletableFuture<R> fn(CompletableFuture<IN1> in1, Supplier<IN2> s2, BiFunction<IN1,IN2,R> fn)
IN1 - base type of input1IN2 - type of input2R - type of return resultin1 - provides first value for fns2 - provides second value for fnfn - function to apply to that pojo if/when task is activateddefault <IN1,IN2,R> SupplierTask<R> fnTask(Supplier<IN1> s1, Supplier<IN2> s2, BiFunction<IN1,IN2,R> fn)
IN1 - type of input1IN2 - type of input2R - type of return results1 - provides first value for fns2 - provides second value for fnfn - function to apply to that pojo if/when task is activateddefault <IN1,IN2,R> CompletableFuture<R> fn(Supplier<IN1> s1, Supplier<IN2> s2, BiFunction<IN1,IN2,R> fn)
IN1 - type of input1IN2 - type of input2R - type of return results1 - provides first value for fns2 - provides second value for fnfn - function to apply to that pojo if/when task is activateddefault <IN> ConsumerTask vfnTask(Supplier<IN> s1, Consumer<IN> fn)
IN - type of input1s1 - provides value for fnfn - function to apply to that pojo if/when task is activateddefault <IN> CompletableFuture<Void> vfn(Supplier<IN> s1, Consumer<IN> fn)
IN - type of input1s1 - provides value for fnfn - function to apply to that pojo if/when task is activateddefault <IN1,IN2> ConsumerTask vfnTask(CompletableFuture<IN1> cf1, Supplier<IN2> s2, BiConsumer<IN1,IN2> fn)
IN1 - 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 activateddefault <IN1,IN2> CompletableFuture<Void> vfn(CompletableFuture<IN1> cf1, Supplier<IN2> s2, BiConsumer<IN1,IN2> fn)
IN1 - 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 activateddefault <IN1,IN2> ConsumerTask vfnTask(CompletableFuture<IN1> cf1, CompletableFuture<IN2> cf2, BiConsumer<IN1,IN2> fn)
IN1 - 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 activateddefault <IN1,IN2> CompletableFuture<Void> vfn(CompletableFuture<IN1> cf1, CompletableFuture<IN2> cf2, BiConsumer<IN1,IN2> fn)
IN1 - 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 activateddefault <IN1,IN2> ConsumerTask vfnTask(Supplier<IN1> s1, CompletableFuture<IN2> cf2, BiConsumer<IN1,IN2> fn)
IN1 - 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 activateddefault <IN1,IN2> CompletableFuture<Void> vfn(Supplier<IN1> s1, CompletableFuture<IN2> cf2, BiConsumer<IN1,IN2> fn)
IN1 - 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 activateddefault <IN1,IN2> ConsumerTask vfnTask(Supplier<IN1> s1, Supplier<IN2> s2, BiConsumer<IN1,IN2> fn)
IN1 - 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 activateddefault <IN1,IN2> CompletableFuture<Void> vfn(Supplier<IN1> s1, Supplier<IN2> s2, BiConsumer<IN1,IN2> fn)
IN1 - 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 activatedCopyright © 2021. All rights reserved.