public class MemoryWorkQueuing extends Object implements WorkQueuing
WorkQueuing
using in-memory queuing.Modifier and Type | Field and Description |
---|---|
protected Map<String,Map<String,Work>> |
allCompleted |
protected Map<String,BlockingQueue<Runnable>> |
allQueued |
protected Map<String,Map<String,Work>> |
allRunning |
protected Map<String,Map<String,Work>> |
allScheduled |
protected WorkManagerImpl |
mgr |
protected WorkQueueDescriptorRegistry |
workQueueDescriptors |
Constructor and Description |
---|
MemoryWorkQueuing(WorkManagerImpl mgr,
WorkQueueDescriptorRegistry workQueueDescriptors) |
Modifier and Type | Method and Description |
---|---|
void |
clearCompletedWork(String queueId,
long completionTime)
Clears the list of completed work instances older than the given time in the given queue.
|
int |
count(String queueId,
Work.State state)
Gets the number of work instances in the given state in a given queue.
|
Work |
find(String workId,
Work.State state)
Finds a work instance in the scheduled or running or completed sets.
|
protected Work |
findCompleted(String workId) |
protected Work |
findRunning(String workId) |
protected Work |
findScheduled(String workId) |
protected Map<String,Work> |
getCompleted(String queueId) |
Set<String> |
getCompletedQueueIds()
Finds which queues have completed work.
|
protected int |
getCompletedSize(String queueId) |
protected WorkQueueDescriptor |
getDescriptor(String queueId) |
protected Map<String,Work> |
getRunning(String queueId) |
protected int |
getRunningSize(String queueId) |
protected Map<String,Work> |
getScheduled(String queueId) |
protected int |
getScheduledSize(String queueId) |
BlockingQueue<Runnable> |
getWorkQueue(String queueId) |
Work.State |
getWorkState(String workId)
Gets the state in which a work instance is.
|
void |
init()
Starts up this
WorkQueuing and attempts to resume work previously suspended and saved at
shutdown time. |
BlockingQueue<Runnable> |
initWorkQueue(String queueId)
Creates a blocking queue of work used by the
ThreadPoolExecutor . |
protected boolean |
isCompleted(String workId) |
protected boolean |
isRunning(String workId) |
protected boolean |
isScheduled(String workId) |
boolean |
isWorkInState(String workId,
Work.State state)
Checks if a work instance with the given id is in the given state.
|
protected List<Work> |
listCompleted(String queueId) |
protected List<String> |
listCompletedIds(String queueId) |
protected List<String> |
listNonCompletedIds(String queueId) |
protected List<Work> |
listRunning(String queueId) |
protected List<String> |
listRunningIds(String queueId) |
protected List<Work> |
listScheduled(String queueId) |
protected List<String> |
listScheduledIds(String queueId) |
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 BlockingQueue<Runnable> |
newBlockingQueue(WorkQueueDescriptor workQueueDescriptor) |
protected Map<String,Work> |
newCompletedMap() |
protected Map<String,Work> |
newRunningMap() |
protected Map<String,Work> |
newScheduledMap() |
protected Work |
removeFromScheduledSet(String queueId,
String workId) |
Work |
removeScheduled(String queueId,
String workId)
Finds a scheduled work instance and removes it from the scheduled queue.
|
int |
setSuspending(String queueId)
Notifies this queuing that all work should be suspending.
|
void |
workCompleted(String queueId,
Work work)
Moves a work instance from the running set to the completed set.
|
void |
workRunning(String queueId,
Work work)
Put the work instance into the running set.
|
boolean |
workSchedule(String queueId,
Work work)
Submit a work to the
ThreadPoolExecutor and put it in the scheduled set. |
protected final WorkManagerImpl mgr
protected final WorkQueueDescriptorRegistry workQueueDescriptors
protected final Map<String,BlockingQueue<Runnable>> allQueued
public MemoryWorkQueuing(WorkManagerImpl mgr, WorkQueueDescriptorRegistry workQueueDescriptors)
public void init()
WorkQueuing
WorkQueuing
and attempts to resume work previously suspended and saved at
shutdown time.init
in interface WorkQueuing
protected WorkQueueDescriptor getDescriptor(String queueId)
public BlockingQueue<Runnable> initWorkQueue(String queueId)
WorkQueuing
ThreadPoolExecutor
.initWorkQueue
in interface WorkQueuing
public BlockingQueue<Runnable> getWorkQueue(String queueId)
public boolean workSchedule(String queueId, Work work)
WorkQueuing
ThreadPoolExecutor
and put it in the scheduled set.workSchedule
in interface WorkQueuing
queueId
- the queue idwork
- the work instanceprotected Map<String,Work> getScheduled(String queueId)
protected Map<String,Work> getRunning(String queueId)
protected Map<String,Work> getCompleted(String queueId)
protected BlockingQueue<Runnable> newBlockingQueue(WorkQueueDescriptor workQueueDescriptor)
protected Map<String,Work> newScheduledMap()
protected Map<String,Work> newRunningMap()
protected Map<String,Work> newCompletedMap()
public void workRunning(String queueId, Work work)
WorkQueuing
workRunning
in interface WorkQueuing
queueId
- the queue idwork
- the work instancepublic void workCompleted(String queueId, Work work)
WorkQueuing
workCompleted
in interface WorkQueuing
queueId
- the queue idwork
- the work instancepublic Work find(String workId, Work.State state)
WorkQueuing
find
in interface WorkQueuing
workId
- the id of the work to findstate
- the state defining the state to look into, SCHEDULED
, RUNNING
, COMPLETED
, or null
for SCHEDULED or RUNNINGnull
if not foundpublic boolean isWorkInState(String workId, Work.State state)
WorkQueuing
isWorkInState
in interface WorkQueuing
workId
- the work idstate
- the state, SCHEDULED
, RUNNING
, COMPLETED
, or null
for non-completedtrue
if a work instance with the given id is in the given statepublic Work.State getWorkState(String workId)
WorkQueuing
This can be Work.State.SCHEDULED
, Work.State.RUNNING
, Work.State.COMPLETED
, Work.State.FAILED
, or
Work.State.CANCELED
.
getWorkState
in interface WorkQueuing
workId
- the id of the work to findnull
if not foundpublic List<Work> listWork(String queueId, Work.State state)
WorkQueuing
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 WorkQueuing
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)
WorkQueuing
listWorkIds
in interface WorkQueuing
queueId
- the queue idstate
- the state defining the state to look into, SCHEDULED
, RUNNING
, COMPLETED
, or null
for non-completedpublic int count(String queueId, Work.State state)
WorkQueuing
count
in interface WorkQueuing
queueId
- the queue idstate
- the state, SCHEDULED
, RUNNING
or
COMPLETED
protected int getScheduledSize(String queueId)
protected int getRunningSize(String queueId)
protected int getCompletedSize(String queueId)
protected boolean isScheduled(String workId)
protected boolean isCompleted(String workId)
protected Work findScheduled(String workId)
protected Work findRunning(String workId)
protected Work findCompleted(String workId)
protected List<Work> listScheduled(String queueId)
protected List<Work> listRunning(String queueId)
protected List<Work> listCompleted(String queueId)
protected List<String> listScheduledIds(String queueId)
protected List<String> listRunningIds(String queueId)
protected List<String> listNonCompletedIds(String queueId)
protected List<String> listCompletedIds(String queueId)
public Work removeScheduled(String queueId, String workId)
WorkQueuing
removeScheduled
in interface WorkQueuing
queueId
- the queue idworkId
- the id of the work to findnull
protected Work removeFromScheduledSet(String queueId, String workId)
public int setSuspending(String queueId)
WorkQueuing
setSuspending
in interface WorkQueuing
public Set<String> getCompletedQueueIds()
WorkQueuing
getCompletedQueueIds
in interface WorkQueuing
public void clearCompletedWork(String queueId, long completionTime)
WorkQueuing
clearCompletedWork
in interface WorkQueuing
queueId
- the queue idcompletionTime
- the completion time (milliseconds since epoch) before which completed work instances are
cleared, or 0
for allCopyright © 2016 Nuxeo SA. All rights reserved.