Modifier and Type | Class and Description |
---|---|
static class |
CoreAsync.Builder
Builder for
CoreAsync . |
Constructor and Description |
---|
CoreAsync() |
Modifier and Type | Method and Description |
---|---|
static CoreAsync.Builder |
builder()
Build a new CoreAsync instance.
|
<C> Stage<C> |
call(Callable<? extends C> callable)
Call the given callable on the default executor and track the result using a completable.
|
<C> Stage<C> |
call(Callable<? extends C> callable,
ExecutorService executor)
Call the given callable on the provided executor and track the result using a completable.
|
Caller |
caller() |
<T> Stage<T> |
cancelled()
Build an immediately cancelled completable.
|
<C,T> Stage<T> |
collect(Collection<? extends Stage<? extends C>> stages,
Function<? super Collection<C>,? extends T> collector)
Build a new completable that is the result of reducing the provided collection of stages using
the provided collector.
|
<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.
|
Stage<Void> |
collectAndDiscard(Collection<? extends Stage<?>> stages)
Collect the results from a collection 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.
|
<C> Stage<C> |
doCall(Callable<? extends C> callable,
ExecutorService executor,
Completable<C> stage) |
protected <C,T> Stage<T> |
doCollect(Collection<? extends Stage<? extends C>> stages,
Function<? super Collection<C>,? extends T> collector) |
<C,T> Stage<T> |
eventuallyCollect(Collection<? extends Callable<? extends Stage<? extends C>>> callables,
Consumer<? super C> consumer,
Supplier<? extends T> supplier,
int parallelism)
Collect the result from a collection of operations that are lazily created.
|
ExecutorService |
executor()
Fetch the configured primary executor (if any).
|
<T> Stage<T> |
failed(Throwable e)
Build an already failed completable.
|
<C> Managed<C> |
managed(Supplier<? extends Stage<C>> setup,
Function<? super C,? extends Stage<Void>> teardown)
Setup a managed reference.
|
<C> ReloadableManaged<C> |
reloadableManaged(Supplier<? extends Stage<C>> setup,
Function<? super C,? 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.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
collect, collectAndDiscard
public ExecutorService executor()
IllegalStateException
- if no caller executor is available.public Caller caller()
public <C> Stage<C> call(Callable<? extends C> callable)
Async
call
in interface Async
C
- type of the operationcallable
- operation to callAsync.call(Callable, ExecutorService)
public <C> Stage<C> call(Callable<? extends C> callable, ExecutorService executor)
Async
public <C> Stage<C> doCall(Callable<? extends C> callable, ExecutorService executor, Completable<C> stage)
public <T> Completable<T> completable()
Async
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.
completable
in interface Async
T
- type of the completable.public Stage<Void> completed()
Async
The completable is immediately completed with a null
value.
completed
in interface Async
Async.completed(Object)
public <T> Stage<T> completed(T value)
Async
public <T> Stage<T> failed(Throwable e)
Async
public <T> Stage<T> cancelled()
Async
public <T> Stage<Collection<T>> collect(Collection<? extends Stage<? extends T>> stages)
Async
public <C,T> Stage<T> collect(Collection<? extends Stage<? extends C>> stages, Function<? super Collection<C>,? extends T> collector)
Async
protected <C,T> Stage<T> doCollect(Collection<? extends Stage<? extends C>> stages, Function<? super Collection<C>,? extends T> collector)
public <T,U> Stage<U> streamCollect(Collection<? extends Stage<? extends T>> stages, Consumer<? super T> consumer, Supplier<? extends U> supplier)
Async
This is similar to Async.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.
streamCollect
in interface Async
T
- source type of the collected stagesU
- target type of the collectorstages
- the collection of stagesconsumer
- value consumersupplier
- result supplierpublic <C,T> Stage<T> eventuallyCollect(Collection<? extends Callable<? extends Stage<? extends C>>> callables, Consumer<? super C> consumer, Supplier<? extends T> supplier, int parallelism)
Async
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.
eventuallyCollect
in interface Async
C
- source type of the collected stagesT
- 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 timepublic Stage<Void> collectAndDiscard(Collection<? extends Stage<?>> stages)
Async
Signals like cancellations and failures will be communicated in a similar fashion to Async.streamCollect(Collection, Consumer, Supplier)
.
collectAndDiscard
in interface Async
stages
- collection to collectpublic <C> Managed<C> managed(Supplier<? extends Stage<C>> setup, Function<? super C,? extends Stage<Void>> teardown)
Async
public <C> ReloadableManaged<C> reloadableManaged(Supplier<? extends Stage<C>> setup, Function<? super C,? extends Stage<Void>> teardown)
Async
reloadableManaged
in interface Async
C
- type of the managed referencesetup
- the setup method for the managed referenceteardown
- teardown method for the manager referencepublic <T> Stage<RetryResult<T>> retryUntilCompleted(Callable<? extends Stage<T>> callable, RetryPolicy policy)
Async
RetryPolicy
expire.retryUntilCompleted
in interface Async
T
- the type returned by the actioncallable
- action to runpolicy
- retry policy to useAsync.retryUntilCompleted(java.util.concurrent.Callable, RetryPolicy, ClockSource)
public <T> Stage<RetryResult<T>> retryUntilCompleted(Callable<? extends Stage<T>> callable, RetryPolicy policy, ClockSource clockSource)
Async
RetryPolicy
expire.retryUntilCompleted
in interface Async
T
- the type returned by the actioncallable
- action to runpolicy
- retry policy to useclockSource
- clock source to usepublic static CoreAsync.Builder builder()
Copyright © 2017. All rights reserved.