edu.emory.mathcs.util.concurrent
Class SecureAsyncTask
java.lang.Object
edu.emory.mathcs.util.concurrent.AsyncTask
edu.emory.mathcs.util.concurrent.SecureAsyncTask
- All Implemented Interfaces:
- Future
- public class SecureAsyncTask
- extends AsyncTask
Variant of AsyncTask
that overrides method
createPerformer
so that
it always runs with a fixed access control context and
thread context
inherited from the caller of
createPerformer method. This class is intended primarily for subclassing.
Typical usage scenario in subclasses is to create a new instance and
call createPerformer
. As a result, one obtains a runnable that
will perform assigned task with the same access permissions,
DelegatableThreadLocal
s, and the context class loader, regardless
of the thread that actually executes the runnable.
- Version:
- 1.0
- Author:
- Dawid Kurzyniec
Method Summary |
protected java.lang.Runnable |
createPerformer(Callable call,
boolean disableStackTraces)
Creates a runnable that will execute specified call and then mark this
AsyncTask with the result of that call. |
static AsyncTask |
start(Executor executor,
Callable call)
Schedules specified task with given executor, and returns
completion handle that can be used to access the result or to cancel
the task. |
static AsyncTask |
start(Executor executor,
Callable call,
Callback cb)
Schedules specified task with given executor, and returns
completion handle that can be used to access the result or to cancel
the task. |
static AsyncTask |
start(Executor executor,
Callable call,
Callback cb,
boolean disableStackTraces)
Schedules specified task with given executor, and returns
completion handle that can be used to access the result or to cancel
the task. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
SecureAsyncTask
protected SecureAsyncTask()
SecureAsyncTask
protected SecureAsyncTask(Callback cb)
createPerformer
protected java.lang.Runnable createPerformer(Callable call,
boolean disableStackTraces)
- Creates a runnable that will execute specified call and then mark this
AsyncTask with the result of that call. The runnable will run
with access control context and
ThreadContext
inherited from
this method's invoker, regardless of the thread that will actually
execute it.
If the call completes successfully, this AsyncTask is marked
completed with the result returned by the call. If the call
throws an exception, the AsyncTask is marked as failed with
cause being that exception. The stack trace of the thread in which
the performer is created is appended to the failure cause stack
trace unless the disableStackTraces parameter is set to false.
This method is intended to be used by subclasses. Runnable
returned from this method should be executed only once -- subsequent
execution attempts will fail due to "task already completed" condition.
- Overrides:
createPerformer
in class AsyncTask
- Parameters:
call
- the call to executedisableStackTraces
- if true, does not append invoker stack trace
to traces of exceptions thrown during execution of the runnable
- Returns:
- runnable that will execute specified call and
set the result of this AsyncTask upon completion
start
public static AsyncTask start(Executor executor,
Callable call)
- Schedules specified task with given executor, and returns
completion handle that can be used to access the result or to cancel
the task. The task will run
with access control context and
ThreadContext
inherited from
this method's invoker, regardless of the thread that will actually
execute it.
Later, if task completes successfully, the handle is marked
completed with the result that has been returned from the task.
If the task ends with an exception, the handle is marked
failed with cause being that exception. In such case, as a debugging
aid, current stack trace (that is, that of this method's invoker) is
appended to the original stack trace.
- Parameters:
executor
- the executor to usecall
- the task to schedule
- Returns:
- completion handle that can be used to access the result or
cancel the task
start
public static AsyncTask start(Executor executor,
Callable call,
Callback cb)
- Schedules specified task with given executor, and returns
completion handle that can be used to access the result or to cancel
the task. The task will run
with access control context and
ThreadContext
inherited from
this method's invoker, regardless of the thread that will actually
execute it.
Later, if task completes successfully, the handle is marked
completed with the result that has been returned from the task.
If the task ends with an exception, the handle is marked
failed with cause being that exception. In such case, as a debugging
aid, current stack trace (that is, that of this method's invoker) is
appended to the original stack trace.
- Parameters:
executor
- the executor to usecall
- the task to schedulecb
- callback to invoke upon completion
- Returns:
- completion handle that can be used to access the result or
cancel the task
start
public static AsyncTask start(Executor executor,
Callable call,
Callback cb,
boolean disableStackTraces)
- Schedules specified task with given executor, and returns
completion handle that can be used to access the result or to cancel
the task. The task will run
with access control context and
ThreadContext
inherited from
this method's invoker, regardless of the thread that will actually
execute it.
Later, if task completes successfully, the handle is marked
completed with the result that has been returned from the task.
If the task ends with an exception, the handle is marked
failed with cause being that exception. In such case, as a debugging
aid, current stack trace (that is, that of this method's invoker) is
appended to the original stack trace unless
the disableStackTraces parameter is set to false
- Parameters:
executor
- the executor to usecall
- the task to schedulecb
- callback to invoke upon completiondisableStackTraces
- if true, does not append invoker stack trace
to traces of exceptions thrown during task execution
- Returns:
- completion handle that can be used to access the result or
cancel the task