|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectroboguice.util.SafeAsyncTask<ResultT>
ResultT
- public abstract class SafeAsyncTask<ResultT>
A class similar but unrelated to android's AsyncTask
.
Unlike AsyncTask, this class properly propagates exceptions.
If you're familiar with AsyncTask and are looking for AsyncTask.doInBackground(Object[])
,
we've named it Callable.call()
here to conform with java 1.5's Callable
interface.
Current limitations: does not yet handle progress, although it shouldn't be
hard to add.
If using your own executor, you must call future() to get a runnable you can execute.
Nested Class Summary | |
---|---|
static class |
SafeAsyncTask.Task<ResultT>
|
Field Summary | |
---|---|
protected static Executor |
DEFAULT_EXECUTOR
|
static int |
DEFAULT_POOL_SIZE
|
protected Executor |
executor
|
protected FutureTask<Void> |
future
|
protected android.os.Handler |
handler
|
protected StackTraceElement[] |
launchLocation
|
Constructor Summary | |
---|---|
SafeAsyncTask()
Sets executor to Executors.newFixedThreadPool(DEFAULT_POOL_SIZE) and Handler to new Handler() |
|
SafeAsyncTask(Executor executor)
Sets Handler to new Handler() |
|
SafeAsyncTask(android.os.Handler handler)
Sets executor to Executors.newFixedThreadPool(DEFAULT_POOL_SIZE) |
|
SafeAsyncTask(android.os.Handler handler,
Executor executor)
|
Method Summary | |
---|---|
boolean |
cancel(boolean mayInterruptIfRunning)
|
void |
execute()
|
protected void |
execute(StackTraceElement[] launchLocation)
|
Executor |
executor()
|
SafeAsyncTask<ResultT> |
executor(Executor executor)
|
FutureTask<Void> |
future()
|
android.os.Handler |
handler()
|
SafeAsyncTask<ResultT> |
handler(android.os.Handler handler)
|
protected SafeAsyncTask.Task<ResultT> |
newTask()
|
protected void |
onException(Exception e)
Logs the exception as an Error by default, but this method may be overridden by subclasses. |
protected void |
onFinally()
|
protected void |
onInterrupted(Exception e)
Called when the thread has been interrupted, likely because the task was canceled. |
protected void |
onPreExecute()
|
protected void |
onSuccess(ResultT t)
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface java.util.concurrent.Callable |
---|
call |
Field Detail |
---|
public static final int DEFAULT_POOL_SIZE
protected static final Executor DEFAULT_EXECUTOR
protected android.os.Handler handler
protected Executor executor
protected StackTraceElement[] launchLocation
protected FutureTask<Void> future
Constructor Detail |
---|
public SafeAsyncTask()
public SafeAsyncTask(android.os.Handler handler)
public SafeAsyncTask(Executor executor)
public SafeAsyncTask(android.os.Handler handler, Executor executor)
Method Detail |
---|
public FutureTask<Void> future()
public SafeAsyncTask<ResultT> executor(Executor executor)
public Executor executor()
public SafeAsyncTask<ResultT> handler(android.os.Handler handler)
public android.os.Handler handler()
public void execute()
protected void execute(StackTraceElement[] launchLocation)
public boolean cancel(boolean mayInterruptIfRunning)
protected void onPreExecute() throws Exception
Exception,
- captured on passed to onException() if present.
Exception
protected void onSuccess(ResultT t) throws Exception
t
- the result of Callable.call()
Exception,
- captured on passed to onException() if present.
Exception
protected void onInterrupted(Exception e)
onException(Exception)
, but this method
may be overridden to handle interruptions differently than other
exceptions.
e
- an InterruptedException or InterruptedIOExceptionprotected void onException(Exception e) throws RuntimeException
e
- the exception thrown from onPreExecute()
, Callable.call()
, or onSuccess(Object)
RuntimeException,
- ignored
RuntimeException
protected void onFinally() throws RuntimeException
RuntimeException,
- ignored
RuntimeException
protected SafeAsyncTask.Task<ResultT> newTask()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |