Class ServiceFuture<T>

  • Type Parameters:
    T - the type of the returning object
    All Implemented Interfaces:
    com.google.common.util.concurrent.ListenableFuture<T>, Future<T>

    public class ServiceFuture<T>
    extends com.google.common.util.concurrent.AbstractFuture<T>
    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.
    • Constructor Detail

      • ServiceFuture

        protected ServiceFuture()
    • Method Detail

      • fromResponse

        public static <T> ServiceFuture<T> fromResponse​(rx.Observable<ServiceResponse<T>> observable)
        Creates a ServiceCall from an observable object.
        Type Parameters:
        T - the type of the response
        Parameters:
        observable - the observable to create from
        Returns:
        the created ServiceCall
      • fromResponse

        public static <T> ServiceFuture<T> fromResponse​(rx.Observable<ServiceResponse<T>> observable,
                                                        ServiceCallback<T> callback)
        Creates a ServiceCall from an observable object and a callback.
        Type Parameters:
        T - the type of the response
        Parameters:
        observable - the observable to create from
        callback - the callback to call when events happen
        Returns:
        the created ServiceCall
      • fromBody

        public static <T> ServiceFuture<T> fromBody​(rx.Observable<T> observable,
                                                    ServiceCallback<T> callback)
        Creates a ServiceFuture from an observable object and a callback.
        Type Parameters:
        T - the type of the response
        Parameters:
        observable - the observable to create from
        callback - the callback to call when events happen
        Returns:
        the created ServiceFuture
      • fromBody

        public static ServiceFuture<Void> fromBody​(rx.Completable completable,
                                                   ServiceCallback<Void> callback)
        Creates a ServiceFuture from an Completable object and a callback.
        Parameters:
        completable - the completable to create from
        callback - the callback to call when event happen
        Returns:
        the created ServiceFuture
      • fromHeaderResponse

        public static <T,​V> ServiceFuture<T> fromHeaderResponse​(rx.Observable<ServiceResponseWithHeaders<T,​V>> observable,
                                                                      ServiceCallback<T> callback)
        Creates a ServiceCall from an observable and a callback for a header response.
        Type Parameters:
        T - the type of the response body
        V - the type of the response header
        Parameters:
        observable - the observable of a REST call that returns JSON in a header
        callback - the callback to call when events happen
        Returns:
        the created ServiceCall
      • getSubscription

        public rx.Subscription getSubscription()
        Returns:
        the current Rx subscription associated with the ServiceCall.
      • setSubscription

        protected void setSubscription​(rx.Subscription subscription)
      • success

        public boolean success​(T result)
        Invoke this method to report completed, allowing AbstractFuture.get() to be unblocked.
        Parameters:
        result - the service response returned.
        Returns:
        true if successfully reported; false otherwise.
      • cancel

        public boolean cancel​(boolean mayInterruptIfRunning)
        Specified by:
        cancel in interface Future<T>
        Overrides:
        cancel in class com.google.common.util.concurrent.AbstractFuture<T>
      • isCancelled

        public boolean isCancelled()
        Specified by:
        isCancelled in interface Future<T>
        Overrides:
        isCancelled in class com.google.common.util.concurrent.AbstractFuture<T>