org.uacalc.ui.tm
Class BackgroundTask<V>

java.lang.Object
  extended by org.uacalc.ui.tm.BackgroundTask<V>
All Implemented Interfaces:
java.lang.Runnable, java.util.concurrent.Future<V>

public abstract class BackgroundTask<V>
extends java.lang.Object
implements java.lang.Runnable, java.util.concurrent.Future<V>

BackgroundTask

Background task class supporting cancellation, completion notification, and progress notification.

Author:
Brian Goetz and Tim Peierls

Nested Class Summary
static class BackgroundTask.Status
           
 
Field Summary
protected  ProgressReport report
           
protected  BackgroundTask.Status status
           
 
Constructor Summary
BackgroundTask(ProgressReport report)
           
 
Method Summary
 boolean cancel(boolean mayInterruptIfRunning)
           
protected abstract  V compute()
           
 V get()
           
 V get(long timeout, java.util.concurrent.TimeUnit unit)
           
 ProgressReport getProgressReport()
           
 BackgroundTask.Status getStatus()
           
 boolean isCancelled()
           
 boolean isDone()
           
protected  void onCompletion(V result, java.lang.Throwable exception, boolean cancelled, boolean outOfMemory)
           
protected  void onProgress(int current, int max)
           
 void run()
           
protected  void setProgressReport(ProgressReport pr)
           
 void setStatus(BackgroundTask.Status v)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

status

protected volatile BackgroundTask.Status status

report

protected ProgressReport report
Constructor Detail

BackgroundTask

public BackgroundTask(ProgressReport report)
Method Detail

setProgressReport

protected void setProgressReport(ProgressReport pr)

getProgressReport

public ProgressReport getProgressReport()

compute

protected abstract V compute()
                      throws java.lang.Exception
Throws:
java.lang.Exception

onCompletion

protected void onCompletion(V result,
                            java.lang.Throwable exception,
                            boolean cancelled,
                            boolean outOfMemory)

getStatus

public BackgroundTask.Status getStatus()

setStatus

public void setStatus(BackgroundTask.Status v)

onProgress

protected void onProgress(int current,
                          int max)

cancel

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

get

public V get()
      throws java.lang.InterruptedException,
             java.util.concurrent.ExecutionException
Specified by:
get in interface java.util.concurrent.Future<V>
Throws:
java.lang.InterruptedException
java.util.concurrent.ExecutionException

get

public V get(long timeout,
             java.util.concurrent.TimeUnit unit)
      throws java.lang.InterruptedException,
             java.util.concurrent.ExecutionException,
             java.util.concurrent.TimeoutException
Specified by:
get in interface java.util.concurrent.Future<V>
Throws:
java.lang.InterruptedException
java.util.concurrent.ExecutionException
java.util.concurrent.TimeoutException

isCancelled

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

isDone

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

run

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


Copyright 2003 Ralph Freese. All Rights Reserved.