org.omnaest.utils.structure.element
Class FutureSimple<V>

java.lang.Object
  extended by org.omnaest.utils.structure.element.FutureSimple<V>
Type Parameters:
V -
All Implemented Interfaces:
Future<V>

public class FutureSimple<V>
extends Object
implements Future<V>

Simple Future implementation using a CountDownLatch which unlocks when the value is set.

Author:
Omnaest

Constructor Summary
FutureSimple()
           
 
Method Summary
 boolean cancel(boolean mayInterruptIfRunning)
           
 V get()
           
 V get(long timeout, TimeUnit unit)
           
 boolean getShouldCancel()
          Returns true if the Future.cancel(boolean) method has been called at least once
 boolean isCancelled()
           
 boolean isDone()
           
 void setIsCancelled(boolean isCancelled)
          Sets the value for the Future.isCancelled()
 void setValue(V value)
          Sets the value to be returned by Future.get().
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FutureSimple

public FutureSimple()
See Also:
Future, FutureSimple
Method Detail

cancel

public boolean cancel(boolean mayInterruptIfRunning)
Specified by:
cancel in interface Future<V>

isCancelled

public boolean isCancelled()
Specified by:
isCancelled in interface Future<V>

isDone

public boolean isDone()
Specified by:
isDone in interface Future<V>

get

public V get()
      throws InterruptedException,
             ExecutionException
Specified by:
get in interface Future<V>
Throws:
InterruptedException
ExecutionException

get

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

setValue

public void setValue(V value)
Sets the value to be returned by Future.get(). After setting any value the Future.isDone() will return true.

Parameters:
value -

getShouldCancel

public boolean getShouldCancel()
Returns true if the Future.cancel(boolean) method has been called at least once

Returns:

setIsCancelled

public void setIsCancelled(boolean isCancelled)
Sets the value for the Future.isCancelled()

Parameters:
isCancelled -


Copyright © 2013. All Rights Reserved.