cz.cuni.amis.utils.future
Class RunnableFuture<RESULT>

java.lang.Object
  extended by cz.cuni.amis.utils.future.RunnableFuture<RESULT>
All Implemented Interfaces:
IFuture<RESULT>, java.lang.Runnable, java.util.concurrent.Future<RESULT>

public abstract class RunnableFuture<RESULT>
extends java.lang.Object
implements java.lang.Runnable, IFuture<RESULT>


Constructor Summary
RunnableFuture()
           
 
Method Summary
 boolean cancel(boolean mayInterruptIfRunning)
           
 RESULT get()
          Waits if necessary for the computation to complete, and then retrieves its result.
 RESULT get(long timeout, java.util.concurrent.TimeUnit unit)
          Waits if necessary for at most the given time for the computation to complete, and then retrieves its result, if available.
 boolean isCancelled()
           
 boolean isDone()
           
protected abstract  RESULT process()
          Provide the implementation of your work that returns some RESULT or throws an exception if something happens.
 void run()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RunnableFuture

public RunnableFuture()
Method Detail

process

protected abstract RESULT process()
                           throws java.lang.Exception
Provide the implementation of your work that returns some RESULT or throws an exception if something happens.

Returns:
Throws:
java.lang.Exception

run

public final void run()
Specified by:
run in interface java.lang.Runnable

cancel

public final boolean cancel(boolean mayInterruptIfRunning)
Specified by:
cancel in interface java.util.concurrent.Future<RESULT>

get

public final RESULT get()
Description copied from interface: IFuture
Waits if necessary for the computation to complete, and then retrieves its result.

Specified by:
get in interface IFuture<RESULT>
Specified by:
get in interface java.util.concurrent.Future<RESULT>
Returns:
the computed result

get

public final RESULT get(long timeout,
                        java.util.concurrent.TimeUnit unit)
                 throws PogamutInterruptedException,
                        PogamutTimeoutException
Description copied from interface: IFuture
Waits if necessary for at most the given time for the computation to complete, and then retrieves its result, if available.

Specified by:
get in interface IFuture<RESULT>
Specified by:
get in interface java.util.concurrent.Future<RESULT>
Parameters:
timeout - the maximum time to wait
unit - the time unit of the timeout argument
Returns:
the computed result
Throws:
PogamutInterruptedException - if the current thread was interrupted while waiting
PogamutTimeoutException - if the wait timed out

isCancelled

public final boolean isCancelled()
Specified by:
isCancelled in interface java.util.concurrent.Future<RESULT>

isDone

public final boolean isDone()
Specified by:
isDone in interface java.util.concurrent.Future<RESULT>