public interface WorkManager
WorkManager
executes Work
instances asynchronously.
A Work
can be scheduled by calling schedule(org.nuxeo.ecm.core.work.api.Work)
.
Work is executed in a thread pool and a work queue that depends on the work's category.
Modifier and Type | Interface and Description |
---|---|
static class |
WorkManager.Scheduling
The scheduling policy to use when adding a work instance using
schedule(Work, Scheduling) . |
Modifier and Type | Method and Description |
---|---|
boolean |
awaitCompletion(long timeout,
TimeUnit unit)
Waits for completion of all work.
|
boolean |
awaitCompletion(String queueId,
long timeout,
TimeUnit unit)
Waits for completion of work in a given queue.
|
void |
cleanup()
Clears the list of completed work instances older than what's configured
for each queue.
|
void |
clearCompletedWork(long completionTime)
Clears the list of completed work instances older than the given time.
|
void |
clearCompletedWork(String queueId)
Clears the list of completed work instances for a given queue.
|
Work |
find(Work work,
Work.State state,
boolean useEquals,
int[] pos)
Finds a work instance by equality or identity.
|
String |
getCategoryQueueId(String category)
Gets the queue id used for a given work category.
|
int |
getNonCompletedWorkSize(String queueId)
Gets the size of the non-completed work (scheduled + running) for a give
queue.
|
WorkQueueDescriptor |
getWorkQueueDescriptor(String queueId)
Gets the work queue descriptor for a given queue id.
|
List<String> |
getWorkQueueIds()
Lists the ids of the existing work queues.
|
void |
init()
Starts up this
WorkManager and attempts to resume work previously
suspended and saved at shutdown(long, java.util.concurrent.TimeUnit) time. |
List<Work> |
listWork(String queueId,
Work.State state)
Lists the work instances in a given queue in a defined state.
|
void |
schedule(Work work)
Schedules work for execution at a later time.
|
void |
schedule(Work work,
WorkManager.Scheduling scheduling)
Schedules work for execution at a later time, with a specific
scheduling policy.
|
boolean |
shutdown(long timeout,
TimeUnit unit)
Shuts down this
WorkManager and attempts to suspend and save the
running and scheduled work instances. |
boolean |
shutdownQueue(String queueId,
long timeout,
TimeUnit unit)
Shuts down a work queue and attempts to suspend and save the running and
scheduled work instances.
|
List<String> getWorkQueueIds()
String getCategoryQueueId(String category)
category
- the categoryWorkQueueDescriptor getWorkQueueDescriptor(String queueId)
queueId
- the queue idnull
void init()
WorkManager
and attempts to resume work previously
suspended and saved at shutdown(long, java.util.concurrent.TimeUnit)
time.boolean shutdownQueue(String queueId, long timeout, TimeUnit unit) throws InterruptedException
queueId
- the queue idtimeout
- the time to waitunit
- the timeout unittrue
if shutdown is done, false
if there are
still some threads executing after the timeoutInterruptedException
boolean shutdown(long timeout, TimeUnit unit) throws InterruptedException
WorkManager
and attempts to suspend and save the
running and scheduled work instances.timeout
- the time to waitunit
- the timeout unittrue
if shutdown is done, false
if there are
still some threads executing after the timeoutInterruptedException
void schedule(Work work)
work
- the work to executevoid schedule(Work work, WorkManager.Scheduling scheduling)
work
- the work to executescheduling
- the scheduling policyschedule(Work)
Work find(Work work, Work.State state, boolean useEquals, int[] pos)
Note that an instance requested as RUNNING could be found SUSPENDING or SUSPENDED, and an instance requested as COMPLETED could be found FAILED.
Also, due to the asynchronous nature of work execution, the state of the work could be different than what's expected if the work started or finished in the middle of the call.
work
- the work to findstate
- the state defining the state to look into,
SCHEDULED
, RUNNING
, COMPLETED
, or null
for non-completeduseEquals
- if true
then use Work#equals
to find the
work instance, otherwise use object identitypos
- a 1-element array to return the position in the internal queuenull
if not foundList<Work> listWork(String queueId, Work.State state)
Note that an instance requested as RUNNING could be found SUSPENDING or SUSPENDED, and an instance requested as COMPLETED could be found FAILED.
int getNonCompletedWorkSize(String queueId)
queueId
- the queue idboolean awaitCompletion(String queueId, long timeout, TimeUnit unit) throws InterruptedException
queueId
- the queue idtimeout
- the time to waitunit
- the timeout unittrue
if all work completed in the queue, or false
if there is still some non-completed work after the timeoutInterruptedException
boolean awaitCompletion(long timeout, TimeUnit unit) throws InterruptedException
timeout
- the time to waitunit
- the timeout unittrue
if all work completed, or false
if there is
still some non-completed work after the timeoutInterruptedException
void clearCompletedWork(String queueId)
queueId
- the queue idvoid clearCompletedWork(long completionTime)
completionTime
- the completion time (milliseconds since epoch)
before which completed work instances are cleared, or
0
for allvoid cleanup()
Copyright © 2012 Nuxeo SA. All Rights Reserved.