public interface Async
This type is intended to be passed around in your application, preferably through dependency injection.
It makes the contract between the framework and your application decoupled, which has several benefits for your application's code (see README for details).
Modifier and Type | Method and Description |
---|---|
<T> Stage<T> |
call(Callable<? extends T> callable)
Call the given callable on the default executor and track the result using a completable.
|
<T> Stage<T> |
call(Callable<? extends T> callable,
ExecutorService executor)
Call the given callable on the provided executor and track the result using a completable.
|
<T> Stage<T> |
cancelled()
Build an immediately cancelled completable.
|
<T> Stage<Collection<T>> |
collect(Collection<? extends Stage<? extends T>> stages)
Build a new completable that is the result of collecting all the results in a collection.
|
<T,U> Stage<U> |
collect(Collection<? extends Stage<? extends T>> stages,
Function<? super Collection<T>,? extends U> collector)
Build a new completable that is the result of reducing the provided collection of stages using
the provided collector.
|
default <T> Stage<Collection<T>> |
collect(Stream<? extends Stage<T>> stream)
Collect the result of multiple stages from a stream.
|
Stage<Void> |
collectAndDiscard(Collection<? extends Stage<?>> stages)
Collect the results from a collection of stages, then discard them.
|
default Stage<Void> |
collectAndDiscard(Stream<? extends Stage<?>> stream)
Collect the results from a stream of stages, then discard them.
|
<T> Completable<T> |
completable()
Build a new resolvable completable.
|
Stage<Void> |
completed()
Returns an already completed void completable.
|
<T> Stage<T> |
completed(T value)
Build an already completed completable.
|
<T,U> Stage<U> |
eventuallyCollect(Collection<? extends Callable<? extends Stage<? extends T>>> callables,
Consumer<? super T> consumer,
Supplier<? extends U> supplier,
int parallelism)
Collect the result from a collection of operations that are lazily created.
|
<T> Stage<T> |
failed(Throwable e)
Build an already failed completable.
|
<T> Managed<T> |
managed(Supplier<? extends Stage<T>> setup,
Function<? super T,? extends Stage<Void>> teardown)
Setup a managed reference.
|
<T> ReloadableManaged<T> |
reloadableManaged(Supplier<? extends Stage<T>> setup,
Function<? super T,? extends Stage<Void>> teardown)
Setup a reloadable, managed reference.
|
<T> Stage<RetryResult<T>> |
retryUntilCompleted(Callable<? extends Stage<T>> callable,
RetryPolicy policy)
Retry the given action until it has been completed, or the provided
RetryPolicy expire. |
<T> Stage<RetryResult<T>> |
retryUntilCompleted(Callable<? extends Stage<T>> callable,
RetryPolicy policy,
ClockSource clockSource)
Retry the given action until it has been completed, or the provided
RetryPolicy expire. |
<T,U> Stage<U> |
streamCollect(Collection<? extends Stage<? extends T>> stages,
Consumer<? super T> consumer,
Supplier<? extends U> supplier)
Build a new stage that is the result of applying a computation on a collection of stages.
|
<T> Completable<T> completable()
The completable is returned in a running state, and can be completed, failed, or cancelled.
See documentation for Stage
for details on the various states.
T
- type of the completable.Stage<Void> completed()
The completable is immediately completed with a null
value.
completed(Object)
<T> Stage<T> completed(T value)
T
- type of the completablevalue
- value which the completable was completed using<T> Stage<T> failed(Throwable e)
T
- type of the completable.e
- The Error which the completable is failed using.<T> Stage<T> cancelled()
T
- type of the completabledefault <T> Stage<Collection<T>> collect(Stream<? extends Stage<T>> stream)
T
- type of the collected stagesstream
- stream to collect stages from<T> Stage<Collection<T>> collect(Collection<? extends Stage<? extends T>> stages)
T
- type of the collected completablestages
- the collection of stages<T,U> Stage<U> collect(Collection<? extends Stage<? extends T>> stages, Function<? super Collection<T>,? extends U> collector)
T
- source type of the collected stagesU
- target type the collected stages are being transformed intostages
- the collection of stagescollector
- the collector<T,U> Stage<U> streamCollect(Collection<? extends Stage<? extends T>> stages, Consumer<? super T> consumer, Supplier<? extends U> supplier)
This is similar to collect(Collection, Function)
, but uses abstractions which
operates on the stream of results as they arrive.
This allows the implementor to reduce memory usage for certain operations since all results does not have to be collected.
If the returned stage ends up in a non-completed state, this will be forwarded to the given list of stages as well.
T
- source type of the collected stagesU
- target type of the collectorstages
- the collection of stagesconsumer
- value consumersupplier
- result supplierdefault Stage<Void> collectAndDiscard(Stream<? extends Stage<?>> stream)
stream
- stream to collect results fromStage<Void> collectAndDiscard(Collection<? extends Stage<?>> stages)
Signals like cancellations and failures will be communicated in a similar fashion to streamCollect(Collection, Consumer, Supplier)
.
stages
- collection to collect<T,U> Stage<U> eventuallyCollect(Collection<? extends Callable<? extends Stage<? extends T>>> callables, Consumer<? super T> consumer, Supplier<? extends U> supplier, int parallelism)
Async will be created using the given callables
, but will only create as many
pending stages to be less than or equal to the given parallelism
setting.
If a single completable is cancelled, or failed, all the other will be as well.
This method is intended to be used for rate-limiting requests that could potentially be difficult to stop cleanly, or would use too many parallel resources.
A common example is when querying a database for many distinct things, you typically want to initiating all requests at the same time.
T
- source type of the collected stagesU
- target type the collected stages are being transformed intocallables
- the collection of operationsconsumer
- value consumersupplier
- result supplierparallelism
- number of stages that are allowed to be pending at the same time<T> Stage<T> call(Callable<? extends T> callable)
T
- type of the operationcallable
- operation to callIllegalStateException
- if no default executor service is configuredcall(Callable, ExecutorService)
<T> Stage<T> call(Callable<? extends T> callable, ExecutorService executor)
T
- type of the operationcallable
- operation to callexecutor
- executor service to invoke on<T> Managed<T> managed(Supplier<? extends Stage<T>> setup, Function<? super T,? extends Stage<Void>> teardown)
T
- type of the managed referencesetup
- setup method for the managed referenceteardown
- teardown method for the manager reference<T> ReloadableManaged<T> reloadableManaged(Supplier<? extends Stage<T>> setup, Function<? super T,? extends Stage<Void>> teardown)
T
- type of the managed referencesetup
- the setup method for the managed referenceteardown
- teardown method for the manager reference<T> Stage<RetryResult<T>> retryUntilCompleted(Callable<? extends Stage<T>> callable, RetryPolicy policy)
RetryPolicy
expire.T
- the type returned by the actioncallable
- action to runpolicy
- retry policy to useretryUntilCompleted(java.util.concurrent.Callable, RetryPolicy, ClockSource)
<T> Stage<RetryResult<T>> retryUntilCompleted(Callable<? extends Stage<T>> callable, RetryPolicy policy, ClockSource clockSource)
RetryPolicy
expire.T
- the type returned by the actioncallable
- action to runpolicy
- retry policy to useclockSource
- clock source to useCopyright © 2017. All rights reserved.