Class PgxFuture<T>

  • All Implemented Interfaces:
    java.util.concurrent.CompletionStage<T>, java.util.concurrent.Future<T>

    public class PgxFuture<T>
    extends java.util.concurrent.CompletableFuture<T>
    A PGX-specific extension of CompletableFuture
    • Nested Class Summary

      • Nested classes/interfaces inherited from class java.util.concurrent.CompletableFuture

        java.util.concurrent.CompletableFuture.AsynchronousCompletionTask
    • Constructor Summary

      Constructors 
      Constructor Description
      PgxFuture()  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static <T> PgxFuture<java.lang.Void> allOf​(java.util.List<PgxFuture<T>> promises)  
      boolean cancel()  
      PgxFuture<T> cancelOn​(PgxFuture promise)
      If given promise completes exceptionally because it was canceled, CompletableFuture.cancel(boolean) gets called on this promise as well.
      static <T> PgxFuture<T> completedFuture​(T arg)  
      PgxFuture<T> exceptionally​(java.util.function.Function<java.lang.Throwable,​? extends T> fn)  
      static <T> PgxFuture<T> exceptionallyCompletedFuture​(java.lang.Throwable throwable)  
      T get()  
      T get​(long timeout, java.util.concurrent.TimeUnit unit)  
      T getNow​(T valueIfAbsent)  
      FutureProgress getProgress()
      compute statistics about the progress and estimation to finish a PgxFuture Currently only supported for Graph loading features
      <U> PgxFuture<U> handle​(java.util.function.BiFunction<? super T,​java.lang.Throwable,​? extends U> fn)  
      boolean isConsumed()  
      T join()  
      PgxFuture<java.lang.Void> thenAccept​(java.util.function.Consumer<? super T> block)  
      <U> PgxFuture<U> thenApply​(java.util.function.Function<? super T,​? extends U> function)  
      <U> PgxFuture<U> thenApplyAsync​(java.util.function.Function<? super T,​? extends U> function, java.util.concurrent.Executor executor)  
      <U,​V>
      PgxFuture<V>
      thenCombine​(java.util.concurrent.CompletableFuture<? extends U> other, java.util.function.BiFunction<? super T,​? super U,​? extends V> function)  
      PgxFuture<T> thenComplete​(PgxFuture<T> promise)
      completes the given promise whenever this completes.
      PgxFuture<T> thenComplete​(PgxFuture<T> promise, java.lang.Runnable cleanup)
      completes the given promise whenever this completes.
      <U> PgxFuture<U> thenCompose​(java.util.function.Function<? super T,​? extends java.util.concurrent.CompletionStage<U>> function)  
      <U> PgxFuture<U> thenReturn​(U result)
      A future that discards its result and returns the given parameter on completion.
      • Methods inherited from class java.util.concurrent.CompletableFuture

        acceptEither, acceptEitherAsync, acceptEitherAsync, allOf, anyOf, applyToEither, applyToEitherAsync, applyToEitherAsync, cancel, complete, completeAsync, completeAsync, completedStage, completeExceptionally, completeOnTimeout, copy, defaultExecutor, delayedExecutor, delayedExecutor, failedFuture, failedStage, getNumberOfDependents, handleAsync, handleAsync, isCancelled, isCompletedExceptionally, isDone, minimalCompletionStage, newIncompleteFuture, obtrudeException, obtrudeValue, orTimeout, runAfterBoth, runAfterBothAsync, runAfterBothAsync, runAfterEither, runAfterEitherAsync, runAfterEitherAsync, runAsync, runAsync, supplyAsync, supplyAsync, thenAcceptAsync, thenAcceptAsync, thenAcceptBoth, thenAcceptBothAsync, thenAcceptBothAsync, thenApplyAsync, thenCombine, thenCombineAsync, thenCombineAsync, thenComposeAsync, thenComposeAsync, thenRun, thenRunAsync, thenRunAsync, toCompletableFuture, toString, whenComplete, whenCompleteAsync, whenCompleteAsync
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • PgxFuture

        public PgxFuture()
    • Method Detail

      • allOf

        public static <T> PgxFuture<java.lang.Void> allOf​(java.util.List<PgxFuture<T>> promises)
      • completedFuture

        public static <T> PgxFuture<T> completedFuture​(@Nullable
                                                       T arg)
      • exceptionallyCompletedFuture

        public static <T> PgxFuture<T> exceptionallyCompletedFuture​(java.lang.Throwable throwable)
      • thenApply

        public <U> PgxFuture<U> thenApply​(java.util.function.Function<? super T,​? extends U> function)
        Specified by:
        thenApply in interface java.util.concurrent.CompletionStage<T>
        Overrides:
        thenApply in class java.util.concurrent.CompletableFuture<T>
      • thenApplyAsync

        public <U> PgxFuture<U> thenApplyAsync​(java.util.function.Function<? super T,​? extends U> function,
                                               java.util.concurrent.Executor executor)
        Specified by:
        thenApplyAsync in interface java.util.concurrent.CompletionStage<T>
        Overrides:
        thenApplyAsync in class java.util.concurrent.CompletableFuture<T>
      • thenCombine

        public <U,​V> PgxFuture<V> thenCombine​(java.util.concurrent.CompletableFuture<? extends U> other,
                                                    java.util.function.BiFunction<? super T,​? super U,​? extends V> function)
      • thenReturn

        public <U> PgxFuture<U> thenReturn​(U result)
        A future that discards its result and returns the given parameter on completion.

        Shortcut for thenApply(t -> result).

        Parameters:
        result - the result to return on completion of this future
        Returns:
        a future returning the result on completion
      • get

        public T get()
              throws java.lang.InterruptedException,
                     java.util.concurrent.ExecutionException
        Specified by:
        get in interface java.util.concurrent.Future<T>
        Overrides:
        get in class java.util.concurrent.CompletableFuture<T>
        Throws:
        java.lang.InterruptedException
        java.util.concurrent.ExecutionException
      • get

        public T get​(long timeout,
                     java.util.concurrent.TimeUnit unit)
              throws java.lang.InterruptedException,
                     java.util.concurrent.ExecutionException,
                     java.util.concurrent.TimeoutException
        Specified by:
        get in interface java.util.concurrent.Future<T>
        Overrides:
        get in class java.util.concurrent.CompletableFuture<T>
        Throws:
        java.lang.InterruptedException
        java.util.concurrent.ExecutionException
        java.util.concurrent.TimeoutException
      • getNow

        public T getNow​(T valueIfAbsent)
        Overrides:
        getNow in class java.util.concurrent.CompletableFuture<T>
      • join

        public T join()
        Overrides:
        join in class java.util.concurrent.CompletableFuture<T>
      • thenAccept

        public PgxFuture<java.lang.Void> thenAccept​(java.util.function.Consumer<? super T> block)
        Specified by:
        thenAccept in interface java.util.concurrent.CompletionStage<T>
        Overrides:
        thenAccept in class java.util.concurrent.CompletableFuture<T>
      • handle

        public <U> PgxFuture<U> handle​(java.util.function.BiFunction<? super T,​java.lang.Throwable,​? extends U> fn)
        Specified by:
        handle in interface java.util.concurrent.CompletionStage<T>
        Overrides:
        handle in class java.util.concurrent.CompletableFuture<T>
      • thenCompose

        public <U> PgxFuture<U> thenCompose​(java.util.function.Function<? super T,​? extends java.util.concurrent.CompletionStage<U>> function)
        Specified by:
        thenCompose in interface java.util.concurrent.CompletionStage<T>
        Overrides:
        thenCompose in class java.util.concurrent.CompletableFuture<T>
      • exceptionally

        public PgxFuture<T> exceptionally​(java.util.function.Function<java.lang.Throwable,​? extends T> fn)
        Specified by:
        exceptionally in interface java.util.concurrent.CompletionStage<T>
        Overrides:
        exceptionally in class java.util.concurrent.CompletableFuture<T>
      • thenComplete

        public PgxFuture<T> thenComplete​(PgxFuture<T> promise)
        completes the given promise whenever this completes.

        If this completes exceptionally, the given promise is completed exceptionally as well.

        Parameters:
        promise - the promise
        Returns:
        the pgx future
      • thenComplete

        public PgxFuture<T> thenComplete​(PgxFuture<T> promise,
                                         java.lang.Runnable cleanup)
        completes the given promise whenever this completes.

        If this completes exceptionally, the given promise is completed exceptionally as well.

        Parameters:
        promise -
        cleanup - to be run upon completion (can be null)
        Returns:
        the given promise
      • cancel

        public boolean cancel()
      • cancelOn

        public PgxFuture<T> cancelOn​(PgxFuture promise)
        If given promise completes exceptionally because it was canceled, CompletableFuture.cancel(boolean) gets called on this promise as well.
        Parameters:
        promise - If given promise completes exceptionally because it was canceled, CompletableFuture.cancel(boolean) gets called on this promise as well. If given promise completes exceptionally (regardless of the causing exception) and this promise has started or is done, this promise is then rolled back.
        Returns:
        this
      • isConsumed

        public boolean isConsumed()
      • getProgress

        public FutureProgress getProgress()
        compute statistics about the progress and estimation to finish a PgxFuture Currently only supported for Graph loading features
        Parameters:
        future - a pgx future
        Returns:
        progress of the future execution