forked from Azure/azure-sdk-for-java
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
6c35000 Fix tests for fluent code a1cd0f1 Paging async works 148e463 Generate correct paging code 57cbe08 LRO tests pass bae30e0 Regenerate fluent 0882500 Merge commit '6eb93f97e4e2faab3b8e56090fc697c32dd2f410' into rx 2e44bb0 User observable for paging 0fffe57 Merge 9925f2c into da82c36 b7c1094 Remove unused imports b19b716 LRO now uses Rx 75a68c3 Generate Observable based clients in generic generator 0a7e455 Create VM works 5bb56b9 Fixing the javadoc error and formatting errors for key vault 16c5acd Observable based async works for NSG c039c6e Merge pull request Azure#1015 from anuchandy/resources-create 44a1519 Merge branch 'master' of github.com:Azure/azure-sdk-for-java into resources-create 652d622 Exposing Create and CreateAsync in collection that takes variable number of Creatables git-subtree-dir: runtimes git-subtree-split: 6c35000
- Loading branch information
1 parent
28bc124
commit 65d59d6
Showing
18 changed files
with
569 additions
and
958 deletions.
There are no files selected for viewing
1,015 changes: 320 additions & 695 deletions
1,015
azure-client-runtime/src/main/java/com/microsoft/azure/AzureClient.java
Large diffs are not rendered by default.
Oops, something went wrong.
95 changes: 95 additions & 0 deletions
95
azure-client-runtime/src/main/java/com/microsoft/azure/AzureServiceCall.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
/** | ||
* | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
* | ||
*/ | ||
|
||
package com.microsoft.azure; | ||
|
||
import com.microsoft.rest.ServiceCall; | ||
import com.microsoft.rest.ServiceResponse; | ||
|
||
import rx.Observable; | ||
import rx.Subscriber; | ||
import rx.functions.Func1; | ||
|
||
/** | ||
* An instance of this class provides access to the underlying REST call invocation. | ||
* This class wraps around the Retrofit Call object and allows updates to it in the | ||
* progress of a long running operation or a paging operation. | ||
* | ||
* @param <T> the type of the returning object | ||
*/ | ||
public final class AzureServiceCall<T> extends ServiceCall<T> { | ||
private AzureServiceCall() { | ||
} | ||
|
||
/** | ||
* Creates a ServiceCall from a paging operation. | ||
* | ||
* @param first the observable to the first page | ||
* @param next the observable to poll subsequent pages | ||
* @param callback the client-side callback | ||
* @param <T> the Page type | ||
* @param <V> the element type | ||
* @return the future based ServiceCall | ||
*/ | ||
public static <T extends Page<V>, V> ServiceCall<T> create(Observable<ServiceResponse<T>> first, final Func1<String, Observable<ServiceResponse<T>>> next, final ListOperationCallback<V> callback) { | ||
final AzureServiceCall<T> serviceCall = new AzureServiceCall<>(); | ||
final PagingSubscriber<T, V> subscriber = new PagingSubscriber<>(serviceCall, next, callback); | ||
serviceCall.setSubscription(first | ||
.single() | ||
.subscribe(subscriber)); | ||
return serviceCall; | ||
} | ||
|
||
/** | ||
* The subscriber that handles user callback and automatically subscribes to the next page. | ||
* | ||
* @param <T> the Page type | ||
* @param <V> the element type | ||
*/ | ||
private static class PagingSubscriber<T extends Page<V>, V> extends Subscriber<ServiceResponse<T>> { | ||
private AzureServiceCall<T> serviceCall; | ||
private Func1<String, Observable<ServiceResponse<T>>> next; | ||
private ListOperationCallback<V> callback; | ||
private ServiceResponse<T> lastResponse; | ||
|
||
PagingSubscriber(final AzureServiceCall<T> serviceCall, final Func1<String, Observable<ServiceResponse<T>>> next, final ListOperationCallback<V> callback) { | ||
this.serviceCall = serviceCall; | ||
this.next = next; | ||
this.callback = callback; | ||
} | ||
|
||
@Override | ||
public void onCompleted() { | ||
// do nothing | ||
} | ||
|
||
@Override | ||
public void onError(Throwable e) { | ||
serviceCall.setException(e); | ||
if (callback != null) { | ||
callback.failure(e); | ||
} | ||
} | ||
|
||
@Override | ||
public void onNext(ServiceResponse<T> serviceResponse) { | ||
lastResponse = serviceResponse; | ||
ListOperationCallback.PagingBehavior behavior = ListOperationCallback.PagingBehavior.CONTINUE; | ||
if (callback != null) { | ||
behavior = callback.progress(serviceResponse.getBody().getItems()); | ||
if (behavior == ListOperationCallback.PagingBehavior.STOP || serviceResponse.getBody().getNextPageLink() == null) { | ||
callback.success(); | ||
} | ||
} | ||
if (behavior == ListOperationCallback.PagingBehavior.STOP || serviceResponse.getBody().getNextPageLink() == null) { | ||
serviceCall.set(lastResponse); | ||
} else { | ||
serviceCall.setSubscription(next.call(serviceResponse.getBody().getNextPageLink()).single().subscribe(this)); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.