Class OperationFutureImpl<ResponseT,MetadataT>
- All Implemented Interfaces:
ApiFuture<ResponseT>,OperationFuture<ResponseT,,MetadataT> Future<ResponseT>
TimedRetryAlgorithm.
This class is thread-safe.
This is public only for technical reasons, for advanced usage.
-
Constructor Summary
ConstructorsConstructorDescriptionOperationFutureImpl(RetryingFuture<OperationSnapshot> pollingFuture, ApiFuture<OperationSnapshot> initialFuture, ApiFunction<OperationSnapshot, ResponseT> responseTransformer, ApiFunction<OperationSnapshot, MetadataT> metadataTransformer) Creates a new operation future instance.OperationFutureImpl(RetryingFuture<OperationSnapshot> pollingFuture, ApiFuture<OperationSnapshot> initialFuture, ApiFunction<OperationSnapshot, ResponseT> responseTransformer, ApiFunction<OperationSnapshot, MetadataT> metadataTransformer, ApiFunction<Exception, ResponseT> exceptionTransformer) -
Method Summary
Modifier and TypeMethodDescriptionvoidaddListener(Runnable listener, Executor executor) booleancancel(boolean mayInterruptIfRunning) get()Returns theOperationSnapshotfuture of the initial request which started thisOperationFuture.Gets the metadata of the operation tracked by thisOperationFuture.getName()Returns the value of the name of the operation from the initial operation object returned from the initial call to start the operation.Returns theRetryingFuturewhich continues to pollOperationSnapshot.booleanbooleanisDone()Peeks at the metadata of the operation tracked by thisOperationFuture.
-
Constructor Details
-
OperationFutureImpl
public OperationFutureImpl(RetryingFuture<OperationSnapshot> pollingFuture, ApiFuture<OperationSnapshot> initialFuture, ApiFunction<OperationSnapshot, ResponseT> responseTransformer, ApiFunction<OperationSnapshot, MetadataT> metadataTransformer) Creates a new operation future instance.- Parameters:
pollingFuture- retrying future which tracks polling of the server operation (in most cases with exponential upper bounded intervals)initialFuture- the initial future which started the operation on the server side
-
OperationFutureImpl
public OperationFutureImpl(RetryingFuture<OperationSnapshot> pollingFuture, ApiFuture<OperationSnapshot> initialFuture, ApiFunction<OperationSnapshot, ResponseT> responseTransformer, ApiFunction<OperationSnapshot, MetadataT> metadataTransformer, ApiFunction<Exception, ResponseT> exceptionTransformer)
-
-
Method Details
-
addListener
- Specified by:
addListenerin interfaceApiFuture<ResponseT>
-
cancel
public boolean cancel(boolean mayInterruptIfRunning) -
isCancelled
public boolean isCancelled()- Specified by:
isCancelledin interfaceFuture<ResponseT>
-
isDone
public boolean isDone() -
get
- Specified by:
getin interfaceFuture<ResponseT>- Throws:
InterruptedExceptionExecutionException
-
get
public ResponseT get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException - Specified by:
getin interfaceFuture<ResponseT>- Throws:
InterruptedExceptionExecutionExceptionTimeoutException
-
getName
Description copied from interface:OperationFutureReturns the value of the name of the operation from the initial operation object returned from the initial call to start the operation. Blocks if the initial call to start the operation hasn't returned yet.- Specified by:
getNamein interfaceOperationFuture<ResponseT,MetadataT> - Throws:
ExecutionExceptionInterruptedException
-
getInitialFuture
Description copied from interface:OperationFutureReturns theOperationSnapshotfuture of the initial request which started thisOperationFuture.- Specified by:
getInitialFuturein interfaceOperationFuture<ResponseT,MetadataT>
-
getPollingFuture
Description copied from interface:OperationFutureReturns theRetryingFuturewhich continues to pollOperationSnapshot.- Specified by:
getPollingFuturein interfaceOperationFuture<ResponseT,MetadataT>
-
peekMetadata
Description copied from interface:OperationFuturePeeks at the metadata of the operation tracked by thisOperationFuture. If the initial future hasn't completed yet this method returnsnull, otherwise it returns the latest metadata returned from the server (i.e. either initial call metadata or the metadata received from the latest completed poll iteration).If not
null, the returned result is guaranteed to be an already completed future, soFuture.isDone()will always betrueandFuture.get()will always be non-blocking.Note, some APIs may return
nullin metadata response message. In such cases this method may return a non-null future whoseget()method will returnnull. This behavior is API specific an should be considered a valid case, which indicates that the recent poll request has completed, but no specific metadata was provided by the server (i.e. most probably providing metadata for an intermediate result is not supported by the server).This method should be used to check operation progress without blocking current thread. Since this method returns metadata from the latest completed poll, it is potentially slightly stale compared to the most recent data. To get the most recent data and/or get notified when the current scheduled poll request completes use the
OperationFuture.getMetadata()method instead.If this operation future is completed, this method always returns the metadata from the last poll request (which completed the operation future).
If this operation future failed, this method may (depending on the failure type) return a non-failing future, representing the metadata from the last poll request (which failed the operation future).
If this operation future was cancelled, this method returns a canceled metatata future as well.
In general this method behaves similarly to
RetryingFuture.peekAttemptResult().- Specified by:
peekMetadatain interfaceOperationFuture<ResponseT,MetadataT>
-
getMetadata
Description copied from interface:OperationFutureGets the metadata of the operation tracked by thisOperationFuture. This method returns the current poll metadata result (or the initial call metadata if it hasn't completed yet). The returned future completes once the current scheduled poll request (or the initial request if it hasn't completed yet) is executed and response is received from the server. The time when the polling request is executed is determined by the underlying polling algorithm.Adding direct executor (same thread) callbacks to the future returned by this method is strongly not recommended, since the future is resolved under retrying future's internal lock and may affect the operation polling process. Adding separate thread callbacks is ok.
Note, some APIs may return
nullin metadata response message. In such cases this method may return a non-null future whoseget()method will returnnull. This behavior is API specific an should be considered a valid case, which indicates that the recent poll request has completed, but no specific metadata was provided by the server. (i.e. most probably providing metadata for an intermediate result is not supported by the server).In most cases this method returns a future which is not completed yet, so calling
Future.get()is a potentially blocking operation. To get metadata without blocking the current thread use theOperationFuture.peekMetadata()method instead.If this operation future is completed, this method always returns the metadata from the last poll request (which completed the operation future).
If this operation future failed, this method may (depending on the failure type) return a non-failing future, representing the metadata from the last poll request (which failed the operation future).
If this operation future was cancelled, this method returns a canceled metatata future as well.
In general this method behaves similarly to
RetryingFuture.getAttemptResult().- Specified by:
getMetadatain interfaceOperationFuture<ResponseT,MetadataT>
-