Package org.nuxeo.ecm.core.work
Class WorkManagerImpl
- java.lang.Object
- 
- org.nuxeo.runtime.model.DefaultComponent
- 
- org.nuxeo.ecm.core.work.WorkManagerImpl
 
 
- 
- All Implemented Interfaces:
- WorkManager,- Adaptable,- Component,- Extensible,- TimestampedService
 - Direct Known Subclasses:
- StreamWorkManager
 
 public class WorkManagerImpl extends DefaultComponent implements WorkManager The implementation of aWorkManager. This delegates the queuing implementation to aWorkQueuingimplementation.- Since:
- 5.6
 
- 
- 
Nested Class SummaryNested Classes Modifier and Type Class Description protected static classWorkManagerImpl.WorkCompletionSynchronizerSimple synchronizer to wake up when an in-JVM work is completed.classWorkManagerImpl.WorkSchedulingA work instance and how to schedule it, for schedule-after-commit.protected classWorkManagerImpl.WorkThreadPoolExecutorAThreadPoolExecutorthat keeps available the list of running tasks.- 
Nested classes/interfaces inherited from interface org.nuxeo.ecm.core.work.api.WorkManagerWorkManager.Scheduling
 
- 
 - 
Field SummaryFields Modifier and Type Field Description protected booleanactiveprotected Map<String,String>categoryToQueueIdprotected WorkManagerImpl.WorkCompletionSynchronizercompletionSynchronizerstatic NameDEAD_LETTER_QUEUEThe dead letter queue stream name.static Codec<Record>DEAD_LETTER_QUEUE_CODECstatic StringDEFAULT_CATEGORYstatic StringDEFAULT_QUEUE_IDprotected Map<String,WorkManagerImpl.WorkThreadPoolExecutor>executorsprotected static StringGLOBAL_METRIC_PREFIXprotected static StringIMPL_EPstatic StringNAMEprotected static StringQUEUES_EPprotected WorkQueuingqueuingprotected io.dropwizard.metrics5.MetricRegistryregistrystatic StringSHUTDOWN_DELAY_MS_KEYprotected booleanshutdownInProgressprotected booleanstartedprotected static StringTHREAD_PREFIXstatic StringWORKMANAGER_PROCESSING_DISABLEDeprecated.UseWORKMANAGER_PROCESSING_ENABLEDinsteadstatic StringWORKMANAGER_PROCESSING_ENABLED- 
Fields inherited from class org.nuxeo.runtime.model.DefaultComponentlastModified, name
 
- 
 - 
Constructor SummaryConstructors Constructor Description WorkManagerImpl()
 - 
