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

Package class diagram package ComponentFuture
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:
cz.cuni.amis.utils.future.IFutureWithListeners<RESULT>, Future<RESULT>
Direct Known Subclasses:
PathFuture

public class ComponentFuture<RESULT>
extends cz.cuni.amis.utils.future.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.

Author:
Jimmy

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  CountDownLatch createLatch()
           
 RESULT get()
          Blocks until the future is computed and then returns the result of the computation.
 RESULT get(long timeout, 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 CountDownLatch createLatch()
Overrides:
createLatch in class cz.cuni.amis.utils.future.FutureWithListeners<RESULT>

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 cz.cuni.amis.utils.future.IFutureWithListeners<RESULT>
Specified by:
get in interface Future<RESULT>
Overrides:
get in class cz.cuni.amis.utils.future.FutureWithListeners<RESULT>
Returns:
Throws:
ComponentFutureException

get

public RESULT get(long timeout,
                  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 cz.cuni.amis.utils.future.IFutureWithListeners<RESULT>
Specified by:
get in interface Future<RESULT>
Overrides:
get in class cz.cuni.amis.utils.future.FutureWithListeners<RESULT>
Parameters:
timeout -
unit -
Throws:
ComponentFutureException


Copyright © 2014 AMIS research group, Faculty of Mathematics and Physics, Charles University in Prague, Czech Republic. All Rights Reserved.