Class ReadyFutureImpl<R>

java.lang.Object
org.glassfish.grizzly.impl.ReadyFutureImpl<R>
All Implemented Interfaces:
Future<R>, Cacheable, GrizzlyFuture<R>, FutureImpl<R>

public final class ReadyFutureImpl<R> extends Object implements FutureImpl<R>
Future implementation with the specific unmodifiable result.
Author:
Alexey Stashok
See Also:
  • Field Details

    • result

      protected R result
  • Method Details

    • create

      public static <R> ReadyFutureImpl<R> create()
      Construct cancelled Future.
    • create

      public static <R> ReadyFutureImpl<R> create(R result)
      Construct Future with the result.
    • create

      public static <R> ReadyFutureImpl<R> create(Throwable failure)
      Construct failed Future.
    • addCompletionHandler

      public void addCompletionHandler(CompletionHandler<R> completionHandler)
      Adds a CompletionHandler, which will be notified once the asynchronous computation, represented by this Future, is complete.
      Specified by:
      addCompletionHandler in interface GrizzlyFuture<R>
      Parameters:
      completionHandler - CompletionHandler
    • getResult

      public R getResult()
      Get current result value without any blocking.
      Specified by:
      getResult in interface FutureImpl<R>
      Returns:
      current result value without any blocking.
    • setResult

      public void setResult(R result)
      Should not be called for ReadyFutureImpl
    • cancel

      public boolean cancel(boolean mayInterruptIfRunning)
      Do nothing.
      Specified by:
      cancel in interface Future<R>
      Returns:
      cancel state, which was set during construction.
    • isCancelled

      public boolean isCancelled()
      Specified by:
      isCancelled in interface Future<R>
    • isDone

      public boolean isDone()
      Specified by:
      isDone in interface Future<R>
    • get

      Specified by:
      get in interface Future<R>
      Throws:
      InterruptedException
      ExecutionException
    • get

      public R get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException
      Specified by:
      get in interface Future<R>
      Throws:
      InterruptedException
      ExecutionException
      TimeoutException
    • failure

      public void failure(Throwable failure)
      Should not be called for ReadyFutureImpl
      Specified by:
      failure in interface FutureImpl<R>
    • result

      public void result(R result)
      Description copied from interface: FutureImpl
      Set the result value and notify about operation completion.
      Specified by:
      result in interface FutureImpl<R>
      Parameters:
      result - the result value
    • markForRecycle

      public void markForRecycle(boolean recycleResult)
      Description copied from interface: GrizzlyFuture
      Mark GrizzlyFuture as recyclable, so once result will come - GrizzlyFuture object will be recycled and returned to a thread local object pool. You can consider to use this method, if you're not interested in using this GrizzlyFuture object.
      Specified by:
      markForRecycle in interface GrizzlyFuture<R>
      Parameters:
      recycleResult - if true - the GrizzlyFuture result, if it support recyclable mechanism, will be also recycled together with this GrizzlyFuture object.
    • recycle

      public void recycle()
      Specified by:
      recycle in interface Cacheable
    • recycle

      public void recycle(boolean recycleResult)
      Description copied from interface: GrizzlyFuture
      Recycle GrizzlyFuture now. This method could be used, if you're not interested in using this GrizzlyFuture object, and you're sure this object is not used by any other application part.
      Specified by:
      recycle in interface GrizzlyFuture<R>
      Parameters:
      recycleResult - if true - the GrizzlyFuture result, if it support recyclable mechanism, will be also recycled together with this GrizzlyFuture object.