Method SummaryAll Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description booleanawaitCompletion(long duration, TimeUnit unit)Waits for completion of all work.booleanawaitCompletion(String queueId, long duration, TimeUnit unit)Waits for completion of work in a given queue.voidenableProcessing(boolean value)Set processing for all queuesvoidenableProcessing(String queueId, boolean value)Set processing for a given queue id.Workfind(String workId, Work.State state)Finds a work instance.intgetApplicationStartedOrder()The component notification order forComponent.applicationStarted(org.nuxeo.runtime.model.ComponentContext).StringgetCategoryQueueId(String category)Gets the queue id used for a given work category.protected WorkManagerImpl.WorkThreadPoolExecutorgetExecutor(String queueId)WorkQueueMetricsgetMetrics(String queueId)Gets the metrics for thequeueIdintgetQueueSize(String queueId, Work.State state)Gets the number of work instances in a given queue in a defined state.protected longgetTimestampAfter(long durationInMs)WorkQueueDescriptorgetWorkQueueDescriptor(String queueId)Gets the work queue descriptor for a given queue id.List<String>getWorkQueueIds()Lists the ids of the existing work queues.Work.StategetWorkState(String workId)Gets the state in which a work instance is.protected booleanhasWorkInState(String workId, Work.State state)protected voidindex()voidinit()Starts up thisWorkManagerand attempts to resume work previously suspended and saved atWorkManager.shutdown(long, java.util.concurrent.TimeUnit)time.protected voidinitDeadLetterQueueStream()protected booleanisProcessingDisabled()booleanisProcessingEnabled()Is processing enabled for at least one queuebooleanisProcessingEnabled(String queueId)Is processing enabled for a given queue id.booleanisQueuingEnabled(String queueId)Is queuing enabled for a given queue id.booleanisStarted()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 booleannoScheduledOrRunningWork(String queueId)voidregisterContribution(Object contribution, String xp, ComponentInstance component)protected longremainingMillis(long t0, long delay)Deprecated.since 10.2 because unusedprotected voidremoveExecutor(String queueId)Deprecated.since 10.2 because unusedvoidschedule(Work work)Schedules work for execution at a later time.voidschedule(Work work, boolean afterCommit)Schedules work for execution at a later time, after the current transaction (if any) has committed.voidschedule(Work work, WorkManager.Scheduling scheduling)Schedules work for execution at a later time, with a specific scheduling policy.voidschedule(Work work, WorkManager.Scheduling scheduling, boolean afterCommit)Schedules work for execution at a later time, with a specific scheduling policy.protected booleanscheduleAfterCommit(Work work, WorkManager.Scheduling scheduling)Schedule after commit.voidsetName(String name)Sets the name for this component, as it was defined in its XML.booleanshutdown(long timeout, TimeUnit unit)Shuts down thisWorkManagerand attempts to suspend and save the running and scheduled work instances.protected booleanshutdownExecutors(Collection<WorkManagerImpl.WorkThreadPoolExecutor> list, long timeout, TimeUnit unit)booleanshutdownQueue(String queueId, long timeout, TimeUnit unit)Shuts down a work queue and attempts to suspend and save the running and scheduled work instances.voidstart(ComponentContext context)Start the component.booleansupportsProcessingDisabling()- 
Methods inherited from class org.nuxeo.runtime.model.DefaultComponentactivate, addRuntimeMessage, addRuntimeMessage, deactivate, getAdapter, getDescriptor, getDescriptors, getLastModified, getRegistry, register, registerExtension, setLastModified, setModifiedNow, stop, unregister, unregisterContribution, unregisterExtension
 - 
Methods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 - 
Methods inherited from interface org.nuxeo.runtime.model.ComponentapplicationStarted
 
- 
 
- 
- 
- 
Field Detail- 
NAMEpublic static final String NAME - See Also:
- Constant Field Values
 
 - 
QUEUES_EPprotected static final String QUEUES_EP - See Also:
- Constant Field Values
 
 - 
IMPL_EPprotected static final String IMPL_EP - See Also:
- Constant Field Values
 
 - 
DEFAULT_QUEUE_IDpublic static final String DEFAULT_QUEUE_ID - See Also:
- Constant Field Values
 
 - 
DEFAULT_CATEGORYpublic static final String DEFAULT_CATEGORY - See Also:
- Constant Field Values
 
 - 
THREAD_PREFIXprotected static final String THREAD_PREFIX - See Also:
- Constant Field Values
 
 - 
SHUTDOWN_DELAY_MS_KEYpublic static final String SHUTDOWN_DELAY_MS_KEY - Since:
- 10.2
- See Also:
- Constant Field Values
 
 - 
WORKMANAGER_PROCESSING_DISABLE@Deprecated(since="11.2") public static final String WORKMANAGER_PROCESSING_DISABLE Deprecated.UseWORKMANAGER_PROCESSING_ENABLEDinstead- Since:
- 11.1
- See Also:
- Constant Field Values
 
 - 
WORKMANAGER_PROCESSING_ENABLEDpublic static final String WORKMANAGER_PROCESSING_ENABLED - Since:
- 11.2
- See Also:
- Constant Field Values
 
 - 
DEAD_LETTER_QUEUEpublic static final Name DEAD_LETTER_QUEUE The dead letter queue stream name.- Since:
- 11.1
 
 - 
GLOBAL_METRIC_PREFIXprotected static final String GLOBAL_METRIC_PREFIX - See Also:
- Constant Field Values
 
 - 
registryprotected final io.dropwizard.metrics5.MetricRegistry registry 
 - 
executorsprotected final Map<String,WorkManagerImpl.WorkThreadPoolExecutor> executors 
 - 
queuingprotected WorkQueuing queuing 
 - 
activeprotected boolean active 
 - 
completionSynchronizerprotected WorkManagerImpl.WorkCompletionSynchronizer completionSynchronizer 
 - 
startedprotected volatile boolean started 
 - 
shutdownInProgressprotected volatile boolean shutdownInProgress 
 
- 
 - 
Method Detail- 
setNamepublic void setName(String name) Description copied from interface:ComponentSets the name for this component, as it was defined in its XML.This is called once after construction by the runtime framework. - Specified by:
- setNamein interface- Component
- Overrides:
- setNamein class- DefaultComponent
- Parameters:
- name- the name
 
 - 
registerContributionpublic void registerContribution(Object contribution, String xp, ComponentInstance component) - Overrides:
- registerContributionin class- DefaultComponent
 
 - 
isQueuingEnabledpublic boolean isQueuingEnabled(String queueId) Description copied from interface:WorkManagerIs queuing enabled for a given queue id.- Specified by:
- isQueuingEnabledin interface- WorkManager
 
 - 
enableProcessingpublic void enableProcessing(boolean value) Description copied from interface:WorkManagerSet processing for all queues- Specified by:
- enableProcessingin interface- WorkManager
 
 - 
enableProcessingpublic void enableProcessing(String queueId, boolean value) Description copied from interface:WorkManagerSet processing for a given queue id.- Specified by:
- enableProcessingin interface- WorkManager
 
 - 
isProcessingEnabledpublic boolean isProcessingEnabled() Description copied from interface:WorkManagerIs processing enabled for at least one queue- Specified by:
- isProcessingEnabledin interface- WorkManager
 
 - 
isProcessingDisabledprotected boolean isProcessingDisabled() 
 - 
isProcessingEnabledpublic boolean isProcessingEnabled(String queueId) Description copied from interface:WorkManagerIs processing enabled for a given queue id.- Specified by:
- isProcessingEnabledin interface- WorkManager
 
 - 
getWorkQueueIdspublic List<String> getWorkQueueIds() Description copied from interface:WorkManagerLists the ids of the existing work queues.- Specified by:
- getWorkQueueIdsin interface- WorkManager
- Returns:
- the list of queue ids
 
 - 
getWorkQueueDescriptorpublic WorkQueueDescriptor getWorkQueueDescriptor(String queueId) Description copied from interface:WorkManagerGets the work queue descriptor for a given queue id.- Specified by:
- getWorkQueueDescriptorin interface- WorkManager
- Parameters:
- queueId- the queue id
- Returns:
- the work queue descriptor, or null
 
 - 
getCategoryQueueIdpublic String getCategoryQueueId(String category) Description copied from interface:WorkManagerGets the queue id used for a given work category.- Specified by:
- getCategoryQueueIdin interface- WorkManager
- Parameters:
- category- the category
- Returns:
- the queue id
 
 - 
getApplicationStartedOrderpublic int getApplicationStartedOrder() Description copied from interface:ComponentThe component notification order forComponent.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. - Specified by:
- getApplicationStartedOrderin interface- Component
- Returns:
- the order, 1000 by default
 
 - 
startpublic void start(ComponentContext context) Description copied from interface:ComponentStart the component. This method is called after all the components were resolved and activated- Specified by:
- startin interface- Component
- Overrides:
- startin class- DefaultComponent
 
 - 
initDeadLetterQueueStreamprotected void initDeadLetterQueueStream() 
 - 
initpublic void init() Description copied from interface:WorkManagerStarts up thisWorkManagerand attempts to resume work previously suspended and saved atWorkManager.shutdown(long, java.util.concurrent.TimeUnit)time.- Specified by:
- initin interface- WorkManager
 
 - 
indexprotected void index() 
 - 
getExecutorprotected WorkManagerImpl.WorkThreadPoolExecutor getExecutor(String queueId) 
 - 
shutdownQueuepublic boolean shutdownQueue(String queueId, long timeout, TimeUnit unit) throws InterruptedException Description copied from interface:WorkManagerShuts down a work queue and attempts to suspend and save the running and scheduled work instances.- Specified by:
- shutdownQueuein interface- WorkManager
- Parameters:
- queueId- the queue id
- timeout- the time to wait
- unit- the timeout unit
- Returns:
- trueif shutdown is done,- falseif there are still some threads executing after the timeout
- Throws:
- InterruptedException
 
 - 
shutdownExecutorsprotected boolean shutdownExecutors(Collection<WorkManagerImpl.WorkThreadPoolExecutor> list, long timeout, TimeUnit unit) throws InterruptedException - Throws:
- InterruptedException
 
 - 
remainingMillis@Deprecated protected long remainingMillis(long t0, long delay) Deprecated.since 10.2 because unused
 - 
removeExecutor@Deprecated protected void removeExecutor(String queueId) Deprecated.since 10.2 because unused
 - 
shutdownpublic boolean shutdown(long timeout, TimeUnit unit) throws InterruptedExceptionDescription copied from interface:WorkManagerShuts down thisWorkManagerand attempts to suspend and save the running and scheduled work instances.- Specified by:
- shutdownin interface- WorkManager
- Parameters:
- timeout- the time to wait
- unit- the timeout unit
- Returns:
- trueif shutdown is done,- falseif there are still some threads executing after the timeout
- Throws:
- InterruptedException
 
 - 
schedulepublic void schedule(Work work) Description copied from interface:WorkManagerSchedules work for execution at a later time.This method is identical to WorkManager.schedule(Work, boolean)withafterCommit = false.- Specified by:
- schedulein interface- WorkManager
- Parameters:
- work- the work to execute
 
 - 
schedulepublic void schedule(Work work, boolean afterCommit) Description copied from interface:WorkManagerSchedules work for execution at a later time, after the current transaction (if any) has committed.- Specified by:
- schedulein interface- WorkManager
- Parameters:
- work- the work to execute
- afterCommit- if- trueand the work is scheduled, it will only be run after the current transaction (if any) has committed
 
 - 
schedulepublic void schedule(Work work, WorkManager.Scheduling scheduling) Description copied from interface:WorkManagerSchedules work for execution at a later time, with a specific scheduling policy.This method is identical to WorkManager.schedule(Work, Scheduling, boolean)withafterCommit = false.- Specified by:
- schedulein interface- WorkManager
- Parameters:
- work- the work to execute
- scheduling- the scheduling policy
- See Also:
- WorkManager.schedule(Work)
 
 - 
schedulepublic void schedule(Work work, WorkManager.Scheduling scheduling, boolean afterCommit) Description copied from interface:WorkManagerSchedules work for execution at a later time, with a specific scheduling policy.- Specified by:
- schedulein interface- WorkManager
- Parameters:
- work- the work to execute
- scheduling- the scheduling policy
- afterCommit- if- trueand the work is scheduled, it will only be run after the current transaction (if any) has committed
- See Also:
- WorkManager.schedule(Work)
 
 - 
scheduleAfterCommitprotected boolean scheduleAfterCommit(Work work, WorkManager.Scheduling scheduling) Schedule after commit. Returnsfalseif impossible (no transaction or transaction manager).- Since:
- 5.8
 
 - 
