Package jadex.future

Interface IFuture<E>

All Superinterfaces:
Supplier<E>
All Known Subinterfaces:
IIntermediateFuture<E>, IPullIntermediateFuture<E>, IPullSubscriptionIntermediateFuture<E>, ISubscriptionIntermediateFuture<E>, ITerminableFuture<E>, ITerminableIntermediateFuture<E>, ITuple2Future<E,F>
All Known Implementing Classes:
Future, IntermediateFuture, PullIntermediateDelegationFuture, PullIntermediateFuture, PullSubscriptionIntermediateDelegationFuture, PullSubscriptionIntermediateFuture, SubscriptionIntermediateDelegationFuture, SubscriptionIntermediateFuture, TerminableDelegationFuture, TerminableFuture, TerminableIntermediateDelegationFuture, TerminableIntermediateFuture, Tuple2Future

public interface IFuture<E> extends Supplier<E>
Interface for futures. Similar to Java Future interface but adds a listener notification mechanism.
  • Field Details

    • DONE

      static final IFuture<Void> DONE
      A future representing a completed action. Can be used as direct return value of methods that do not perform asynchronous operations and do not return a result value.
    • TRUE

      static final IFuture<Boolean> TRUE
      A future representing a true result.
    • FALSE

      static final IFuture<Boolean> FALSE
      A future representing a false result.
  • Method Details

    • isDone

      boolean isDone()
      Test if done, i.e. result is available.
      Returns:
      True, if done.
    • getException

      Exception getException()
      Get the exception, if any.
      Returns:
      The exception, if any, or null if the future is not yet done or succeeded without exception.
    • get

      E get()
      Get the result - blocking call.
      Specified by:
      get in interface Supplier<E>
      Returns:
      The future result.
    • get

      E get(boolean realtime)
      Get the result - blocking call.
      Parameters:
      realtime - Flag, if wait should be realtime (in constrast to simulation time).
      Returns:
      The future result.
    • get

      E get(long timeout)
      Get the result - blocking call.
      Parameters:
      timeout - The timeout in millis.
      Returns:
      The future result.
    • get

      E get(long timeout, boolean realtime)
      Get the result - blocking call.
      Parameters:
      timeout - The timeout in millis.
      realtime - Flag, if wait should be realtime (in constrast to simulation time).
      Returns:
      The future result.
    • get

      E get(ThreadSuspendable sus)
      Deprecated.
      - From 3.0. Use the version without suspendable. Will NOT use the suspendable given as parameter. Get the result - blocking call.
      Returns:
      The future result.
    • addResultListener

      void addResultListener(IResultListener<E> listener)
      Add a result listener.
      Parameters:
      listener - The listener.
    • then

      IFuture<? extends E> then(Consumer<? super E> function)
      Applies a function after the result is available, using the result of this Future as input.
      Parameters:
      function - Function that takes the result of this future as input and delivers t.
      Returns:
      Future of the result after the function has been applied.
    • thenApply

      <T> IFuture<T> thenApply(Function<? super E,? extends T> function)
      Applies a function after the result is available, using the result of this Future as input.
      Parameters:
      function - Function that takes the result of this future as input and delivers t.
      Returns:
      Future of the result after the function has been applied.
    • thenApply

      <T> IFuture<T> thenApply(Function<? super E,? extends T> function, Class<?> futuretype)
      Applies a function after the result is available, using the result of this Future as input.
      Parameters:
      function - Function that takes the result of this future as input and delivers t.
      futuretype - The type of the return future.
      Returns:
      Future of the result after the function has been applied.
    • thenCompose

      <T> IFuture<T> thenCompose(Function<? super E,IFuture<T>> function)
      The result of this future is delegated to the given (future-returning) function. The result of the function will be available in the returned future.
      Parameters:
      function - Function that takes the result of this future as input and delivers future(t).
      Returns:
      Future of the result of the second async call.
    • thenCompose

      <T> IFuture<T> thenCompose(Function<? super E,IFuture<T>> function, Class<?> futuretype)
      The result of this future is delegated to the given (future-returning) function. The result of the function will be available in the returned future.
      Parameters:
      function - Function that takes the result of this future as input and delivers future(t).
      futuretype - The type of the return future. If null, a default future is created.
      Returns:
      Future of the result of the second async call.
    • catchEx

      <T> IFuture<E> catchEx(Future<T> delegate)
      Called on exception.
      Parameters:
      delegate - The future the exception will be delegated to.
    • catchEx

      IFuture<E> catchEx(Consumer<? super Exception> consumer)
      Called on exception.
      Parameters:
      consumer - The function called with the exception.
    • catchEx

      IFuture<E> catchEx(Consumer<? super Exception> function, Class<?> consumer)
      Called on exception.
      Parameters:
      consumer - The function called with the exception.
    • printOnEx

      IFuture<E> printOnEx()
      Print an exception.
    • delegate

      void delegate(Future<E> delegate)
      Deprecated.
      Use delegateTo.
      Delegate the result and exception to another future. Short form for adding a delegation listener.
      Parameters:
      delegate - The other future.
    • delegateTo

      void delegateTo(Future<E> target)
      Forward the result and exception to another future. Short form for adding a delegation listener.
      Parameters:
      target - The target future.