From e952c3971c6aa43549317b9aa41668fb96880a8c Mon Sep 17 00:00:00 2001 From: Jianghao Lu Date: Tue, 2 Aug 2016 00:07:31 -0700 Subject: [PATCH] Make ServiceCall Future-like --- .../java/com/microsoft/rest/ServiceCall.java | 28 ++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) 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..85a4a43db000b 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 object returned. + * @return true if successfully reported; false otherwise. + */ + public boolean success(T 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); + } }