public class WorkManagerImpl extends DefaultComponent implements WorkManager
WorkManager. This delegates the queuing implementation to a WorkQueuing
implementation.| Modifier and Type | Class and Description |
|---|---|
protected class |
WorkManagerImpl.WorkCompletionSynchronizer
Simple synchronizer to wake up when an in-JVM work is completed.
|
class |
WorkManagerImpl.WorkScheduling
A work instance and how to schedule it, for schedule-after-commit.
|
protected class |
WorkManagerImpl.WorkThreadPoolExecutor
A
ThreadPoolExecutor that keeps available the list of running tasks. |
WorkManager.Scheduling| Modifier and Type | Field and Description |
|---|---|
protected boolean |
active |
protected Map<String,String> |
categoryToQueueId |
protected WorkManagerImpl.WorkCompletionSynchronizer |
completionSynchronizer |
static String |
DEFAULT_CATEGORY |
static String |
DEFAULT_QUEUE_ID |
protected Map<String,WorkManagerImpl.WorkThreadPoolExecutor> |
executors |
protected static String |
IMPL_EP |
static String |
NAME |
protected static String |
QUEUES_EP |
protected WorkQueuing |
queuing |
protected com.codahale.metrics.MetricRegistry |
registry |
static String |
SHUTDOWN_DELAY_MS_KEY |
protected boolean |
shutdownInProgress |
protected boolean |
started |
protected static String |
THREAD_PREFIX |
lastModified, name| Constructor and Description |
|---|
WorkManagerImpl() |
| Modifier and Type | Method and Description |
|---|---|
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 |
enableProcessing(boolean value)
Set processing for all queues
|
void |
enableProcessing(String queueId,
boolean value)
Set processing for a given queue id.
|
Work |
find(String workId,
Work.State state)
Finds a work instance.
|
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.
|
protected WorkManagerImpl.WorkThreadPoolExecutor |
getExecutor(String queueId) |
WorkQueueMetrics |
getMetrics(String queueId)
Gets the metrics for the
queueId |
int |
getQueueSize(String queueId,
Work.State state)
Gets the number of work instances in a given queue in a defined state.
|
protected long |
getTimestampAfter(long durationInMs) |
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.
|
protected boolean |
hasWorkInState(String workId,
Work.State state) |
protected void |
index() |
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 |
isProcessingEnabled()
Is processing enabled for at least one queue
|
boolean |
isProcessingEnabled(String queueId)
Is processing enabled for a given queue id.
|
boolean |
isQueuingEnabled(String queueId)
Is queuing enabled for a given queue id.
|
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.
|
protected boolean |
noScheduledOrRunningWork(String queueId) |
void |
registerContribution(Object contribution,
String xp,
ComponentInstance component) |
protected long |
remainingMillis(long t0,
long delay)
Deprecated.
since 10.2 because unused
|
protected void |
removeExecutor(String queueId)
Deprecated.
since 10.2 because unused
|
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.
|
protected boolean |
scheduleAfterCommit(Work work,
WorkManager.Scheduling scheduling)
Schedule after commit.
|
void |
setName(String name)
Sets the name for this component, as it was defined in its XML.
|
boolean |
shutdown(long timeout,
TimeUnit unit)
Shuts down this
WorkManager and attempts to suspend and save the running and scheduled work instances. |
protected boolean |
shutdownExecutors(Collection<WorkManagerImpl.WorkThreadPoolExecutor> list,
long timeout,
TimeUnit unit) |
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 |
start(ComponentContext context)
Start the component.
|
boolean |
supportsProcessingDisabling() |
activate, deactivate, getAdapter, getDescriptor, getDescriptors, getLastModified, getRegistry, register, registerExtension, setLastModified, setModifiedNow, stop, unregister, unregisterContribution, unregisterExtensionclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitapplicationStartedpublic static final String NAME
protected static final String QUEUES_EP
protected static final String IMPL_EP
public static final String DEFAULT_QUEUE_ID
public static final String DEFAULT_CATEGORY
protected static final String THREAD_PREFIX
public static final String SHUTDOWN_DELAY_MS_KEY
protected final com.codahale.metrics.MetricRegistry registry
protected final Map<String,WorkManagerImpl.WorkThreadPoolExecutor> executors
protected final Map<String,String> categoryToQueueId
protected WorkQueuing queuing
protected boolean active
protected WorkManagerImpl.WorkCompletionSynchronizer completionSynchronizer
protected volatile boolean started
protected volatile boolean shutdownInProgress
public WorkManagerImpl()
public void setName(String name)
ComponentThis is called once after construction by the runtime framework.
setName in interface ComponentsetName in class DefaultComponentname - the namepublic void registerContribution(Object contribution, String xp, ComponentInstance component)
registerContribution in class DefaultComponentpublic boolean isQueuingEnabled(String queueId)
WorkManagerisQueuingEnabled in interface WorkManagerpublic void enableProcessing(boolean value)
WorkManagerenableProcessing in interface WorkManagerpublic void enableProcessing(String queueId, boolean value)
WorkManagerenableProcessing in interface WorkManagerpublic boolean isProcessingEnabled()
WorkManagerisProcessingEnabled in interface WorkManagerpublic boolean isProcessingEnabled(String queueId)
WorkManagerisProcessingEnabled in interface WorkManagerpublic List<String> getWorkQueueIds()
WorkManagergetWorkQueueIds in interface WorkManagerpublic WorkQueueDescriptor getWorkQueueDescriptor(String queueId)
WorkManagergetWorkQueueDescriptor in interface WorkManagerqueueId - the queue idnullpublic String getCategoryQueueId(String category)
WorkManagergetCategoryQueueId in interface WorkManagercategory - the categorypublic int getApplicationStartedOrder()
ComponentComponent.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 Componentpublic void start(ComponentContext context)
Componentstart in interface Componentstart in class DefaultComponentpublic void init()
WorkManagerWorkManager and attempts to resume work previously suspended and saved at
WorkManager.shutdown(long, java.util.concurrent.TimeUnit) time.init in interface WorkManagerprotected void index()
protected WorkManagerImpl.WorkThreadPoolExecutor getExecutor(String queueId)
public boolean shutdownQueue(String queueId, long timeout, TimeUnit unit) throws InterruptedException
WorkManagershutdownQueue in interface WorkManagerqueueId - the queue idtimeout - the time to waitunit - the timeout unittrue if shutdown is done, false if there are still some threads executing after the
timeoutInterruptedExceptionprotected boolean shutdownExecutors(Collection<WorkManagerImpl.WorkThreadPoolExecutor> list, long timeout, TimeUnit unit) throws InterruptedException
InterruptedException@Deprecated protected long remainingMillis(long t0, long delay)
@Deprecated protected void removeExecutor(String queueId)
public boolean shutdown(long timeout, TimeUnit unit) throws InterruptedException
WorkManagerWorkManager and attempts to suspend and save the running and scheduled work instances.shutdown in interface WorkManagertimeout - the time to waitunit - the timeout unittrue if shutdown is done, false if there are still some threads executing after the
timeoutInterruptedExceptionpublic void schedule(Work work)
WorkManager
This method is identical to WorkManager.schedule(Work, boolean) with afterCommit = false.
schedule in interface WorkManagerwork - the work to executepublic void schedule(Work work, boolean afterCommit)
WorkManagerschedule in interface WorkManagerwork - 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 WorkManagerwork - the work to executescheduling - the scheduling policyWorkManager.schedule(Work)public void schedule(Work work, WorkManager.Scheduling scheduling, boolean afterCommit)
WorkManagerschedule in interface WorkManagerwork - 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)protected boolean scheduleAfterCommit(Work work, WorkManager.Scheduling scheduling)
false if impossible (no transaction or transaction manager).public Work find(String workId, Work.State state)
WorkManagerfind in interface WorkManagerworkId - the id of the work to findstate - the state defining the state to look into, SCHEDULED, RUNNING, or null for non-completednull if not foundprotected boolean hasWorkInState(String workId, Work.State state)
state - SCHEDULED, RUNNING or null for bothpublic Work.State getWorkState(String workId)
WorkManagergetWorkState in interface WorkManagerworkId - the id of the work to findnull if not foundpublic List<Work> listWork(String queueId, Work.State state)
WorkManagerlistWork in interface WorkManagerqueueId - the queue idstate - the state defining the state to look into, SCHEDULED, RUNNING, or null for non-completedpublic List<String> listWorkIds(String queueId, Work.State state)
WorkManagerlistWorkIds in interface WorkManagerqueueId - the queue idstate - the state defining the state to look into, SCHEDULED, RUNNING, or null for non-completedpublic WorkQueueMetrics getMetrics(String queueId)
WorkManagerqueueIdgetMetrics in interface WorkManagerpublic int getQueueSize(String queueId, Work.State state)
WorkManagergetQueueSize in interface WorkManagerqueueId - the queue idstate - the state defining the state to look into, SCHEDULED, RUNNING, COMPLETED, or null for non-completed (
SCHEDULED or RUNNING)public boolean awaitCompletion(long duration, TimeUnit unit) throws InterruptedException
WorkManagerawaitCompletion in interface WorkManagerduration - the time to waitunit - the timeout unittrue if all work completed, or false if there is still some non-completed work after the
timeoutInterruptedExceptionpublic boolean awaitCompletion(String queueId, long duration, TimeUnit unit) throws InterruptedException
WorkManagerawaitCompletion in interface WorkManagerqueueId - 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 timeoutInterruptedExceptionprotected long getTimestampAfter(long durationInMs)
protected boolean noScheduledOrRunningWork(String queueId)
public boolean isStarted()
isStarted in interface WorkManagertrue if activeComponent.applicationStarted(org.nuxeo.runtime.model.ComponentContext),
WorkManager.init(),
WorkManager.shutdown(long, TimeUnit)public boolean supportsProcessingDisabling()
supportsProcessingDisabling in interface WorkManagerCopyright © 2019 Nuxeo. All rights reserved.