public interface Orchestrator extends CommonConfig
The prototypical use of this class involves adding a POJO task class to this orchestrator, calling one of its task methods, activating that method, and retrieving the result. These operations are commonly performed together as in the following example:
1. Orchestrator $ = Orchestrator.create(); 2. CompletableFuture<T> future = $.task(new MyTask()).myMethod(...); 3. T value = future.get();The task class that is added to this Orchestrator through the call to
$.task() at line 2 can take can
be any class that implements TaskInterface. A wrapper is returned that enables the subsequent call to
myMethod to have its dependencies recorded but not yet (at that point) be activated; the returned
CompletableFuture is not and will not be completed until activation occurs. In the example above, activation
occurs implicitly through the call to get() at line 3.
Explicit activation can also be done by calling activate(CompletableFuture) on this class. There are
a number of variations of the activate method providing different semantics for completion guarantees
and return results. Explicitly calling activate is also the only way to activate multiple
CompletableFutures at once, which can be desirable for maximizing parallelism.
Exceptions thrown from task methods are propagated to the caller, regardless of thread, through the
CompletableFutures returned by those task methods, e.g. by calling CompletableFuture.get() or
CompletableFuture.handle(BiFunction). As seen in any resulting stack trace, whatever operation that
initiated activation will be the starting point, even though the exception might not be visible until a later point
in the code. Thus one might get an exception on a call to get() that if activated separately from the
get will have only reflect the activating stack trace.
There is no limit on the number of orchestrators created. They are thread-safe and relatively lightweight. Task activation/execution is only tied to its orchestrator for configuration purposes. Tasks from different orchestrators can be freely intermixed.
| Modifier and Type | Method and Description |
|---|---|
default void |
activate(CompletableFuture<?>... futures)
Activates (enables for execution) the task methods behind each supplied CompletableFuture if they were
generated through BascomTask and if they are have not already been activated.
|
default <T> CompletableFuture<T> |
activate(CompletableFuture<T> future)
Variant of
activate(CompletableFuture[] futures) that accepts only a single CompletableFuture
argument and returns that same argument after having activated it. |
void |
activate(long timeoutMs,
CompletableFuture<?>... futures)
Variant of
activate(CompletableFuture[]) that will timeout according to the TimeoutStrategy
* in effect. |
<T> CompletableFuture<T> |
activate(long timeoutMs,
CompletableFuture<T> future) |
default void |
activate(long timeout,
TimeUnit timeUnit,
CompletableFuture<?>... futures)
Variant of
activate(long, CompletableFuture[]) with TimeUnit option. |
default <T> CompletableFuture<T> |
activate(long timeout,
TimeUnit timeUnit,
CompletableFuture<T> future) |
default void |
activateAndWait(CompletableFuture<?>... futures)
Variant of
activate(CompletableFuture[]) that waits for all of its arguments to complete
(successfully or exceptionally). |
default <T> CompletableFuture<T> |
activateAndWait(CompletableFuture<T> future) |
default <T> List<T> |
activateAndWait(List<CompletableFuture<T>> futures)
Variant of
activateAndWait(CompletableFuture[]) that returns a typed result from typed input. |
void |
activateAndWait(long timeoutMs,
CompletableFuture<?>... futures)
Variant of
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
activateAndWait(long timeout, CompletableFuture[]) that returns a typed result
matching the supplied typed input. |
default void |
activateAndWait(long timeout,
TimeUnit timeUnit,
CompletableFuture<?>... futures)
Variant of
activateAndWait(long, CompletableFuture[]) with TimeUnit option. |
default <T> CompletableFuture<T> |
activateAndWait(long timeout,
TimeUnit timeUnit,
CompletableFuture<T> future)
Activates then returns its single argument.
|
default <T> List<T> |
activateAndWait(long timeout,
TimeUnit timeUnit,
List<CompletableFuture<T>> futures)
Variant of
activateAndWait(long timeout, List) with TimeUnit option. |
default <T> void |
activateAsReady(List<CompletableFuture<T>> futures,
TriConsumer<T,Throwable,Integer> completionFn)
Variant of
activateAsReady(long, List, TriConsumer) without a timeout. |
<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.
|
default <T> void |
activateAsReady(long timeout,
TimeUnit timeUnit,
List<CompletableFuture<T>> futures,
TriConsumer<T,Throwable,Integer> completionFn)
Variant of
activateAsReady(long, List, TriConsumer) TimeUnit option. |
default <T> CompletableFuture<List<T>> |
activateFuture(List<CompletableFuture<T>> futures)
Initiates asynchronous activation on the supplied futures all using spawned threads, keeping the calling thread
free.
|
<T> CompletableFuture<List<T>> |
activateFuture(long timeoutMs,
List<CompletableFuture<T>> futures)
Variant of
activateFuture(List) that will timeout according to the TimeoutStrategy in effect |
default <T> CompletableFuture<List<T>> |
activateFuture(long timeout,
TimeUnit timeUnit,
List<CompletableFuture<T>> futures)
Variant of
activateFuture(long, List) with TimeUnit option. |
default <R> CompletableFuture<Optional<R>> |
cond(CompletableFuture<Boolean> condition,
CompletableFuture<R> thenFuture)
Activate the supplied CompletableFuture if the supplied condition evaluates to true.
|
<R> CompletableFuture<Optional<R>> |
cond(CompletableFuture<Boolean> condition,
CompletableFuture<R> thenFuture,
boolean thenActivate)
Variant of
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
cond(CompletableFuture, CompletableFuture, CompletableFuture) with additional boolean
arguments indicating whether to proactively activate thenFuture and/or elseFuture when
condition is activated. |
default <R> CompletableFuture<R> |
cond(CompletableFuture<Boolean> condition,
CompletableFuture<R> thenFuture,
CompletableFuture<R> elseFuture)
Activate one of two choices depending on the result of the supplied condition.
|
static Orchestrator |
create()
Creates an Orchestrator with no name.
|
static Orchestrator |
create(String name)
Creates a new named Orchestrator with the supplied name.
|
static Orchestrator |
create(String name,
Object arg)
Creates an Orchestrator with the given name and argument.
|
static Orchestrator |
current()
Returns the orchestrator used to activate the current task method in the current thread.
|
default void |
execute(CompletableFuture<?>... futures)
Deprecated.
|
default void |
execute(long timeoutMs,
CompletableFuture<?>... futures)
Deprecated.
|
default void |
execute(long timeout,
TimeUnit timeUnit,
CompletableFuture<?>... futures)
Deprecated.
|
default void |
executeAndWait(CompletableFuture<?>... futures)
Deprecated.
|
default void |
executeAndWait(long timeoutMs,
CompletableFuture<?>... futures)
Deprecated.
|
default void |
executeAndWait(long timeout,
TimeUnit timeUnit,
CompletableFuture<?>... futures)
Deprecated.
|
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 <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 <T,U,R> CompletableFuture<R> |
fn(CompletableFuture<T> firstInput,
CompletableFuture<U> secondInput,
BiFunction<T,U,R> fn)
Produces function result from two arguments.
|
default <T,R> CompletableFuture<R> |
fn(CompletableFuture<T> input,
Function<T,R> fn)
Produces function result from one argument.
|
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 <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.
|
<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.
|
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.
|
<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.
|
String |
getName()
Name as set from
create(String) or setName(String). |
TaskMeta |
getTaskMeta(CompletableFuture<?> cf)
Returns details for any future previously registered with
activate(CompletableFuture[]) (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 POJO class whose interface X in turn implements TaskInterface<X>.
|
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.
|
<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.
|
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, removeAllInterceptors, removeInterceptor, restoreConfigurationDefaults, restoreDefaultExecutorService, setExecutorService, setSpawnMode, setTimeout, setTimeoutMs, setTimeoutStrategystatic Orchestrator create()
static Orchestrator create(String name)
setName(name).name - for orchestrator, useful in logging outputstatic Orchestrator create(String name, Object arg)
name - optional / possibly null for this orchestrator, useful for loggingarg - to pass to GlobalOrchestratorConfig.Config.updateConfigurationOn(Orchestrator, Object).static Orchestrator current()
The mechanism here uses ThreadLocal and is therefore thread-safe. It works for all cases even when the processing thread comes from the completion of CompletableFuture outside of BascomTask's control.
String getName()
create(String) or setName(String).void setName(String name)
name - to setTaskMeta getTaskMeta(CompletableFuture<?> cf)
activate(CompletableFuture[]) (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 activate(CompletableFuture<?>... futures)
The actual execution of a task method will take place as soon as all of its CompletableFuture inputs (if any) have completed (thus accessing a CompletableFuture inside a task method will never block). The execution sequencing and thread assignment is determined automatically.
Each task method will only be activated/executed only once even if passed multiple times to this method
or any of its variants or access operations such as CompletableFuture.get() that implicitly call
this method. As compared with the latter (where a single future is activated) this method call is only needed
to start multiple futures at the same time, or for starting tasks whose purpose is to perform a side-effect
that occurs without any other call to access its a value from it, or for any other situation where an access
of its value is not possible nor desirable.
In contrast to activateAndWait(CompletableFuture[]), this call does not necessarily wait for any
of the activated task methods to finish executing. More specifically, it does not wait on any threads that
might be spawned to finish. Thus calls such as CompletableFuture.get(), made after calling this
method, may block.
Exceptions may be thrown from activated task methods but are not immediately thrown by this call even if the task method completes prior to its return. Those exceptions are instead exposed through the CompletableFutures being passed as arguments.
futures - to activatedefault <T> CompletableFuture<T> activate(CompletableFuture<T> future)
activate(CompletableFuture[] futures) that accepts only a single CompletableFuture
argument and returns that same argument after having activated it. This is provided as a convenient way to
activate CompletableFutures for chaining, e.g.:
$.task.activate(future).thenAccept(v->doSomethingWith(v));
T - type of argumentfuture - to activatedefault void activate(long timeout,
TimeUnit timeUnit,
CompletableFuture<?>... futures)
activate(long, CompletableFuture[]) with TimeUnit option.timeout - to settimeUnit - time units to apply to timeoutfutures - to activatedefault <T> CompletableFuture<T> activate(long timeout, TimeUnit timeUnit, CompletableFuture<T> future)
<T> CompletableFuture<T> activate(long timeoutMs, CompletableFuture<T> future)
void activate(long timeoutMs,
CompletableFuture<?>... futures)
activate(CompletableFuture[]) that will timeout according to the TimeoutStrategy
* in effect.timeoutMs - timout in millisecondsfutures - to activate@Deprecated default void execute(CompletableFuture<?>... futures)
activate(CompletableFuture[]) instead.futures - to activate@Deprecated default void execute(long timeoutMs, CompletableFuture<?>... futures)
activate(long,CompletableFuture[]) instead.timeoutMs - timout in millisecondsfutures - to activate@Deprecated default void execute(long timeout, TimeUnit timeUnit, CompletableFuture<?>... futures)
activate(long,TimeUnit,CompletableFuture[]) instead.timeout - timout in millisecondstimeUnit - time units to apply to timeoutfutures - to activatedefault void activateAndWait(CompletableFuture<?>... futures)
activate(CompletableFuture[]) that waits for all of its arguments to complete
(successfully or exceptionally). After this call, any call on the supplied futures will not block since
they will have already completed (successfully or exceptionally).futures - to activate and then wait ondefault <T> CompletableFuture<T> activateAndWait(CompletableFuture<T> future)
default void activateAndWait(long timeout,
TimeUnit timeUnit,
CompletableFuture<?>... futures)
activateAndWait(long, CompletableFuture[]) with TimeUnit option.timeout - to settimeUnit - time units to apply to timeoutfutures - to activatedefault <T> CompletableFuture<T> activateAndWait(long timeout, TimeUnit timeUnit, CompletableFuture<T> future)
T - type of argumenttimeout - to settimeUnit - time units to apply to timeoutfuture - to activatevoid activateAndWait(long timeoutMs,
CompletableFuture<?>... futures)
activateAndWait(CompletableFuture[]) that will timeout according to the TimeoutStrategy
in effect.timeoutMs - timout in millisecondsfutures - to activate<T> CompletableFuture<T> activateAndWait(long timeoutMs, CompletableFuture<T> future)
@Deprecated default void executeAndWait(CompletableFuture<?>... futures)
activateAndWait(CompletableFuture[]) instead.futures - to activate@Deprecated default void executeAndWait(long timeout, TimeUnit timeUnit, CompletableFuture<?>... futures)
activateAndWait(long,TimeUnit,CompletableFuture[]) instead.timeout - to settimeUnit - time units to apply to timeoutfutures - to activate@Deprecated default void executeAndWait(long timeoutMs, CompletableFuture<?>... futures)
activateAndWait(long,CompletableFuture[]) instead.timeoutMs - timout in millisecondsfutures - default <T> List<T> activateAndWait(List<CompletableFuture<T>> futures)
activateAndWait(CompletableFuture[]) that returns a typed result from typed input.T - Type of list itemsfutures - to activatedefault <T> List<T> activateAndWait(long timeout, TimeUnit timeUnit, List<CompletableFuture<T>> futures)
activateAndWait(long timeout, List) with TimeUnit option.T - Type of list itemstimeout - to settimeUnit - time units to apply to timeoutfutures - to activate<T> List<T> activateAndWait(long timeoutMs, List<CompletableFuture<T>> futures)
activateAndWait(long timeout, CompletableFuture[]) that returns a typed result
matching the supplied typed input.T - Type of list itemstimeoutMs - timout in millisecondsfutures - to activatedefault <T> CompletableFuture<List<T>> activateFuture(List<CompletableFuture<T>> futures)
SpawnMode.NEVER_MAIN and invoking CompletableFuture.allOf(CompletableFuture[])
on the same set of futures, except that using this method does not interfere with whatever SpawnMode is
in effect. If, for example, SpawnMode.NEVER_SPAWN is set then calling this method will have no
effect since that SpawnMode forces everything to be run in the calling thread.T - Type of list itemsfutures - to activatedefault <T> CompletableFuture<List<T>> activateFuture(long timeout, TimeUnit timeUnit, List<CompletableFuture<T>> futures)
activateFuture(long, List) with TimeUnit option.T - Type of list itemstimeout - to settimeUnit - time units to apply to timeoutfutures - to activate<T> CompletableFuture<List<T>> activateFuture(long timeoutMs, List<CompletableFuture<T>> futures)
activateFuture(List) that will timeout according to the TimeoutStrategy in effectT - Type of list itemstimeoutMs - timout in millisecondsfutures - to activatedefault <T> void activateAsReady(List<CompletableFuture<T>> futures, TriConsumer<T,Throwable,Integer> completionFn)
activateAsReady(long, List, TriConsumer) without a timeout.T - type of each elementfutures - to activatecompletionFn - that will be called as many times as there are entries in the futures listdefault <T> void activateAsReady(long timeout,
TimeUnit timeUnit,
List<CompletableFuture<T>> futures,
TriConsumer<T,Throwable,Integer> completionFn)
activateAsReady(long, List, TriConsumer) TimeUnit option.T - type of each elementtimeout - to settimeUnit - time units to apply to timeoutfutures - to activatecompletionFn - that will be called as many times as there are entries in the futures list<T> void activateAsReady(long timeoutMs,
List<CompletableFuture<T>> futures,
TriConsumer<T,Throwable,Integer> completionFn)
Completion 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.
T - of each each elementtimeoutMs - timout in millisecondsfutures - to activatecompletionFn - that will be called as many times as there are entries in the futures listCompletableFuture<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 <R> CompletableFuture<Optional<R>> cond(CompletableFuture<Boolean> condition, CompletableFuture<R> thenFuture)
R - type of nested return valuecondition - to first evaluatethenFuture - to activate if condition evaluates to true<R> CompletableFuture<Optional<R>> cond(CompletableFuture<Boolean> condition, CompletableFuture<R> thenFuture, boolean thenActivate)
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.
R - type of nested return valuecondition - to first evaluatethenFuture - to activate if condition evaluates to truethenActivate - iff true then activate 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 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.R - 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 condition<BASE,SUB extends TaskInterface<BASE>> BASE task(SUB userTask)
X 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.
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)<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 activated<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 activated<T,R> SupplierTask<R> fnTask(CompletableFuture<T> input, Function<T,R> fn)
T - unwrapped type of inputR - unwrapped type of type of function resultinput - input to functionfn - function to apply to that pojo if/when task is activateddefault <T,R> CompletableFuture<R> fn(CompletableFuture<T> input, Function<T,R> fn)
T - unwrapped type of inputR - unwrapped type of function resultinput - input to functionfn - function to apply to input when activated<T,U,R> SupplierTask<R> fnTask(CompletableFuture<T> firstInput, CompletableFuture<U> secondInput, BiFunction<T,U,R> fn)
T - 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 activateddefault <T,U,R> CompletableFuture<R> fn(CompletableFuture<T> firstInput, CompletableFuture<U> secondInput, BiFunction<T,U,R> fn)
T - 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 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 activated<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 activated<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 activated<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 activated<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 activated<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.