public class WorkManagerImpl extends DefaultComponent implements WorkManager
WorkManager
.Modifier and Type | Class and Description |
---|---|
static class |
WorkManagerImpl.NamedThreadFactory
Creates non-daemon threads at normal priority.
|
static class |
WorkManagerImpl.SuspendPolicy
A handler for rejected tasks that suspends them.
|
static class |
WorkManagerImpl.WorkThreadPoolExecutor
A
ThreadPoolExecutor that keeps available the list of scheduled,
running and completed tasks and provides other methods. |
WorkManager.Scheduling
Modifier and Type | Field and Description |
---|---|
static String |
DEFAULT_CATEGORY |
static String |
DEFAULT_QUEUE_ID |
Constructor and Description |
---|
WorkManagerImpl() |
Modifier and Type | Method and Description |
---|---|
void |
activate(ComponentContext context)
Activates the component.
|
boolean |
awaitCompletion(long timeout,
TimeUnit unit)
Waits for completion of all work.
|
boolean |
awaitCompletion(String queueId,
long timeout,
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 |
deactivate(ComponentContext context)
Deactivates the component.
|
Work |
find(Work work,
Work.State state,
boolean useEquals,
int[] pos)
Finds a work instance by equality or identity.
|
String |
getCategoryQueueId(String category)
Gets the queue id used for a given work category.
|
int |
getNonCompletedWorkSize(String queueId)
Gets the size of the non-completed work (scheduled + running) for a give
queue.
|
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.
|
void |
init()
Starts up this
WorkManager and attempts to resume work previously
suspended and saved at WorkManager.shutdown(long, java.util.concurrent.TimeUnit) time. |
List<Work> |
listWork(String queueId,
Work.State state)
Lists the work instances in a given queue in a defined state.
|
void |
registerContribution(Object contribution,
String extensionPoint,
ComponentInstance contributor) |
void |
schedule(Work work)
Schedules work for execution at a later time.
|
void |
schedule(Work work,
WorkManager.Scheduling scheduling)
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) |
applicationStarted, getAdapter, getApplicationStartedOrder, getLastModified, registerExtension, setLastModified, unregisterExtension
public static final String DEFAULT_QUEUE_ID
public static final String DEFAULT_CATEGORY
public void activate(ComponentContext context) throws Exception
Component
This method is called by the runtime when a component is activated.
activate
in interface Component
activate
in class DefaultComponent
context
- the runtime contextException
- if an error occurs during activationpublic void deactivate(ComponentContext context) throws Exception
Component
This method is called by the runtime when a component is deactivated.
deactivate
in interface Component
deactivate
in class DefaultComponent
context
- the runtime contextException
- if an error occurs during activationpublic void registerContribution(Object contribution, String extensionPoint, ComponentInstance contributor) throws Exception
registerContribution
in class DefaultComponent
Exception
public void unregisterContribution(Object contribution, String extensionPoint, ComponentInstance contributor) throws Exception
unregisterContribution
in class DefaultComponent
Exception
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 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
schedule
in interface WorkManager
work
- the work to executepublic void schedule(Work work, WorkManager.Scheduling scheduling)
WorkManager
schedule
in interface WorkManager
work
- the work to executescheduling
- the scheduling policyWorkManager.schedule(Work)
public Work find(Work work, Work.State state, boolean useEquals, int[] pos)
WorkManager
Note that an instance requested as RUNNING could be found SUSPENDING or SUSPENDED, and an instance requested as COMPLETED could be found FAILED.
Also, due to the asynchronous nature of work execution, the state of the work could be different than what's expected if the work started or finished in the middle of the call.
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
- if true
then use Work#equals
to find the
work instance, otherwise use object identitypos
- a 1-element array to return the position in the internal queuenull
if not foundpublic List<Work> listWork(String queueId, Work.State state)
WorkManager
Note that an instance requested as RUNNING could be found SUSPENDING or SUSPENDED, and an instance requested as COMPLETED could be found FAILED.
listWork
in interface WorkManager
queueId
- the queue idstate
- the state defining the state to look into,
SCHEDULED
, RUNNING
, COMPLETED
, or null
for non-completedpublic int getNonCompletedWorkSize(String queueId)
WorkManager
getNonCompletedWorkSize
in interface WorkManager
queueId
- the queue idpublic boolean awaitCompletion(String queueId, long timeout, TimeUnit unit) throws InterruptedException
WorkManager
awaitCompletion
in interface WorkManager
queueId
- the queue idtimeout
- 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 timeout, TimeUnit unit) throws InterruptedException
WorkManager
awaitCompletion
in interface WorkManager
timeout
- 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
Copyright © 2012 Nuxeo SA. All Rights Reserved.