com.azure.core.util.polling
This package contains utility classes and interfaces for handling long-running operations in the Azure client libraries.
Long-running operations are operations such as the creation or deletion of a resource, which take a significant amount of time to complete. These operations are typically handled asynchronously, with the client initiating the operation and then polling the service at intervals to determine whether the operation has completed.
This package provides a standard mechanism for initiating, tracking, and retrieving the results of long-running operations
Code Sample: Asynchronously wait for polling to complete and then retrieve the final result
LocalDateTime timeToReturnFinalResponse = LocalDateTime.now().plus(Duration.ofMinutes(5));
// Create poller instance
PollerFlux<String, String> poller = new PollerFlux<>(Duration.ofMillis(100),
(context) -> Mono.empty(),
(context) -> {
if (LocalDateTime.now().isBefore(timeToReturnFinalResponse)) {
System.out.println("Returning intermediate response.");
return Mono.just(new PollResponse<>(LongRunningOperationStatus.IN_PROGRESS,
"Operation in progress."));
} else {
System.out.println("Returning final response.");
return Mono.just(new PollResponse<>(LongRunningOperationStatus.SUCCESSFULLY_COMPLETED,
"Operation completed."));
}
},
(activationResponse, context) -> Mono.just("FromServer:OperationIsCancelled"),
(context) -> Mono.just("FromServer:FinalOutput"));
poller.take(Duration.ofMinutes(30))
.last()
.flatMap(asyncPollResponse -> {
if (asyncPollResponse.getStatus() == LongRunningOperationStatus.SUCCESSFULLY_COMPLETED) {
// operation completed successfully, retrieving final result.
return asyncPollResponse
.getFinalResult();
} else {
return Mono.error(new RuntimeException("polling completed unsuccessfully with status:"
+ asyncPollResponse.getStatus()));
}
}).block();
Code Sample: Using a SimpleSyncPoller to poll until the operation is successfully completed
LongRunningOperationStatus operationStatus = syncPoller.poll().getStatus();
while (operationStatus != LongRunningOperationStatus.SUCCESSFULLY_COMPLETED) {
System.out.println("Polling status: " + operationStatus.toString());
System.out.println("Polling response: " + operationStatus.toString());
operationStatus = syncPoller.poll().getStatus();
}
Async |
Async |
Chained |
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. |
Default |
The default polling strategy to use with Azure data plane services. |
Location |
Implements a Location polling strategy. |
Long |
An enum to represent all possible states that a long-running operation may find itself in. |
Operation |
Implements an operation resource polling strategy, typically from Operation-Location. |
Poll |
Poll |
Poll |
Poll |
Poller |
A Flux that simplifies the task of executing long-running operations against an Azure service. |
Polling |
A key/value store that is propagated between various poll related operations associated with PollerFlux<T,U> and SyncPoller<T,U> poller. |
Polling |
Options to configure polling strategy. |
Status |
Fallback polling strategy that doesn't poll but exits successfully if no other polling strategies are detected and status code is 2xx. |
Sync |
A synchronous polling strategy that chains multiple synchronous polling strategies, finds the first strategy that can poll the current long-running operation, and polls with that strategy. |
Sync |
The default synchronous polling strategy to use with Azure data plane services. |
Sync |
Implements a synchronous Location polling strategy. |
Sync |
Implements a synchronous operation resource polling strategy, typically from Operation-Location. |
Sync |
Fallback polling strategy that doesn't poll but exits successfully if no other polling strategies are detected and status code is 2xx. |
Polling |
Represents a known strategy for polling a long-running operation in Azure. |
Sync |
A type that offers API that simplifies the task of executing long-running operations against an Azure service. |
Sync |
Represents a known strategy for polling a long-running operation in Azure. |
Azure SDK for Java geri bildirimi
Azure SDK for Java, açık kaynak bir projedir. Geri bildirim sağlamak için bir bağlantı seçin: