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)
Deprecated.
since 5.8, use
getWorkState(java.lang.String) instead |
String |
getCategoryQueueId(String category)
Gets the queue id used for a given work category.
|
int |
getNonCompletedWorkSize(String queueId)
Deprecated.
since 5.8, use
getQueueSize(java.lang.String, org.nuxeo.ecm.core.work.api.Work.State) with null state
instead |
int |
getQueueSize(String queueId,
Work.State state)
Gets the number of work instances in a given queue in a defined state.
|
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.
|
Work.State |
getWorkState(String workId)
Gets the state in which a work instance is.
|
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.
|
List<String> |
listWorkIds(String queueId,
Work.State state)
Lists the work ids in a given queue in a defined state.
|
void |
schedule(Work work)
Schedules work for execution at a later time.
|
void |
schedule(Work work,
boolean afterCommit)
Schedules work for execution at a later time, after the current
transaction (if any) has committed.
|
void |
schedule(Work work,
WorkManager.Scheduling scheduling)
Schedules work for execution at a later time, with a specific
scheduling policy.
|
void |
schedule(Work work,
WorkManager.Scheduling scheduling,
boolean afterCommit)
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)
This method is identical to schedule(Work, boolean)
with
afterCommit = false
.
work
- the work to executevoid schedule(Work work, boolean afterCommit)
work
- the work to executeafterCommit
- if true
and the work is scheduled, it will
only be run after the current transaction (if any) has
committedvoid schedule(Work work, WorkManager.Scheduling scheduling)
This method is identical to schedule(Work, Scheduling, boolean)
with afterCommit = false
.
work
- the work to executescheduling
- the scheduling policyschedule(Work)
void schedule(Work work, WorkManager.Scheduling scheduling, boolean afterCommit)
work
- the work to executescheduling
- the scheduling policyafterCommit
- if true
and the work is scheduled, it will
only be run after the current transaction (if any) has
committedschedule(Work)
@Deprecated Work find(Work work, Work.State state, boolean useEquals, int[] pos)
getWorkState(java.lang.String)
insteadWork.State getWorkState(String workId)
This can be SCHEDULED
, RUNNING
, COMPLETED
, Work.State.CANCELED
or
Work.State.FAILED
.
workId
- the id of the work to findnull
if not foundList<Work> listWork(String queueId, Work.State state)
List<String> listWorkIds(String queueId, Work.State state)
int getQueueSize(String queueId, Work.State state)
@Deprecated int getNonCompletedWorkSize(String queueId)
getQueueSize(java.lang.String, org.nuxeo.ecm.core.work.api.Work.State)
with null
state
insteadqueueId
- 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 © 2014 Nuxeo SA. All Rights Reserved.