cz.cuni.amis.pogamut.base.utils.future
Class ComponentFuture<RESULT>

java.lang.Object
  extended by cz.cuni.amis.utils.future.FutureWithListeners<RESULT>
      extended by cz.cuni.amis.pogamut.base.utils.future.ComponentFuture<RESULT>
Type Parameters:
RESULT -
All Implemented Interfaces:
java.util.concurrent.Future<RESULT>
Direct Known Subclasses:
PathFuture

public class ComponentFuture<RESULT>
extends FutureWithListeners<RESULT>

Future that depends on the running state of the IComponent. This future guarantees that it unblock all threads waiting for the result if the world view (or other component(s) specified via ComponentFuture(IComponentBus, IComponent...)) dies.


Field Summary
 
Fields inherited from class cz.cuni.amis.utils.future.FutureWithListeners
latch, listeners, mutex
 
Constructor Summary
ComponentFuture(IComponentBus bus, IComponent... dependants)
          Constructor where you have to specify components on which the result depends + its component bus.
 
Method Summary
protected  java.util.concurrent.CountDownLatch createLatch()
          Factory method that should return CountDownLatch or its descendant initialized to 1.
 RESULT get()
          Blocks until the future is computed and then returns the result of the computation.
 RESULT get(long timeout, java.util.concurrent.TimeUnit unit)
          Blocks until the future is computed (or timeout) and then returns the result of the computation.
 
Methods inherited from class cz.cuni.amis.utils.future.FutureWithListeners
addFutureListener, cancel, cancelComputation, computationException, getException, getStatus, isCancelled, isDone, isListening, removeFutureListener, setResult, switchStatus
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ComponentFuture

public ComponentFuture(IComponentBus bus,
                       IComponent... dependants)
Constructor where you have to specify components on which the result depends + its component bus. Note that all components must be registered at 'bus'.

Parameters:
bus - may be null - in this case a simple CountDownLatch is created instead of BusAwareCountDownLatch
dependants - may be null or zero-length - in this case a simple CountDownLatch is created instead of BusAwareCountDownLatch
Method Detail

createLatch

protected java.util.concurrent.CountDownLatch createLatch()
Description copied from class: FutureWithListeners
Factory method that should return CountDownLatch or its descendant initialized to 1.

Overrides:
createLatch in class FutureWithListeners<RESULT>
Returns:

get

public RESULT get()
           throws ComponentFutureException
Blocks until the future is computed and then returns the result of the computation.

If the result can't be computed (computation is cancelled, exception happens or some component working on the future result stops), throws an ComponentFutureException.

For additional info, see FutureWithListeners.get().

Specified by:
get in interface java.util.concurrent.Future<RESULT>
Overrides:
get in class FutureWithListeners<RESULT>
Returns:
Throws:
ComponentFutureException

get

public RESULT get(long timeout,
                  java.util.concurrent.TimeUnit unit)
           throws ComponentFutureException
Blocks until the future is computed (or timeout) and then returns the result of the computation. If the result is not computed until timeout, null is returned (check status of the future, whether the 'null' is truly the result of the computation).

If the result can't be computed (computation is cancelled, exception happens or some component working on the future result stops), throws an ComponentFutureException.

For additional info, see FutureWithListeners.get(long, TimeUnit).

Specified by:
get in interface java.util.concurrent.Future<RESULT>
Overrides:
get in class FutureWithListeners<RESULT>
Parameters:
timeout -
unit -
Throws:
ComponentFutureException