public class MemoryWorkQueuing extends Object implements WorkQueuing
WorkQueuing
using in-memory queuing.WorkQueuing.Listener
Modifier and Type | Field and Description |
---|---|
protected Map<String,MemoryBlockingQueue> |
allQueued |
protected WorkQueuing.Listener |
listener |
Constructor and Description |
---|
MemoryWorkQueuing(WorkQueuing.Listener listener) |
Modifier and Type | Method and Description |
---|---|
long |
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.
|
MemoryBlockingQueue |
getQueue(String queueId)
Gets the blocking queue of work used by the
ThreadPoolExecutor . |
Work.State |
getWorkState(String workId)
Gets the state in which a work instance is.
|
MemoryBlockingQueue |
init(WorkQueueDescriptor config)
Starts up this
WorkQueuing and attempts to resume work previously suspended and saved at shutdown time. |
boolean |
isWorkInState(String workId,
Work.State state)
Checks if a work instance with the given id is in the given state.
|
void |
listen(WorkQueuing.Listener listener)
Set the callback for debugging purpose
|
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.
|
WorkQueueMetrics |
metrics(String queueId)
Returns current metrics of queue identified by the
queueId |
void |
removeScheduled(String queueId,
String workId)
Finds a scheduled work instance and removes it from the scheduled queue.
|
void |
setActive(String queueId,
boolean value)
Enable/disable this
queueId processing |
void |
workCanceled(String queueId,
Work work)
Removes a work instance from scheduled set.
|
void |
workCompleted(String queueId,
Work work)
Moves a work instance from the running set to the completed set.
|
protected static boolean |
workHasState(Work work,
Work.State state)
Returns
true if the given state is not null and matches the state of the given work or if the
state is null and the work's state is either Work.State.SCHEDULED or Work.State.RUNNING ,
false otherwise. |
void |
workReschedule(String queueId,
Work work)
Moves back a work instance from running set to the scheduled set.
|
void |
workRunning(String queueId,
Work work)
Put the work instance into the running set.
|
void |
workSchedule(String queueId,
Work work)
Submit a work to the
ThreadPoolExecutor and put it in the scheduled set. |
protected final Map<String,MemoryBlockingQueue> allQueued
protected WorkQueuing.Listener listener
public MemoryWorkQueuing(WorkQueuing.Listener listener)
public MemoryBlockingQueue init(WorkQueueDescriptor config)
WorkQueuing
WorkQueuing
and attempts to resume work previously suspended and saved at shutdown time.init
in interface WorkQueuing
public MemoryBlockingQueue getQueue(String queueId)
WorkQueuing
ThreadPoolExecutor
.getQueue
in interface WorkQueuing
public void workSchedule(String queueId, Work work)
WorkQueuing
ThreadPoolExecutor
and put it in the scheduled set.workSchedule
in interface WorkQueuing
queueId
- the queue idwork
- the work instancepublic void workCanceled(String queueId, Work work)
WorkQueuing
workCanceled
in interface WorkQueuing
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 void workReschedule(String queueId, Work work)
WorkQueuing
workReschedule
in interface WorkQueuing
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.State getWorkState(String workId)
WorkQueuing
This can be Work.State.SCHEDULED
, Work.State.RUNNING
, State#COMPLETED
, State#FAILED
, or
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
, or null
for non-completedpublic long count(String queueId, Work.State state)
WorkQueuing
count
in interface WorkQueuing
queueId
- the queue idstate
- the state, SCHEDULED
, RUNNING
or
COMPLETED
public void removeScheduled(String queueId, String workId)
WorkQueuing
removeScheduled
in interface WorkQueuing
queueId
- the queue idworkId
- the id of the work to findpublic void setActive(String queueId, boolean value)
WorkQueuing
queueId
processingsetActive
in interface WorkQueuing
public void listen(WorkQueuing.Listener listener)
WorkQueuing
listen
in interface WorkQueuing
public WorkQueueMetrics metrics(String queueId)
WorkQueuing
queueId
metrics
in interface WorkQueuing
protected static boolean workHasState(Work work, Work.State state)
true
if the given state is not null
and matches the state of the given work or if the
state is null
and the work's state is either Work.State.SCHEDULED
or Work.State.RUNNING
,
false
otherwise.Copyright © 2018 Nuxeo. All rights reserved.