你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

SyncPollingStrategy<T,U> Interface

Type Parameters

T

the TypeReference of the response type from a polling call, or BinaryData if raw response body should be kept

U

the TypeReference of the final result object to deserialize into, or BinaryData if raw response body should be kept

public interface SyncPollingStrategy<T,U>

Represents a known strategy for polling a long-running operation in Azure.

The methods in the polling strategy will be invoked from the SyncPoller<T,U>. The order of the invocations is:

  1. canPoll(Response<?> initialResponse) - exits if returns false
  2. onInitialResponse(Response<?> response, PollingContext<T> pollingContext, TypeReference<T> pollResponseType) - immediately after canPoll(Response<?> initialResponse) returns true
  3. poll(PollingContext<T> pollingContext, TypeReference<T> pollResponseType) - invoked after each polling interval, if the last polling response indicates an "In Progress" status. Returns a PollResponse<T> with the latest status
  4. getResult(PollingContext<T> pollingContext, TypeReference<U> resultType) - invoked when the last polling response indicates a "Successfully Completed" status. Returns the final result of the given type

If the user decides to cancel the PollingContext<T> or SyncPoller<T,U>, the cancel(PollingContext<T> pollingContext, PollResponse<T> initialResponse) method will be invoked. If the strategy doesn't support cancellation, an error will be returned.

Users are not expected to provide their own implementation of this interface. Built-in polling strategies in this library and other client libraries are often sufficient for handling polling in most long-running operations in Azure. When there are special scenarios, built-in polling strategies can be inherited and select methods can be overridden to accomplish the polling requirements, without writing an entire polling strategy from scratch.

Method Summary

Modifier and Type Method and Description
abstract boolean canPoll(Response<?> initialResponse)

Checks if this strategy is able to handle polling for this long-running operation based on the information in the initial response.

default T cancel(PollingContext<T> pollingContext, PollResponse<T> initialResponse)

Cancels the long-running operation if service supports cancellation.

abstract U getResult(PollingContext<T> pollingContext, TypeReference<U> resultType)

Parses the response from the final GET call into the result type of the long-running operation.

abstract PollResponse<T> onInitialResponse(Response<?> response, PollingContext<T> pollingContext, TypeReference<T> pollResponseType)

Parses the initial response into a LongRunningOperationStatus, and stores information useful for polling in the PollingContext<T>.

abstract PollResponse<T> poll(PollingContext<T> pollingContext, TypeReference<T> pollResponseType)

Parses the response from the polling URL into a PollResponse<T>, and stores information useful for further polling and final response in the PollingContext<T>.

Method Details

canPoll

public abstract boolean canPoll(Response initialResponse)

Checks if this strategy is able to handle polling for this long-running operation based on the information in the initial response.

Parameters:

initialResponse - the response from the initial method call to activate the long-running operation

Returns:

true if this polling strategy can handle the initial response, false if not

cancel

public default T cancel(PollingContext pollingContext, PollResponse initialResponse)

Cancels the long-running operation if service supports cancellation. If service does not support cancellation then the implementer should throw an IllegalStateException with an error message indicating absence of cancellation.

Implementing this method is optional - by default, cancellation will not be supported unless overridden.

Parameters:

pollingContext - the PollingContext<T> for the current polling operation, or null if the polling has started in a SyncPoller<T,U>
initialResponse - the response from the initial operation

Returns:

the cancellation response content

getResult

public abstract U getResult(PollingContext pollingContext, TypeReference resultType)

Parses the response from the final GET call into the result type of the long-running operation.

Parameters:

pollingContext - the PollingContext<T> for the current polling operation
resultType - the TypeReference<T> of the final result object to deserialize into, or BinaryData if raw response body should be kept.

Returns:

the final result

onInitialResponse

public abstract PollResponse onInitialResponse(Response response, PollingContext pollingContext, TypeReference pollResponseType)

Parses the initial response into a LongRunningOperationStatus, and stores information useful for polling in the PollingContext<T>. If the result is anything other than IN_PROGRESS, the long-running operation will be terminated and none of the other methods will be invoked.

Parameters:

response - the response from the initial method call to activate the long-running operation
pollingContext - the PollingContext<T> for the current polling operation
pollResponseType - the TypeReference<T> of the response type from a polling call, or BinaryData if raw response body should be kept. This should match the generic parameter U.

Returns:

the poll response containing the status and the response content

poll

public abstract PollResponse poll(PollingContext pollingContext, TypeReference pollResponseType)

Parses the response from the polling URL into a PollResponse<T>, and stores information useful for further polling and final response in the PollingContext<T>. The result must have the LongRunningOperationStatus specified, and the entire polling response content as a BinaryData.

Parameters:

pollingContext - the PollingContext<T> for the current polling operation
pollResponseType - the TypeReference<T> of the response type from a polling call, or BinaryData if raw response body should be kept. This should match the generic parameter U.

Returns:

the poll response containing the status and the response content

Applies to