Package com.azure.core.util.polling
Class ChainedPollingStrategy<T,U>
java.lang.Object
com.azure.core.util.polling.ChainedPollingStrategy<T,U>
- Type Parameters:
T
- the type of the response type from a polling call, or BinaryData if raw response body should be keptU
- the type of the final result object to deserialize into, or BinaryData if raw response body should be kept
- All Implemented Interfaces:
PollingStrategy<T,
U>
A polling strategy that chains multiple polling strategies, finds the first strategy that can poll the current
long-running operation, and polls with that strategy.
-
Constructor Summary
ConstructorDescriptionChainedPollingStrategy
(List<PollingStrategy<T, U>> strategies) Creates a chained polling strategy with a list of polling strategies. -
Method Summary
Modifier and TypeMethodDescriptioncancel
(PollingContext<T> pollingContext, PollResponse<T> initialResponse) Cancels the long-running operation if service supports cancellation.Checks if this strategy is able to handle polling for this long-running operation based on the information in the initial response.getResult
(PollingContext<T> context, TypeReference<U> resultType) Parses the response from the final GET call into the result type of the long-running operation.onInitialResponse
(Response<?> response, PollingContext<T> pollingContext, TypeReference<T> pollResponseType) Parses the initial response into aLongRunningOperationStatus
, and stores information useful for polling in thePollingContext
.poll
(PollingContext<T> context, TypeReference<T> pollResponseType) Parses the response from the polling URL into aPollResponse
, and stores information useful for further polling and final response in thePollingContext
.
-
Constructor Details
-
ChainedPollingStrategy
Creates a chained polling strategy with a list of polling strategies.- Parameters:
strategies
- the list of polling strategies- Throws:
NullPointerException
- Ifstrategies
is null.IllegalArgumentException
- Ifstrategies
is an empty list.
-
-
Method Details
-
canPoll
Description copied from interface:PollingStrategy
Checks if this strategy is able to handle polling for this long-running operation based on the information in the initial response.- Specified by:
canPoll
in interfacePollingStrategy<T,
U> - 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
-
getResult
Parses the response from the final GET call into the result type of the long-running operation.- Specified by:
getResult
in interfacePollingStrategy<T,
U> - Parameters:
context
- thePollingContext
for the current polling operationresultType
- theTypeReference
of the final result object to deserialize into, or BinaryData if raw response body should be kept.- Returns:
- a publisher emitting the final result
- Throws:
NullPointerException
- ifcanPoll(Response)
is not called prior to this, or if it returns false.
-
onInitialResponse
public Mono<PollResponse<T>> onInitialResponse(Response<?> response, PollingContext<T> pollingContext, TypeReference<T> pollResponseType) Parses the initial response into aLongRunningOperationStatus
, and stores information useful for polling in thePollingContext
. If the result is anything other thanLongRunningOperationStatus.IN_PROGRESS
, the long-running operation will be terminated and none of the other methods will be invoked.- Specified by:
onInitialResponse
in interfacePollingStrategy<T,
U> - Parameters:
response
- the response from the initial method call to activate the long-running operationpollingContext
- thePollingContext
for the current polling operationpollResponseType
- theTypeReference
of the response type from a polling call, or BinaryData if raw response body should be kept. This should match the generic parameterPollingStrategy
.- Returns:
- a publisher emitting the poll response containing the status and the response content
- Throws:
NullPointerException
- ifcanPoll(Response)
is not called prior to this, or if it returns false.
-
poll
Parses the response from the polling URL into aPollResponse
, and stores information useful for further polling and final response in thePollingContext
. The result must have theLongRunningOperationStatus
specified, and the entire polling response content as aBinaryData
.- Specified by:
poll
in interfacePollingStrategy<T,
U> - Parameters:
context
- thePollingContext
for the current polling operationpollResponseType
- theTypeReference
of the response type from a polling call, or BinaryData if raw response body should be kept. This should match the generic parameterPollingStrategy
.- Returns:
- a publisher emitting the poll response containing the status and the response content
- Throws:
NullPointerException
- ifcanPoll(Response)
is not called prior to this, or if it returns false.
-
cancel
Cancels the long-running operation if service supports cancellation. If service does not support cancellation then the implementer should return Mono.error with an error message indicating absence of cancellation. Implementing this method is optional - by default, cancellation will not be supported unless overridden.- Specified by:
cancel
in interfacePollingStrategy<T,
U> - Parameters:
pollingContext
- thePollingContext
for the current polling operation, or null if the polling has started in aSyncPoller
initialResponse
- the response from the initial operation- Returns:
- a publisher emitting the cancellation response content
- Throws:
NullPointerException
- ifcanPoll(Response)
is not called prior to this, or if it returns false.
-