findpublic Work find(String workId, Work.State state) Description copied from interface:WorkManagerFinds a work instance.- Specified by:
- findin interface- WorkManager
- Parameters:
- workId- the id of the work to find
- state- the state defining the state to look into,- SCHEDULED,- RUNNING, or- nullfor non-completed
- Returns:
- the found work instance, or nullif not found
 
 - 
hasWorkInStateprotected boolean hasWorkInState(String workId, Work.State state) - Parameters:
- state- SCHEDULED, RUNNING or null for both
 
 - 
getWorkStatepublic Work.State getWorkState(String workId) Description copied from interface:WorkManager- Specified by:
- getWorkStatein interface- WorkManager
- Parameters:
- workId- the id of the work to find
- Returns:
- the work state, or nullif not found
 
 - 
listWorkpublic List<Work> listWork(String queueId, Work.State state) Description copied from interface:WorkManagerLists the work instances in a given queue in a defined state.- Specified by:
- listWorkin interface- WorkManager
- Parameters:
- queueId- the queue id
- state- the state defining the state to look into,- SCHEDULED,- RUNNING, or- nullfor non-completed
- Returns:
- the list of work instances in the given state
 
 - 
listWorkIdspublic List<String> listWorkIds(String queueId, Work.State state) Description copied from interface:WorkManagerLists the work ids in a given queue in a defined state.- Specified by:
- listWorkIdsin interface- WorkManager
- Parameters:
- queueId- the queue id
- state- the state defining the state to look into,- SCHEDULED,- RUNNING, or- nullfor non-completed
- Returns:
- the list of work ids in the given state
 
 - 
getMetricspublic WorkQueueMetrics getMetrics(String queueId) Description copied from interface:WorkManagerGets the metrics for thequeueId- Specified by:
- getMetricsin interface- WorkManager
 
 - 
getQueueSizepublic int getQueueSize(String queueId, Work.State state) Description copied from interface:WorkManagerGets the number of work instances in a given queue in a defined state.- Specified by:
- getQueueSizein interface- WorkManager
- Parameters:
- queueId- the queue id
- state- the state defining the state to look into,- SCHEDULED,- RUNNING, or- nullfor non-completed (- SCHEDULEDor- RUNNING)
- Returns:
- the number of work instances in the given state
 
 - 
awaitCompletionpublic boolean awaitCompletion(long duration, TimeUnit unit) throws InterruptedExceptionDescription copied from interface:WorkManagerWaits for completion of all work.- Specified by:
- awaitCompletionin interface- WorkManager
- Parameters:
- duration- the time to wait
- unit- the timeout unit
- Returns:
- trueif all work completed, or- falseif there is still some non-completed work after the timeout
- Throws:
- InterruptedException
 
 - 
awaitCompletionpublic boolean awaitCompletion(String queueId, long duration, TimeUnit unit) throws InterruptedException Description copied from interface:WorkManagerWaits for completion of work in a given queue.- Specified by:
- awaitCompletionin interface- WorkManager
- Parameters:
- queueId- the queue id
- duration- the time to wait
- unit- the timeout unit
- Returns:
- trueif all work completed in the queue, or- falseif there is still some non-completed work after the timeout
- Throws:
- InterruptedException
 
 - 
getTimestampAfterprotected long getTimestampAfter(long durationInMs) 
 - 
noScheduledOrRunningWorkprotected boolean noScheduledOrRunningWork(String queueId) 
 - 
isStartedpublic boolean isStarted() - Specified by:
- isStartedin interface- WorkManager
- Returns:
- trueif active
- See Also:
- Component.applicationStarted(org.nuxeo.runtime.model.ComponentContext),- WorkManager.init(),- WorkManager.shutdown(long, TimeUnit)
 
 - 
supportsProcessingDisablingpublic boolean supportsProcessingDisabling() - Specified by:
- supportsProcessingDisablingin interface- WorkManager
- Returns:
- true if the implementation supports processing disabling
 
 
- 
 
-