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 dcffd781c7c59..94b1abfb9bb63 100644 --- a/client-runtime/src/main/java/com/microsoft/rest/ServiceCall.java +++ b/client-runtime/src/main/java/com/microsoft/rest/ServiceCall.java @@ -7,14 +7,18 @@ package com.microsoft.rest; +import com.google.common.util.concurrent.AbstractFuture; + import retrofit2.Call; /** * 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 the type of the returning object */ -public class ServiceCall { +public class ServiceCall extends AbstractFuture> { /** * The Retrofit method invocation. */ @@ -62,4 +66,26 @@ public void cancel() { public boolean isCanceled() { return call.isCanceled(); } + + /** + * 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(ServiceResponse result) { + return set(result); + } + + /** + * Invoke this method to report a failure, allowing + * {@link AbstractFuture#get()} to throw the exception. + * + * @param t the exception thrown. + * @return true if successfully reported; false otherwise. + */ + public boolean failure(Throwable t) { + return setException(t); + } }