cz.cuni.amis.utils.future
Interface IFutureWithListeners<RESULT>

Package class diagram package IFutureWithListeners
All Superinterfaces:
Future<RESULT>
All Known Implementing Classes:
FutureWithListeners

public interface IFutureWithListeners<RESULT>
extends Future<RESULT>

Author:
Martin Cerny

Method Summary
 void addFutureListener(IFutureListener<RESULT> listener)
          Adds a listener on a future status (using strong reference).
 boolean cancel(boolean mayInterruptIfRunning)
           
 void computationException(Exception e)
          Informs the future that it can't be computed due to the exception.
 RESULT get()
           
 RESULT get(long timeout, TimeUnit unit)
          Returns a result or waits for the computation till timeout.
 Exception getException()
          Contains an exception that has happened during the computation in the case of (FutureWithListeners.getStatus() == EXCEPTION).
 FutureStatus getStatus()
          Current status of the future computation.
 boolean isCancelled()
           
 boolean isDone()
           
 boolean isListening(IFutureListener<RESULT> listener)
          Whether some listener is listening on the future.
 void removeFutureListener(IFutureListener<RESULT> listener)
          Removes a listener from the future.
 void setResult(RESULT result)
          Sets the result of the future computation.
 

Method Detail

addFutureListener

void addFutureListener(IFutureListener<RESULT> listener)
Adds a listener on a future status (using strong reference). Listeners are automatically removed whenever the future gets its result (or is cancelled or an exception happens).

Parameters:
listener -

cancel

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

computationException

void computationException(Exception e)
Informs the future that it can't be computed due to the exception.

Switches the status to EXCEPTION (notifying listeners along the way).

The result can be set only iff NOT FutureWithListeners.isDone(), i.e., status is FutureStatus:FUTURE_IS_BEING_COMPUTED.

Parameters:
e -

get

RESULT get()
Specified by:
get in interface Future<RESULT>

get

RESULT get(long timeout,
           TimeUnit unit)
Returns a result or waits for the computation till timeout.

Does not throw TimeoutException! It returns null instead - always examine status of the future via FutureWithListeners.getStatus() if the null is returned to tell whether the 'null' is the result of the computation (if the status is FUTURE_IS_READY than the 'null' is truly the result).

Specified by:
get in interface Future<RESULT>
Parameters:
timeout -
unit -
Returns:

getException

Exception getException()
Contains an exception that has happened during the computation in the case of (FutureWithListeners.getStatus() == EXCEPTION).

Returns:

getStatus

FutureStatus getStatus()
Current status of the future computation.

Returns:

isCancelled

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

isDone

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

isListening

boolean isListening(IFutureListener<RESULT> listener)
Whether some listener is listening on the future.

Parameters:
listener -
Returns:

removeFutureListener

void removeFutureListener(IFutureListener<RESULT> listener)
Removes a listener from the future.

Parameters:
listener -

setResult

void setResult(RESULT result)
Sets the result of the future computation.

Switches the status to FUTURE_IS_READY (notifying listeners along the way).

The result can be set only iff NOT FutureWithListeners.isDone(), i.e., status is FutureStatus:FUTURE_IS_BEING_COMPUTED.

Parameters:
result -


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