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 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 |
protected boolean |
shutdownInProgress |
protected boolean |
started |
protected static String |
THREAD_PREFIX |
protected WorkQueueRegistry |
workQueueConfig |
protected WorkQueuingRegistry |
workQueuingConfig |
lastModified
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) |
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 WorkQueuing |
newWorkQueuing(Class<? extends WorkQueuing> klass) |
protected boolean |
noScheduledOrRunningWork(String queueId) |
void |
registerContribution(Object contribution,
String extensionPoint,
ComponentInstance contributor) |
protected long |
remainingMillis(long t0,
long delay) |
protected void |
removeExecutor(String queueId) |
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.
|
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.
|
void |
stop(ComponentContext context)
Stop the component.
|
void |
unregisterContribution(Object contribution,
String extensionPoint,
ComponentInstance contributor) |
activate, deactivate, getAdapter, getLastModified, registerExtension, setLastModified, setModifiedNow, unregisterExtension
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
applicationStarted
public 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
protected final com.codahale.metrics.MetricRegistry registry
protected final WorkQueueRegistry workQueueConfig
protected final WorkQueuingRegistry workQueuingConfig
protected final Map<String,WorkManagerImpl.WorkThreadPoolExecutor> executors
protected WorkQueuing queuing
protected WorkManagerImpl.WorkCompletionSynchronizer completionSynchronizer
protected volatile boolean started
protected volatile boolean shutdownInProgress
public WorkManagerImpl()
public 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
protected WorkQueuing newWorkQueuing(Class<? extends WorkQueuing> klass)
public boolean isQueuingEnabled(String queueId)
WorkManager
isQueuingEnabled
in interface WorkManager
public void enableProcessing(boolean value)
WorkManager
enableProcessing
in interface WorkManager
public void enableProcessing(String queueId, boolean value)
WorkManager
enableProcessing
in interface WorkManager
public boolean isProcessingEnabled()
WorkManager
isProcessingEnabled
in interface WorkManager
public boolean isProcessingEnabled(String queueId)
WorkManager
isProcessingEnabled
in interface WorkManager
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
public void start(ComponentContext context)
Component
start
in interface Component
start
in class DefaultComponent
public void stop(ComponentContext context) throws InterruptedException
Component
stop
in interface Component
stop
in class DefaultComponent
InterruptedException
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
protected WorkManagerImpl.WorkThreadPoolExecutor getExecutor(String queueId)
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
protected boolean shutdownExecutors(Collection<WorkManagerImpl.WorkThreadPoolExecutor> list, long timeout, TimeUnit unit) throws InterruptedException
InterruptedException
protected long remainingMillis(long t0, long delay)
protected void removeExecutor(String queueId)
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)
protected boolean scheduleAfterCommit(Work work, WorkManager.Scheduling scheduling)
false
if impossible (no transaction or transaction manager).public Work find(String workId, Work.State state)
WorkManager
find
in interface WorkManager
workId
- 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)
WorkManager
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
, 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
, or null
for non-completedpublic WorkQueueMetrics getMetrics(String queueId)
WorkManager
queueId
getMetrics
in interface WorkManager
public 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
)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 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
protected long getTimestampAfter(long durationInMs)
protected boolean noScheduledOrRunningWork(String queueId)
public boolean isStarted()
isStarted
in interface WorkManager
true
if activeComponent.applicationStarted(org.nuxeo.runtime.model.ComponentContext)
,
WorkManager.init()
,
WorkManager.shutdown(long, TimeUnit)
Copyright © 2018 Nuxeo. All rights reserved.