Skip to content

Commit 0a23944

Browse files
yaohaizhjianghaolu
authored andcommitted
Add support of LRO for postOrDelete. (#636)
1 parent 6615da9 commit 0a23944

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

.gitignore

+6
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,9 @@ hs_err_pid*
2222
.idea
2323
*.iml
2424
.DS_Store
25+
26+
# Eclipse/VSCode Java files
27+
.settings/
28+
.project
29+
.factorypath
30+
.classpath

azure-client-runtime/src/main/java/com/microsoft/azure/AzureClient.java

+31
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,37 @@ public Observable<ServiceResponseWithHeaders<T, THeader>> call(ServiceResponse<T
507507
});
508508
}
509509

510+
/**
511+
* Handles an initial response from a POST or DELETE operation response by polling
512+
* the status of the operation asynchronously, calling the user provided callback
513+
* when the operation terminates.
514+
*
515+
* @param observable the initial observable from the POST or DELETE operation.
516+
* @param lroOptions long running operation options.
517+
* @param <T> the return type of the caller
518+
* @param <THeader> the type of the response header
519+
* @param resourceType the java.lang.reflect.Type of the resource.
520+
* @param headerType the type of the response header
521+
* @return the task describing the asynchronous polling.
522+
*/
523+
public <T, THeader> Observable<ServiceResponseWithHeaders<T, THeader>> getPostOrDeleteResultWithHeadersAsync(Observable<Response<ResponseBody>> observable, final LongRunningOperationOptions lroOptions, Type resourceType, final Class<THeader> headerType) {
524+
Observable<ServiceResponse<T>> bodyResponse = getPostOrDeleteResultAsync(observable, lroOptions, resourceType);
525+
return bodyResponse
526+
.flatMap(new Func1<ServiceResponse<T>, Observable<ServiceResponseWithHeaders<T, THeader>>>() {
527+
@Override
528+
public Observable<ServiceResponseWithHeaders<T, THeader>> call(ServiceResponse<T> serviceResponse) {
529+
try {
530+
return Observable
531+
.just(new ServiceResponseWithHeaders<>(serviceResponse.body(),
532+
restClient().serializerAdapter().<THeader>deserialize(restClient().serializerAdapter().serialize(serviceResponse.response().headers()), headerType),
533+
serviceResponse.response()));
534+
} catch (IOException e) {
535+
return Observable.error(e);
536+
}
537+
}
538+
});
539+
}
540+
510541
/**
511542
* Given a polling state representing state of a LRO operation, this method returns {@link Single} object,
512543
* when subscribed to it, a single poll will be performed and emits the latest polling state. A poll will be

0 commit comments

Comments
 (0)