diff --git a/azure-client-runtime/src/main/java/com/microsoft/azure/AzureServiceCall.java b/azure-client-runtime/src/main/java/com/microsoft/azure/AzureServiceCall.java index e9c8728b67..c55c189cee 100644 --- a/azure-client-runtime/src/main/java/com/microsoft/azure/AzureServiceCall.java +++ b/azure-client-runtime/src/main/java/com/microsoft/azure/AzureServiceCall.java @@ -10,13 +10,12 @@ import com.microsoft.rest.ServiceCall; import com.microsoft.rest.ServiceResponse; import com.microsoft.rest.ServiceResponseWithHeaders; - -import java.util.List; - import rx.Observable; import rx.Subscriber; import rx.functions.Func1; +import java.util.List; + /** * 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 diff --git a/azure-client-runtime/src/main/java/com/microsoft/azure/TaskGroupBase.java b/azure-client-runtime/src/main/java/com/microsoft/azure/TaskGroupBase.java index 747f0273fa..6de2a3ab46 100644 --- a/azure-client-runtime/src/main/java/com/microsoft/azure/TaskGroupBase.java +++ b/azure-client-runtime/src/main/java/com/microsoft/azure/TaskGroupBase.java @@ -64,18 +64,31 @@ public Observable executeAsync() { final List> observables = new ArrayList<>(); while (nextNode != null) { final DAGNode thisNode = nextNode; - observables.add(nextNode.data().executeAsync() - .flatMap(new Func1>() { - @Override - public Observable call(T t) { - dag().reportedCompleted(thisNode); - if (dag().isRootNode(thisNode)) { - return Observable.just(t); - } else { + T cachedResult = nextNode.data().result(); + if (cachedResult != null && !this.dag().isRootNode(nextNode)) { + observables.add(Observable.just(cachedResult) + .flatMap(new Func1>() { + @Override + public Observable call(T t) { + dag().reportedCompleted(thisNode); return executeAsync(); } - } - })); + }) + ); + } else { + observables.add(nextNode.data().executeAsync() + .flatMap(new Func1>() { + @Override + public Observable call(T t) { + dag().reportedCompleted(thisNode); + if (dag().isRootNode(thisNode)) { + return Observable.just(t); + } else { + return executeAsync(); + } + } + })); + } nextNode = dag.getNext(); } return Observable.merge(observables); diff --git a/client-runtime/src/main/java/com/microsoft/rest/ServiceCall.java b/client-runtime/src/main/java/com/microsoft/rest/ServiceCall.java index 949ef7b887..960a016b88 100644 --- a/client-runtime/src/main/java/com/microsoft/rest/ServiceCall.java +++ b/client-runtime/src/main/java/com/microsoft/rest/ServiceCall.java @@ -8,7 +8,6 @@ package com.microsoft.rest; import com.google.common.util.concurrent.AbstractFuture; - import rx.Observable; import rx.Subscription; import rx.functions.Action1; @@ -130,6 +129,17 @@ protected void setSubscription(Subscription subscription) { this.subscription = subscription; } + /** + * Invoke this method to report completed, allowing + * {@link AbstractFuture#get()} to be unblocked. + * + * @param result the service response returned. + * @return true if successfully reported; false otherwise. + */ + public boolean success(T result) { + return set(result); + } + @Override public boolean cancel(boolean mayInterruptIfRunning) { subscription.unsubscribe();