public class AsyncBackgroundTaskManager extends BackgroundTaskManager
BackgroundTaskManager. Tasks run in a pool. Takes
a blocking flag in constructor; when blocking=true, manager waits for tasks to complete
before returning control to client. When blocking=false, manager schedules on a separate
thread and does not wait for task completion. Scheduler thread is paused whenever a new command
begins.
NOTE: only a manager on buckd should be set/instantiated to nonblocking mode, otherwise unexpected behavior might occur
| Modifier | Constructor and Description |
|---|---|
protected |
AsyncBackgroundTaskManager(int nThreads) |
| Modifier and Type | Method and Description |
|---|---|
protected Map<Class<?>,com.facebook.buck.support.bgtasks.ManagedBackgroundTask<?>> |
getCancellableTasks()
Return map of tasks that might be cancelled (i.e.
|
protected int |
getCommandsRunning() |
TaskManagerCommandScope |
getNewScope(BuildId buildId,
boolean blocking)
Returns a new
TaskManagerCommandScope for a build on this manager. |
protected Queue<com.facebook.buck.support.bgtasks.ManagedBackgroundTask<?>> |
getScheduledTasks()
Return list of currently scheduled (not yet submitted) tasks.
|
protected boolean |
isShutDown()
Check if the manager is shut down.
|
static AsyncBackgroundTaskManager |
of()
Same as
of() except with the default number of threads. |
static AsyncBackgroundTaskManager |
of(int nThreads)
Constructs an
AsyncBackgroundTaskManager. |
void |
shutdown(long timeout,
TimeUnit units)
Shut down manager, waiting until given timeout for tasks to finish.
|
void |
shutdownNow()
Shut down scheduler and pool threads.
|
protected void |
startScheduling() |
public static AsyncBackgroundTaskManager of(int nThreads)
AsyncBackgroundTaskManager. If in nonblocking mode, sets up a scheduler
thread and pool for tasks.nThreads - (optional) number of threads in pool. defaults to DEFAULT_THREADS if
not providedpublic static AsyncBackgroundTaskManager of()
of() except with the default number of threads.public TaskManagerCommandScope getNewScope(BuildId buildId, boolean blocking)
BackgroundTaskManagerTaskManagerCommandScope for a build on this manager. The TaskManagerCommandScope lives for the duration of the command such that it's TaskManagerCommandScope.close() will trigger the tasks scheduled to be ran.getNewScope in class BackgroundTaskManagerbuildId - unique identifier BuildId of a command that created a scopeblocking - whether the current command should wait for tasks to finish on exitprotected void startScheduling()
public void shutdownNow()
shutdownNow in class BackgroundTaskManagerpublic void shutdown(long timeout,
TimeUnit units)
throws InterruptedException
BackgroundTaskManagershutdown in class BackgroundTaskManagertimeout - timeout for tasks to finishunits - units of timeoutInterruptedExceptionprotected Queue<com.facebook.buck.support.bgtasks.ManagedBackgroundTask<?>> getScheduledTasks()
protected Map<Class<?>,com.facebook.buck.support.bgtasks.ManagedBackgroundTask<?>> getCancellableTasks()
protected boolean isShutDown()
protected int getCommandsRunning()