Package com.azure.core.util.polling
Interface SyncPoller<T,U>
- Type Parameters:
T
- The type of poll response value.U
- The type of the final result of long-running operation.
public interface SyncPoller<T,U>
A type that offers API that simplifies the task of executing long-running operations against an Azure service.
It provides the following functionality:
- Querying the current state of the long-running operation.
- Requesting cancellation of long-running operation, if supported by the service.
- Fetching final result of long-running operation, if supported by the service.
- Wait for long-running operation to complete, with optional timeout.
- Wait for long-running operation to reach a specific state.
-
Method Summary
Modifier and TypeMethodDescriptionvoid
cancels the remote long-running operation if cancellation is supported by the service.static <T,
U> SyncPoller<T, U> createPoller
(Duration pollInterval, Function<PollingContext<T>, PollResponse<T>> syncActivationOperation, Function<PollingContext<T>, PollResponse<T>> pollOperation, BiFunction<PollingContext<T>, PollResponse<T>, T> cancelOperation, Function<PollingContext<T>, U> fetchResultOperation) Creates default SyncPoller.static <T,
U> SyncPoller<T, U> createPoller
(Duration pollInterval, Supplier<Response<?>> initialOperation, SyncPollingStrategy<T, U> strategy, TypeReference<T> pollResponseType, TypeReference<U> resultType) Creates PollerFlux.Retrieve the final result of the long-running operation.poll()
Poll once and return the poll response received.default SyncPoller<T,
U> setPollInterval
(Duration pollInterval) Sets the poll interval for this poller.Wait for polling to complete.waitForCompletion
(Duration timeout) Wait for polling to complete with a timeout.waitUntil
(LongRunningOperationStatus statusToWaitFor) Wait for the givenLongRunningOperationStatus
to receive.waitUntil
(Duration timeout, LongRunningOperationStatus statusToWaitFor) Wait for the givenLongRunningOperationStatus
.
-
Method Details
-
poll
PollResponse<T> poll()Poll once and return the poll response received.- Returns:
- the poll response
-
waitForCompletion
PollResponse<T> waitForCompletion()Wait for polling to complete. The polling is considered complete based on status defined inLongRunningOperationStatus
.- Returns:
- the final poll response
-
waitForCompletion
Wait for polling to complete with a timeout. The polling is considered complete based on status defined inLongRunningOperationStatus
.- Parameters:
timeout
- the duration to waits for polling completion.- Returns:
- the final poll response.
-
waitUntil
Wait for the givenLongRunningOperationStatus
to receive.- Parameters:
statusToWaitFor
- the desiredLongRunningOperationStatus
to block for.- Returns:
PollResponse
whosePollResponse.getStatus()
matchesstatusToWaitFor
.- Throws:
IllegalArgumentException
- ifstatusToWaitFor
isnull
.
-
waitUntil
Wait for the givenLongRunningOperationStatus
.- Parameters:
timeout
- the duration to waits for the polling.statusToWaitFor
- the desiredLongRunningOperationStatus
to block for.- Returns:
PollResponse
whosePollResponse.getStatus()
matchesstatusToWaitFor
.- Throws:
IllegalArgumentException
- ifstatusToWaitFor
is ortimeout
null
.
-
getFinalResult
U getFinalResult()Retrieve the final result of the long-running operation.- Returns:
- the final result of the long-running operation if there is one.
-
cancelOperation
void cancelOperation()cancels the remote long-running operation if cancellation is supported by the service. -
setPollInterval
Sets the poll interval for this poller. The new interval will be used for all subsequent polling operations including the polling operations that are already in progress.- Parameters:
pollInterval
- The new poll interval for this poller.- Returns:
- The updated instance of
SyncPoller
. - Throws:
NullPointerException
- if thepollInterval
is null.IllegalArgumentException
- if thepollInterval
is zero or negative.
-
createPoller
static <T,U> SyncPoller<T,U> createPoller(Duration pollInterval, Function<PollingContext<T>, PollResponse<T>> syncActivationOperation, Function<PollingContext<T>, PollResponse<T>> pollOperation, BiFunction<PollingContext<T>, PollResponse<T>, T> cancelOperation, Function<PollingContext<T>, U> fetchResultOperation) Creates default SyncPoller.- Type Parameters:
T
- The type of poll response value.U
- The type of the final result of long-running operation.- Parameters:
pollInterval
- the polling interval.syncActivationOperation
- the operation to synchronously activate (start) the long-running operation, this operation will be called with a newPollingContext
.pollOperation
- the operation to poll the current state of long-running operation, this parameter is required and the operation will be called with currentPollingContext
.cancelOperation
- aFunction
that represents the operation to cancel the long-running operation if service supports cancellation, this parameter is required and if service does not support cancellation then the implementer should throw an exception with an error message indicating absence of cancellation support, the operation will be called with currentPollingContext
.fetchResultOperation
- aFunction
that represents the operation to retrieve final result of the long-running operation if service support it, this parameter is required and operation will be called currentPollingContext
, if service does not have an api to fetch final result and if final result is same as final poll response value then implementer can choose to simply return value from provided final poll response.- Returns:
- new
SyncPoller
instance.
-
createPoller
static <T,U> SyncPoller<T,U> createPoller(Duration pollInterval, Supplier<Response<?>> initialOperation, SyncPollingStrategy<T, U> strategy, TypeReference<T> pollResponseType, TypeReference<U> resultType) Creates PollerFlux.This create method uses a
SyncPollingStrategy
to poll the status of a long-running operation after the activation operation is invoked. SeeSyncPollingStrategy
for more details of known polling strategies and how to create a custom strategy.- Type Parameters:
T
- The type of poll response value.U
- The type of the final result of long-running operation.- Parameters:
pollInterval
- the polling intervalinitialOperation
- the activation operation to activate (start) the long-running operation. This operation will be invoked at most once across all subscriptions. This parameter is required. If there is no specific activation work to be done then invocation should return null, this operation will be called with a newPollingContext
.strategy
- a known syncrhonous strategy for polling a long-running operation in AzurepollResponseType
- theTypeReference
of the response type from a polling call, or BinaryData if raw response body should be kept. This should match the generic parameterSyncPoller
.resultType
- theTypeReference
of the final result object to deserialize into, or BinaryData if raw response body should be kept. This should match the generic parameterSyncPoller
.- Returns:
- new
SyncPoller
instance.
-