Interface SyncPoller<T,U>
- Type Parameters:
T- The type of poll response value.U- The type of the final result of long-running operation.
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 TypeMethodDescriptionvoidCancels 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.default UgetFinalResult(Duration timeout) 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 givenLongRunningOperationStatusto receive.waitUntil(Duration timeout, LongRunningOperationStatus statusToWaitFor) Wait for the givenLongRunningOperationStatuswith a timeout.
-
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.This operation will wait indefinitely until a completed
LongRunningOperationStatusis received.- Returns:
- the final poll response
-
waitForCompletion
Wait for polling to complete with a timeout. The polling is considered complete based on status defined inLongRunningOperationStatusor if the timeout expires.Polling will continue until a completed
LongRunningOperationStatusis received or the timeout expires.The
timeoutis applied in two ways, first it's used during each poll operation to time it out if the polling operation takes too long. Second, it's used to determine when the wait for should stop. If polling doesn't reach a completion state before thetimeoutelapses aRuntimeExceptionwrapping aTimeoutExceptionwill be thrown.- Parameters:
timeout- the duration to wait for polling completion.- Returns:
- the final poll response.
- Throws:
NullPointerException- Iftimeoutis null.IllegalArgumentException- Iftimeoutis zero or negative.RuntimeException- If polling doesn't complete before thetimeoutelapses. (Throwable.getCause()should be aTimeoutException).
-
waitUntil
Wait for the givenLongRunningOperationStatusto receive.This operation will wait indefinitely until the
statusToWaitForis received or aLongRunningOperationStatus.isComplete()state is reached.- Parameters:
statusToWaitFor- the desiredLongRunningOperationStatusto block for.- Returns:
PollResponsewhosePollResponse.getStatus()matchesstatusToWaitForor isLongRunningOperationStatus.isComplete().- Throws:
NullPointerException- ifstatusToWaitForisnull.
-
waitUntil
Wait for the givenLongRunningOperationStatuswith a timeout.Polling will continue until a response is returned with a
LongRunningOperationStatusmatchingstatusToWaitFor, aLongRunningOperationStatus.isComplete()state is reached, or the timeout expires.Unlike
waitForCompletion(Duration)orgetFinalResult(Duration), when the timeout elapses aRuntimeExceptionwrapping aTimeoutExceptionwill not be thrown. Instead, the last poll response will be returned. This is because unlike a completion state, a wait for state may be skipped if the state is reached and completed before a poll operation is executed. For example, if a long-running operation has the flowA -> B -> C -> Dand thestatusToWaitForisBand the first poll request returns stateAbut in the time between polls stateBcompletes, then the next poll request will return stateCand thestatusToWaitForwill never be returned.This may return null if no poll operation completes within the timeout.
- Parameters:
timeout- the duration to wait for the polling.statusToWaitFor- the desiredLongRunningOperationStatusto block for.- Returns:
PollResponsewhosePollResponse.getStatus()matchesstatusToWaitFor, or null if no response was returned within the timeout.- Throws:
NullPointerException- ifstatusToWaitForortimeoutisnull.IllegalArgumentException- iftimeoutis zero or negative.
-
getFinalResult
U getFinalResult()Retrieve the final result of the long-running operation.If polling hasn't completed this will wait indefinitely until polling completes.
- Returns:
- the final result of the long-running operation if there is one.
-
getFinalResult
Retrieve the final result of the long-running operation.If polling hasn't completed this will wait for the
timeoutfor polling to complete. In this case this API is effectively equivalent towaitForCompletion(Duration)+getFinalResult().Polling will continue until a completed
LongRunningOperationStatusis received or the timeout expires.The
timeoutis applied in two ways, first it's used during each poll operation to time it out if the polling operation takes too long. Second, it's used to determine when the wait for should stop. If polling doesn't reach a completion state before thetimeoutelapses aRuntimeExceptionwrapping aTimeoutExceptionwill be thrown.If this method isn't overridden by the implementation then this method is effectively equivalent to calling
waitForCompletion(Duration)thengetFinalResult().- Parameters:
timeout- the duration to wait for polling completion.- Returns:
- the final result of the long-running operation if there is one.
- Throws:
NullPointerException- Iftimeoutis null.IllegalArgumentException- Iftimeoutis zero or negative.RuntimeException- If polling doesn't complete before thetimeoutelapses. (Throwable.getCause()should be aTimeoutException).
-
cancelOperation
void cancelOperation()Cancels the remote long-running operation if cancellation is supported by the service.If cancellation isn't supported by the service this will throw an exception.
- Throws:
RuntimeException- if the operation does not support cancellation.
-
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 thepollIntervalis null.IllegalArgumentException- if thepollIntervalis 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- aFunctionthat 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- aFunctionthat 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
SyncPollerinstance. - Throws:
NullPointerException- ifpollInterval,syncActivationOperation,pollOperation,cancelOperationorfetchResultOperationisnull.IllegalArgumentException- ifpollIntervalis zero or negative.
-
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 method uses a
SyncPollingStrategyto poll the status of a long-running operation after the activation operation is invoked. SeeSyncPollingStrategyfor 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 synchronous strategy for polling a long-running operation in AzurepollResponseType- theTypeReferenceof the response type from a polling call, or BinaryData if raw response body should be kept. This should match the generic parameterSyncPoller.resultType- theTypeReferenceof the final result object to deserialize into, or BinaryData if raw response body should be kept. This should match the generic parameterSyncPoller.- Returns:
- new
SyncPollerinstance. - Throws:
NullPointerException- ifpollInterval,initialOperation,strategy,pollResponseTypeorresultTypeisnull.IllegalArgumentException- ifpollIntervalis zero or negative.
-