edu.wisc.ssec.mcidasv.util
Class BackgroundTask<V>

java.lang.Object
  extended by edu.wisc.ssec.mcidasv.util.BackgroundTask<V>
All Implemented Interfaces:
Runnable, Future<V>
Direct Known Subclasses:
Submitter

public abstract class BackgroundTask<V>
extends Object
implements Runnable, Future<V>

Background task class supporting cancellation, completion notification, and progress notification. Courtesy of Java Concurrency in Practice, written by Brian Goetz and Tim Peierls.


Nested Class Summary
private  class BackgroundTask.Computation
           
 
Field Summary
private  FutureTask<V> computation
           
 
Constructor Summary
BackgroundTask()
           
 
Method Summary
 boolean cancel(boolean mayInterruptIfRunning)
           
protected abstract  V compute()
           
 V get()
           
 V get(long timeout, TimeUnit unit)
           
 boolean isCancelled()
           
 boolean isDone()
           
protected  void onCompletion(V result, Throwable exception, boolean cancelled)
           
protected  void onProgress(int current, int max)
           
 void run()
           
protected  void setProgress(int current, int max)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

computation

private final FutureTask<V> computation
Constructor Detail

BackgroundTask

public BackgroundTask()
Method Detail

setProgress

protected void setProgress(int current,
                           int max)

compute

protected abstract V compute()
                      throws Exception
Throws:
Exception

onCompletion

protected void onCompletion(V result,
                            Throwable exception,
                            boolean cancelled)

onProgress

protected void onProgress(int current,
                          int max)

cancel

public boolean cancel(boolean mayInterruptIfRunning)
Specified by:
cancel 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

isCancelled

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

isDone

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

run

public void run()
Specified by:
run in interface Runnable