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.
|
protected class |
WorkManagerImpl.ShutdownListener |
class |
WorkManagerImpl.WorkCompletionSynchronizer |
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 |
started |
protected static String |
THREAD_PREFIX |
protected WorkQueueDescriptorRegistry |
workQueueDescriptors |
lastModified
Constructor and Description |
---|
WorkManagerImpl() |
Modifier and Type | Method and Description |
---|---|
void |
activate(ComponentContext context)
Activates the component.
|
protected void |
activateQueue(WorkQueueDescriptor workQueueDescriptor) |
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.
|
protected void |
closeQueuing() |
void |
deactivateQueue(WorkQueueDescriptor workQueueDescriptor) |
Work |
find(String workId,
Work.State state)
Finds a work instance.
|
Work |
find(Work work,
Work.State state,
boolean useEquals,
int[] pos)
Deprecated.
|
String |
findResult(String workId)
Finds a work result.
|
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 int |
getCompletedSize(String queueId) |
protected WorkManagerImpl.WorkThreadPoolExecutor |
getExecutor(String queueId) |
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.
|
protected int |
getRunningSize(String queueId) |
protected int |
getScheduledOrRunningSize(String queueId) |
protected int |
getScheduledSize(String queueId) |
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. |
protected boolean |
isProcessingEnabled(String queueId) |
protected boolean |
isQueuingEnabled(String queueId) |
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) |
void |
registerContribution(Object contribution,
String extensionPoint,
ComponentInstance contributor) |
void |
registerWorkQueueDescriptor(WorkQueueDescriptor workQueueDescriptor) |
void |
registerWorkQueuing(WorkQueuing q) |
void |
registerWorkQueuingDescriptor(WorkQueuingImplDescriptor descr) |
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 |
unregisterContribution(Object contribution,
String extensionPoint,
ComponentInstance contributor) |
void |
unregisterWorkQueing() |
void |
unregisterWorkQueueDescriptor(WorkQueueDescriptor workQueueDescriptor) |
void |
unregisterWorkQueuingDescriptor(WorkQueuingImplDescriptor descr) |
deactivate, getAdapter, getLastModified, registerExtension, setLastModified, setModifiedNow, unregisterExtension
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 WorkQueueDescriptorRegistry workQueueDescriptors
protected final Map<String,WorkManagerImpl.WorkThreadPoolExecutor> executors
protected final WorkManagerImpl.WorkCompletionSynchronizer completionSynchronizer
protected WorkQueuing queuing
protected volatile boolean started
public WorkManagerImpl()
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 registerWorkQueueDescriptor(WorkQueueDescriptor workQueueDescriptor)
public void unregisterWorkQueueDescriptor(WorkQueueDescriptor workQueueDescriptor)
protected void activateQueue(WorkQueueDescriptor workQueueDescriptor)
public void deactivateQueue(WorkQueueDescriptor workQueueDescriptor)
public void registerWorkQueuingDescriptor(WorkQueuingImplDescriptor descr)
public void registerWorkQueuing(WorkQueuing q)
public void unregisterWorkQueuingDescriptor(WorkQueuingImplDescriptor descr)
public void unregisterWorkQueing()
protected WorkQueuing newWorkQueuing(Class<? extends WorkQueuing> klass)
protected void closeQueuing()
protected boolean isQueuingEnabled(String queueId)
protected boolean isProcessingEnabled(String queueId)
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
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).@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 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
, COMPLETED
, or null
for non-completednull
if not foundpublic String findResult(String workId)
WorkManager
findResult
in interface WorkManager
workId
- the id of the work to find the resultnull
if there is no result or if work is not COMPLETED
protected boolean hasWorkInState(String workId, Work.State state)
state
- SCHEDULED, RUNNING or null for bothpublic 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 idprotected int getScheduledSize(String queueId)
protected int getRunningSize(String queueId)
protected int getScheduledOrRunningSize(String queueId)
protected int getCompletedSize(String queueId)
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
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.