# Interface OperationFuture&lt;ResponseT,MetadataT&gt; (2.81.0)

2.81.0 (latest) 2.80.0 2.79.0 2.76.0 2.75.0 2.74.1 2.73.1 2.72.2 2.71.0 2.70.3 2.69.0 2.68.2 2.67.0 2.66.0 2.65.0 2.63.1 2.62.0 2.61.0 2.60.0 2.59.1 2.58.0 2.57.0 2.55.0 2.54.1 2.53.0 2.52.0 2.51.0 2.50.0 2.49.0 2.48.1 2.47.0 2.46.1 2.45.0 2.43.0 2.42.0 2.41.0 2.39.0 2.38.0 2.37.0 2.36.0 2.35.0 2.34.1 2.33.0 2.32.1 2.31.1 2.30.1 2.24.0 2.23.3 2.22.0 2.21.0 2.20.1 2.19.6 2.18.7 2.17.0 2.16.0 2.15.0 2.14.0 2.13.0 2.12.2 2.11.0 2.10.0 2.9.0 2.8.1 2.7.1

    public interface OperationFuture<ResponseT,MetadataT> extends ApiFuture<ResponseT>

An ApiFuture which tracks polling of a service. The polling is done periodically, based on the
[com.google.api.gax.retrying.TimedRetryAlgorithm](https://docs.cloud.google.com/java/docs/reference/gax/latest/com.google.api.gax.retrying.TimedRetryAlgorithm).

Implementations are expected to be thread-safe.

## Implements

com.google.api.core.ApiFuture\<ResponseT\>

| ## Type Parameters ||
|---|---|
| **Name** | **Description** |
| `ResponseT` |   |
| `MetadataT` |   |

## Methods

### getInitialFuture()

    public abstract ApiFuture<OperationSnapshot> getInitialFuture()

Returns the [OperationSnapshot](https://docs.cloud.google.com/java/docs/reference/gax/latest/com.google.api.gax.longrunning.OperationSnapshot) future of the initial request which started this `
OperationFuture`.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/api-common/latest/com.google.api.core.ApiFuture.html<https://docs.cloud.google.com/java/docs/reference/gax/latest/com.google.api.gax.longrunning.OperationSnapshot>` |   |

### getMetadata()

    public abstract ApiFuture<MetadataT> getMetadata()

Gets the metadata of the operation tracked by this [OperationFuture](https://docs.cloud.google.com/java/docs/reference/gax/latest/com.google.api.gax.longrunning.OperationFuture). 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 `null` in metadata response message. In such cases this
method may return a non-null future whose `get()` method will return `null`. 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 ApiFuture#get() is a potentially blocking operation. To get metadata without blocking the
current thread use the [#peekMetadata()](https://docs.cloud.google.com/java/docs/reference/gax/latest/com.google.api.gax.longrunning.OperationFuture#com_google_api_gax_longrunning_OperationFuture_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()](https://docs.cloud.google.com/java/docs/reference/gax/latest/com.google.api.gax.retrying.RetryingFuture#com_google_api_gax_retrying_RetryingFuture_getAttemptResult__).

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/api-common/latest/com.google.api.core.ApiFuture.html<MetadataT>` |   |

### getName()

    public abstract String getName()

Returns 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.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` |   |

| **Exceptions** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/lang/InterruptedException.html` |   |
| `https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/ExecutionException.html` |   |

### getPollingFuture()

    public abstract RetryingFuture<OperationSnapshot> getPollingFuture()

Returns the [RetryingFuture](https://docs.cloud.google.com/java/docs/reference/gax/latest/com.google.api.gax.retrying.RetryingFuture) which continues to poll [OperationSnapshot](https://docs.cloud.google.com/java/docs/reference/gax/latest/com.google.api.gax.longrunning.OperationSnapshot).

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/gax/latest/com.google.api.gax.retrying.RetryingFuture<https://docs.cloud.google.com/java/docs/reference/gax/latest/com.google.api.gax.longrunning.OperationSnapshot>` |   |

### peekMetadata()

    public abstract ApiFuture<MetadataT> peekMetadata()

Peeks at the metadata of the operation tracked by this [OperationFuture](https://docs.cloud.google.com/java/docs/reference/gax/latest/com.google.api.gax.longrunning.OperationFuture). If the initial
future hasn't completed yet this method returns `null`, 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, so
ApiFuture#isDone() will always be `true` and ApiFuture#get() will always
be non-blocking.

Note, some APIs may return `null` in metadata response message. In such cases this
method may return a non-null future whose `get()` method will return `null`. 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 [#getMetadata()](https://docs.cloud.google.com/java/docs/reference/gax/latest/com.google.api.gax.longrunning.OperationFuture#com_google_api_gax_longrunning_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()](https://docs.cloud.google.com/java/docs/reference/gax/latest/com.google.api.gax.retrying.RetryingFuture#com_google_api_gax_retrying_RetryingFuture_peekAttemptResult__).

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/api-common/latest/com.google.api.core.ApiFuture.html<MetadataT>` |   |