public class WorkManagerImpl extends DefaultComponent implements WorkManager
WorkManager
. This delegates the queuing implementation to a WorkQueuing
implementation.Modifier and Type | Class and Description |
---|---|
static class |
WorkManagerImpl.CancelingPolicy
A handler for rejected tasks that discards them.
|
class |
WorkManagerImpl.WorkCompletionSynchronizer |
class |
WorkManagerImpl.WorkScheduling
A work instance and how to schedule it, for schedule-after-commit.
|
WorkManager.Scheduling
Modifier and Type | Field and Description |
---|---|
static String |
DEFAULT_CATEGORY |
static String |
DEFAULT_QUEUE_ID |
static String |
NAME |
Constructor and Description |
---|
WorkManagerImpl() |
Modifier and Type | Method and Description |
---|---|
void |
activate(ComponentContext context)
Activates the component.
|
void |
applicationStarted(ComponentContext context)
Notify the component that Nuxeo Framework finished starting all Nuxeo bundles.
|
boolean |
awaitCompletion(long duration,
TimeUnit unit)
Waits for completion of all work.
|
boolean |
awaitCompletion(String queueId,
long duration,
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.
|
void |
deactivateQueue(WorkQueueDescriptor workQueueDescriptor) |
Work |
find(Work work,
Work.State state,
boolean useEquals,
int[] pos)
Deprecated.
|
int |
getApplicationStartedOrder()
The component notification order for
Component.applicationStarted(org.nuxeo.runtime.model.ComponentContext) . |
String |
getCategoryQueueId(String category)
Gets the queue id used for a given work category.
|
int |
getNonCompletedWorkSize(String queueId)
Deprecated.
|
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
WorkManager.shutdown(long, java.util.concurrent.TimeUnit) time. |
boolean |
isStarted() |
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 |
registerContribution(Object contribution,
String extensionPoint,
ComponentInstance contributor) |
void |
registerWorkQueuing(WorkQueuing q) |
void |
registerWorkQueuingDescriptor(WorkQueuingImplDescriptor descr) |
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.
|
void |
unregisterContribution(Object contribution,
String extensionPoint,
ComponentInstance contributor) |
void |
unregisterWorkQueing() |
void |
unregisterWorkQueuingDescriptor(WorkQueuingImplDescriptor descr) |
deactivate, getAdapter, getLastModified, registerExtension, setLastModified, unregisterExtension
public static final String NAME
public static final String DEFAULT_QUEUE_ID
public static final String DEFAULT_CATEGORY
public void activate(ComponentContext context)
Component
This method is called by the runtime when a component is activated.
activate
in interface Component
activate
in class DefaultComponent
context
- the runtime contextpublic void registerContribution(Object contribution, String extensionPoint, ComponentInstance contributor)
registerContribution
in class DefaultComponent
public void unregisterContribution(Object contribution, String extensionPoint, ComponentInstance contributor)
unregisterContribution
in class DefaultComponent
public void deactivateQueue(WorkQueueDescriptor workQueueDescriptor)
public void registerWorkQueuingDescriptor(WorkQueuingImplDescriptor descr)
public void registerWorkQueuing(WorkQueuing q)
public void unregisterWorkQueuingDescriptor(WorkQueuingImplDescriptor descr)
public void unregisterWorkQueing()
public List<String> getWorkQueueIds()
WorkManager
getWorkQueueIds
in interface WorkManager
public WorkQueueDescriptor getWorkQueueDescriptor(String queueId)
WorkManager
getWorkQueueDescriptor
in interface WorkManager
queueId
- the queue idnull
public String getCategoryQueueId(String category)
WorkManager
getCategoryQueueId
in interface WorkManager
category
- the categorypublic int getApplicationStartedOrder()
Component
Component.applicationStarted(org.nuxeo.runtime.model.ComponentContext)
.
Components are notified in increasing order. Order 1000 is the default order for components that don't care. Order 100 is the repository initialization.
getApplicationStartedOrder
in interface Component
getApplicationStartedOrder
in class DefaultComponent
public void applicationStarted(ComponentContext context)
Component
applicationStarted
in interface Component
applicationStarted
in class DefaultComponent
public void init()
WorkManager
WorkManager
and attempts to resume work previously suspended and saved at
WorkManager.shutdown(long, java.util.concurrent.TimeUnit)
time.init
in interface WorkManager
public boolean shutdownQueue(String queueId, long timeout, TimeUnit unit) throws InterruptedException
WorkManager
shutdownQueue
in interface WorkManager
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
public boolean shutdown(long timeout, TimeUnit unit) throws InterruptedException
WorkManager
WorkManager
and attempts to suspend and save the running and scheduled work instances.shutdown
in interface WorkManager
timeout
- the time to waitunit
- the timeout unittrue
if shutdown is done, false
if there are still some threads executing after the
timeoutInterruptedException
public void schedule(Work work)
WorkManager
This method is identical to WorkManager.schedule(Work, boolean)
with afterCommit = false
.
schedule
in interface WorkManager
work
- the work to executepublic void schedule(Work work, boolean afterCommit)
WorkManager
schedule
in interface WorkManager
work
- the work to executeafterCommit
- if true
and the work is scheduled, it will only be run after the current transaction
(if any) has committedpublic void schedule(Work work, WorkManager.Scheduling scheduling)
WorkManager
This method is identical to WorkManager.schedule(Work, Scheduling, boolean)
with afterCommit = false
.
schedule
in interface WorkManager
work
- the work to executescheduling
- the scheduling policyWorkManager.schedule(Work)
public void schedule(Work work, WorkManager.Scheduling scheduling, boolean afterCommit)
WorkManager
schedule
in interface WorkManager
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 committedWorkManager.schedule(Work)
@Deprecated public Work find(Work work, Work.State state, boolean useEquals, int[] pos)
WorkManager
find
in interface WorkManager
work
- the work to findstate
- the state defining the state to look into, SCHEDULED
, RUNNING
, COMPLETED
, or null
for non-completeduseEquals
- ignored, always uses work id equalitypos
- ignored, pass nullnull
if not foundpublic Work.State getWorkState(String workId)
WorkManager
This can be SCHEDULED
, RUNNING
, COMPLETED
,
Work.State.CANCELED
or Work.State.FAILED
.
getWorkState
in interface WorkManager
workId
- the id of the work to findnull
if not foundpublic List<Work> listWork(String queueId, Work.State state)
WorkManager
listWork
in interface WorkManager
queueId
- the queue idstate
- the state defining the state to look into, SCHEDULED
, RUNNING
, COMPLETED
, or null
for non-completedpublic List<String> listWorkIds(String queueId, Work.State state)
WorkManager
listWorkIds
in interface WorkManager
queueId
- the queue idstate
- the state defining the state to look into, SCHEDULED
, RUNNING
, COMPLETED
, or null
for non-completedpublic int getQueueSize(String queueId, Work.State state)
WorkManager
getQueueSize
in interface WorkManager
queueId
- the queue idstate
- the state defining the state to look into, SCHEDULED
, RUNNING
, COMPLETED
, or null
for non-completed (
SCHEDULED
or RUNNING
)@Deprecated public int getNonCompletedWorkSize(String queueId)
WorkManager
getNonCompletedWorkSize
in interface WorkManager
queueId
- the queue idpublic boolean awaitCompletion(String queueId, long duration, TimeUnit unit) throws InterruptedException
WorkManager
awaitCompletion
in interface WorkManager
queueId
- the queue idduration
- 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
public boolean awaitCompletion(long duration, TimeUnit unit) throws InterruptedException
WorkManager
awaitCompletion
in interface WorkManager
duration
- the time to waitunit
- the timeout unittrue
if all work completed, or false
if there is still some non-completed work after the
timeoutInterruptedException
public void clearCompletedWork(String queueId)
WorkManager
clearCompletedWork
in interface WorkManager
queueId
- the queue idpublic void clearCompletedWork(long completionTime)
WorkManager
clearCompletedWork
in interface WorkManager
completionTime
- the completion time (milliseconds since epoch) before which completed work instances are
cleared, or 0
for allpublic void cleanup()
WorkManager
cleanup
in interface WorkManager
public boolean isStarted()
isStarted
in interface WorkManager
true
if activeDefaultComponent.applicationStarted(org.nuxeo.runtime.model.ComponentContext)
,
WorkManager.init()
,
WorkManager.shutdown(long, TimeUnit)
Copyright © 2015 Nuxeo SA. All rights reserved.