public class RedisWorkQueuing extends Object implements WorkQueuing
WorkQueuing
storing Work
instances in Redis.Constructor and Description |
---|
RedisWorkQueuing(WorkManagerImpl mgr,
WorkQueueDescriptorRegistry workQueueDescriptors) |
Modifier and Type | Method and Description |
---|---|
void |
addScheduledWork(String queueId,
Work work)
Persists a work instance and adds it to the scheduled queue.
|
void |
clearCompletedWork(String queueId,
long completionTime)
Clears the list of completed work instances older than the given time in the given queue.
|
Work |
find(String workId,
Work.State state)
Finds a work instance in the scheduled queue or running or completed sets.
|
Set<String> |
getCompletedQueueIds()
Finds which queues have completed work.
|
int |
getQueueSize(String queueId,
Work.State state)
Gets the number of work instances in the given state in a given queue.
|
BlockingQueue<Runnable> |
getScheduledQueue(String queueId)
Gets the blocking queue for scheduled work, to be used in a
ThreadPoolExecutor . |
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> |
initScheduleQueue(String queueId) |
boolean |
isWorkInState(String workId,
Work.State state)
Checks if a work instance with the given id is in the given state.
|
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.
|
Work |
removeScheduled(String queueId,
String workId)
Finds a scheduled work instance and removes it from the scheduled work.
|
int |
scheduleSuspendedWork(String queueId)
Resumes all suspended work instances by moving them to the scheduled queue.
|
int |
setSuspending(String queueId)
Notifies this queuing that all work should be suspending.
|
int |
suspendScheduledWork(String queueId)
Suspends all scheduled work instances by moving them to the suspended queue.
|
void |
workCompleted(String queueId,
Work work)
Moves a work instance from the running set to the completed set.
|
void |
workRunning(String queueId,
Work work)
Moves a work instance from the scheduled queue to the running set.
|
public RedisWorkQueuing(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
public BlockingQueue<Runnable> initScheduleQueue(String queueId)
initScheduleQueue
in interface WorkQueuing
public BlockingQueue<Runnable> getScheduledQueue(String queueId)
WorkQueuing
ThreadPoolExecutor
.getScheduledQueue
in interface WorkQueuing
queueId
- the queue idpublic 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 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 getQueueSize(String queueId, Work.State state)
WorkQueuing
getQueueSize
in interface WorkQueuing
queueId
- the queue idstate
- the state, SCHEDULED
, RUNNING
or
COMPLETED
public 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 removeScheduled(String queueId, String workId)
WorkQueuing
removeScheduled
in interface WorkQueuing
queueId
- the queue idworkId
- the id of the work to findnull
public 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 int setSuspending(String queueId)
WorkQueuing
setSuspending
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 allpublic void addScheduledWork(String queueId, Work work) throws IOException
queueId
- the queue idwork
- the work instanceIOException
public Set<String> getCompletedQueueIds()
WorkQueuing
getCompletedQueueIds
in interface WorkQueuing
public int scheduleSuspendedWork(String queueId) throws IOException
queueId
- the queue idIOException
public int suspendScheduledWork(String queueId) throws IOException
queueId
- the queue idIOException
Copyright © 2015 Nuxeo SA. All rights reserved.