public abstract class AbstractRequest<T> extends CompletableFuture<T> implements Callable<Void>, Request<T>
Thread-safety: This class and its sub-classes are thread-safe. They use the ResponseCollector
's monitor
for synchronization, so that collectors usually don't need any explicit synchronization.
CompletableFuture.AsynchronousCompletionTask
Modifier and Type | Field and Description |
---|---|
protected RequestRepository |
repository |
protected long |
requestId |
protected ResponseCollector<T> |
responseCollector |
NO_REQUEST_ID
Modifier | Constructor and Description |
---|---|
protected |
AbstractRequest(long requestId,
ResponseCollector<T> responseCollector,
RequestRepository repository) |
Modifier and Type | Method and Description |
---|---|
Void |
call() |
boolean |
cancel(boolean mayInterruptIfRunning) |
void |
cancel(Exception exception)
Complete the request with an exception and release its resources.
|
boolean |
complete(T value) |
boolean |
completeExceptionally(Throwable ex) |
long |
getRequestId() |
protected abstract void |
onTimeout()
Called when the timeout task scheduled with
setTimeout(ScheduledExecutorService, long, TimeUnit) expires. |
void |
setTimeout(ScheduledExecutorService timeoutExecutor,
long timeout,
TimeUnit unit)
Schedule a timeout task on the given executor, and complete the request with a
TimeoutException
when the task runs. |
acceptEither, acceptEitherAsync, acceptEitherAsync, allOf, anyOf, applyToEither, applyToEitherAsync, applyToEitherAsync, completedFuture, exceptionally, get, get, getNow, getNumberOfDependents, handle, handleAsync, handleAsync, isCancelled, isCompletedExceptionally, isDone, join, obtrudeException, obtrudeValue, runAfterBoth, runAfterBothAsync, runAfterBothAsync, runAfterEither, runAfterEitherAsync, runAfterEitherAsync, runAsync, runAsync, supplyAsync, supplyAsync, thenAccept, thenAcceptAsync, thenAcceptAsync, thenAcceptBoth, thenAcceptBothAsync, thenAcceptBothAsync, thenApply, thenApplyAsync, thenApplyAsync, thenCombine, thenCombineAsync, thenCombineAsync, thenCompose, thenComposeAsync, thenComposeAsync, thenRun, thenRunAsync, thenRunAsync, toCompletableFuture, toString, whenComplete, whenCompleteAsync, whenCompleteAsync
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
onNewView, onResponse
acceptEither, acceptEitherAsync, acceptEitherAsync, applyToEither, applyToEitherAsync, applyToEitherAsync, exceptionally, handle, handleAsync, handleAsync, runAfterBoth, runAfterBothAsync, runAfterBothAsync, runAfterEither, runAfterEitherAsync, runAfterEitherAsync, thenAccept, thenAcceptAsync, thenAcceptAsync, thenAcceptBoth, thenAcceptBothAsync, thenAcceptBothAsync, thenApply, thenApplyAsync, thenApplyAsync, thenCombine, thenCombineAsync, thenCombineAsync, thenCompose, thenComposeAsync, thenComposeAsync, thenRun, thenRunAsync, thenRunAsync, toCompletableFuture, whenComplete, whenCompleteAsync, whenCompleteAsync
protected final ResponseCollector<T> responseCollector
protected final long requestId
protected final RequestRepository repository
protected AbstractRequest(long requestId, ResponseCollector<T> responseCollector, RequestRepository repository)
protected abstract void onTimeout()
setTimeout(ScheduledExecutorService, long, TimeUnit)
expires.public final long getRequestId()
getRequestId
in interface Request<T>
public void setTimeout(ScheduledExecutorService timeoutExecutor, long timeout, TimeUnit unit)
TimeoutException
when the task runs.
If a timeout task was already registered with this request, it is cancelled.public void cancel(Exception exception)
Request
public boolean complete(T value)
complete
in class CompletableFuture<T>
public boolean completeExceptionally(Throwable ex)
completeExceptionally
in class CompletableFuture<T>
public boolean cancel(boolean mayInterruptIfRunning)
Copyright © 2021 JBoss by Red Hat. All rights reserved.