İngilizce dilinde oku

Aracılığıyla paylaş


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

Java
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

Java
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();
 }

Classes

AsyncPollResponse<T,U>

AsyncPollResponse represents an event emitted by the PollerFlux<T,U> that asynchronously polls a long-running operation (LRO).

ChainedPollingStrategy<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.

DefaultPollingStrategy<T,U>

The default polling strategy to use with Azure data plane services.

LocationPollingStrategy<T,U>

Implements a Location polling strategy.

LongRunningOperationStatus

An enum to represent all possible states that a long-running operation may find itself in.

OperationResourcePollingStrategy<T,U>

Implements an operation resource polling strategy, typically from Operation-Location.

PollOperationDetails

PollOperationDetails provides details for long running operations.

PollResponse<T>

PollResponse represents a single response from a service for a long-running polling operation.

PollerFlux<T,U>

A Flux that simplifies the task of executing long-running operations against an Azure service.

PollingContext<T>

A key/value store that is propagated between various poll related operations associated with PollerFlux<T,U> and SyncPoller<T,U> poller.

PollingStrategyOptions

Options to configure polling strategy.

StatusCheckPollingStrategy<T,U>

Fallback polling strategy that doesn't poll but exits successfully if no other polling strategies are detected and status code is 2xx.

SyncChainedPollingStrategy<T,U>

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.

SyncDefaultPollingStrategy<T,U>

The default synchronous polling strategy to use with Azure data plane services.

SyncLocationPollingStrategy<T,U>

Implements a synchronous Location polling strategy.

SyncOperationResourcePollingStrategy<T,U>

Implements a synchronous operation resource polling strategy, typically from Operation-Location.

SyncStatusCheckPollingStrategy<T,U>

Fallback polling strategy that doesn't poll but exits successfully if no other polling strategies are detected and status code is 2xx.

Interfaces

PollingStrategy<T,U>

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

SyncPoller<T,U>

A type that offers API that simplifies the task of executing long-running operations against an Azure service.

SyncPollingStrategy<T,U>

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