public abstract class AsyncCoordinator extends Thread
Thread.State, Thread.UncaughtExceptionHandler
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
Modifier | Constructor and Description |
---|---|
protected |
AsyncCoordinator() |
Modifier and Type | Method and Description |
---|---|
abstract void |
enqueue(AsyncTask task)
Enqueue a task object, normally you enqueue using task handler, which will then
call this method.
|
abstract AsyncTask |
enqueue(AsyncTaskHandler handler)
Enqueue a new task runner; a task object will automatically be created for
this handler.
|
abstract AsyncTask |
enqueue(AsyncTaskHandler handler,
String customKey,
long executeAt)
Enque a new task handler.
|
boolean |
executeNext()
Execute the text in the queue, if any exists.
|
boolean |
executeNext(Long now)
Execute the next task, passing in the current time.
|
protected abstract AsyncTask |
findAndLockNextTask(Long now)
Find the next task that is unlocked and ready for execution, lock it, and return it.
|
List<ClassLoader> |
getExtraClassLoaders() |
abstract int |
getPendingTaskCount()
Get the number of tasks waiting to be executed.
|
abstract AsyncTaskPersister |
getTaskPersister() |
static void |
gracefulShutdown()
Shutdown, while waiting for all task handlers to finish executing.
|
abstract boolean |
hasPendingTaskWithCustomKey(String key)
Has an unexecuted task with the given custom key
|
abstract boolean |
hasTaskWithCustomKey(String key)
Has any task, pending or already run, with the given custom key
|
abstract boolean |
hasTaskWithId(Long taskId)
Check to see if the task with the given id exists in the queue
|
static void |
init()
Load the coordinator class so that tasks and handlers can be registered, but
don't actually execute any tasks.
|
static void |
initAndStart() |
static void |
initEphemeralSynchronousForTests() |
static void |
initForTests() |
static AsyncCoordinator |
instance() |
boolean |
isSynchronousMode()
true if is in test mode, where we run tests synchronously rather than in a background thread
|
abstract boolean |
markCompleted(AsyncTask task)
Mark the task as completed.
|
abstract boolean |
markFailed(AsyncTask task,
Throwable throwable)
Mark the task as failed.
|
abstract void |
onLoadTaskOnBoot(AsyncTask task)
Called when a task is loaded from the data store during the boot phase.
|
void |
registerClassLoader(ClassLoader loader) |
void |
registerHandler(Class<JsAsyncTaskHandler> handler)
Register a handler that will run tasks of a given name.
|
void |
registerHandler(String name,
Class cls)
Register a handler that will run tasks of a given name.
|
void |
run() |
void |
runTaskForId(Long taskId,
boolean force)
Directly, synchronously execute the task with the given ID, regardless
of whether it has errored out or is scheduled for the future.
|
protected abstract void |
saveNewTask(AsyncTask task)
Save a new task to the data store
|
static void |
shutDownForTests() |
static void |
startup()
Actually start the loop to poll for tasks and execute them.
|
abstract void |
updateTask(AsyncTask task,
boolean executeAtChanged)
Update a task with new information.
|
activeCount, checkAccess, clone, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
protected AsyncCoordinator()
public static AsyncCoordinator instance()
public static void initAndStart()
public static void init()
public static void initEphemeralSynchronousForTests()
public static void initForTests()
public static void startup()
public boolean executeNext()
public boolean executeNext(Long now)
now
- - milliseconds since the epoch.public void registerHandler(String name, Class cls)
name
- cls
- public void registerHandler(Class<JsAsyncTaskHandler> handler)
handler
- protected abstract AsyncTask findAndLockNextTask(Long now)
now
- protected abstract void saveNewTask(AsyncTask task)
task
- public abstract void updateTask(AsyncTask task, boolean executeAtChanged)
task
- executeAtChanged
- public abstract boolean markCompleted(AsyncTask task)
task
- public void runTaskForId(Long taskId, boolean force)
taskId
- force
- -- if true, will run the job even if it is lockedpublic abstract boolean markFailed(AsyncTask task, Throwable throwable)
task
- throwable
- public abstract AsyncTask enqueue(AsyncTaskHandler handler)
handler
- public abstract AsyncTask enqueue(AsyncTaskHandler handler, String customKey, long executeAt)
handler
- - the task handler that will be executed.customKey
- - a user generated unique key that allows you to prevent dupes or later update the taskexecuteAt
- - when you want the task to execute, in epoch millisecondspublic abstract void enqueue(AsyncTask task)
task
- public abstract void onLoadTaskOnBoot(AsyncTask task)
task
- public abstract int getPendingTaskCount()
public abstract AsyncTaskPersister getTaskPersister()
public abstract boolean hasTaskWithId(Long taskId)
taskId
- public abstract boolean hasPendingTaskWithCustomKey(String key)
key
- public abstract boolean hasTaskWithCustomKey(String key)
key
- public static void shutDownForTests()
public static void gracefulShutdown()
public boolean isSynchronousMode()
public void registerClassLoader(ClassLoader loader)
public List<ClassLoader> getExtraClassLoaders()
Copyright © 2016. All rights reserved.