Package org.nuxeo.ecm.core.work
Class MemoryWorkQueuing
- java.lang.Object
-
- org.nuxeo.ecm.core.work.MemoryWorkQueuing
-
- All Implemented Interfaces:
WorkQueuing
public class MemoryWorkQueuing extends Object implements WorkQueuing
Implementation of aWorkQueuing
using in-memory queuing.- Since:
- 5.8
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.nuxeo.ecm.core.work.WorkQueuing
WorkQueuing.Listener
-
-
Field Summary
Fields Modifier and Type Field Description protected Map<String,MemoryBlockingQueue>
allQueued
protected WorkQueuing.Listener
listener
-
Constructor Summary
Constructors Constructor Description MemoryWorkQueuing(WorkQueuing.Listener listener)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method 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 theThreadPoolExecutor
.Work.State
getWorkState(String workId)
Gets the state in which a work instance is.MemoryBlockingQueue
init(WorkQueueDescriptor config)
Starts up thisWorkQueuing
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 purposeList<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 thequeueId
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 thisqueueId
processingboolean
supportsProcessingDisabling()
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)
Returnstrue
if the given state is notnull
and matches the state of the given work or if the state isnull
and the work's state is eitherWork.State.SCHEDULED
orWork.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 theThreadPoolExecutor
and put it in the scheduled set.
-
-
-
Field Detail
-
allQueued
protected final Map<String,MemoryBlockingQueue> allQueued
-
listener
protected WorkQueuing.Listener listener
-
-
Constructor Detail
-
MemoryWorkQueuing
public MemoryWorkQueuing(WorkQueuing.Listener listener)
-
-
Method Detail
-
init
public MemoryBlockingQueue init(WorkQueueDescriptor config)
Description copied from interface:WorkQueuing
Starts up thisWorkQueuing
and attempts to resume work previously suspended and saved at shutdown time.- Specified by:
init
in interfaceWorkQueuing
-
getQueue
public MemoryBlockingQueue getQueue(String queueId)
Description copied from interface:WorkQueuing
Gets the blocking queue of work used by theThreadPoolExecutor
.- Specified by:
getQueue
in interfaceWorkQueuing
-
workSchedule
public void workSchedule(String queueId, Work work)
Description copied from interface:WorkQueuing
Submit a work to theThreadPoolExecutor
and put it in the scheduled set.- Specified by:
workSchedule
in interfaceWorkQueuing
- Parameters:
queueId
- the queue idwork
- the work instance
-
workCanceled
public void workCanceled(String queueId, Work work)
Description copied from interface:WorkQueuing
Removes a work instance from scheduled set.- Specified by:
workCanceled
in interfaceWorkQueuing
-
workRunning
public void workRunning(String queueId, Work work)
Description copied from interface:WorkQueuing
Put the work instance into the running set.- Specified by:
workRunning
in interfaceWorkQueuing
- Parameters:
queueId
- the queue idwork
- the work instance
-
workCompleted
public void workCompleted(String queueId, Work work)
Description copied from interface:WorkQueuing
Moves a work instance from the running set to the completed set.- Specified by:
workCompleted
in interfaceWorkQueuing
- Parameters:
queueId
- the queue idwork
- the work instance
-
workReschedule
public void workReschedule(String queueId, Work work)
Description copied from interface:WorkQueuing
Moves back a work instance from running set to the scheduled set.- Specified by:
workReschedule
in interfaceWorkQueuing
-
find
public Work find(String workId, Work.State state)
Description copied from interface:WorkQueuing
Finds a work instance in the scheduled or running or completed sets.- Specified by:
find
in interfaceWorkQueuing
- Parameters:
workId
- the id of the work to findstate
- the state defining the state to look into,SCHEDULED
,RUNNING
, ornull
for SCHEDULED or RUNNING- Returns:
- the found work instance, or
null
if not found
-
isWorkInState
public boolean isWorkInState(String workId, Work.State state)
Description copied from interface:WorkQueuing
Checks if a work instance with the given id is in the given state.- Specified by:
isWorkInState
in interfaceWorkQueuing
- Parameters:
workId
- the work idstate
- the state,SCHEDULED
,RUNNING
, ornull
for non-completed- Returns:
true
if a work instance with the given id is in the given state
-
getWorkState
public Work.State getWorkState(String workId)
Description copied from interface:WorkQueuing
Gets the state in which a work instance is.This can be
Work.State.SCHEDULED
orWork.State.RUNNING
.- Specified by:
getWorkState
in interfaceWorkQueuing
- Parameters:
workId
- the id of the work to find- Returns:
- the work state, or
null
if not found
-
listWork
public List<Work> listWork(String queueId, Work.State state)
Description copied from interface:WorkQueuing
Lists the work instances in a given queue in a defined state.Note that an instance requested as RUNNING could be found SUSPENDING or SUSPENDED, and an instance requested as COMPLETED could be found FAILED.
- Specified by:
listWork
in interfaceWorkQueuing
- Parameters:
queueId
- the queue idstate
- the state defining the state to look into,SCHEDULED
,RUNNING
, ornull
for non-completed- Returns:
- the list of work instances in the given state
-
listWorkIds
public List<String> listWorkIds(String queueId, Work.State state)
Description copied from interface:WorkQueuing
Lists the work ids in a given queue in a defined state.- Specified by:
listWorkIds
in interfaceWorkQueuing
- Parameters:
queueId
- the queue idstate
- the state defining the state to look into,SCHEDULED
,RUNNING
, ornull
for non-completed- Returns:
- the list of work ids in the given state
-
count
public long count(String queueId, Work.State state)
Description copied from interface:WorkQueuing
Gets the number of work instances in the given state in a given queue.- Specified by:
count
in interfaceWorkQueuing
- Parameters:
queueId
- the queue idstate
- the state,SCHEDULED
orRUNNING
- Returns:
- the number of scheduled work instances in the queue
-
removeScheduled
public void removeScheduled(String queueId, String workId)
Description copied from interface:WorkQueuing
Finds a scheduled work instance and removes it from the scheduled queue.- Specified by:
removeScheduled
in interfaceWorkQueuing
- Parameters:
queueId
- the queue idworkId
- the id of the work to find
-
setActive
public void setActive(String queueId, boolean value)
Description copied from interface:WorkQueuing
Enable/disable thisqueueId
processing- Specified by:
setActive
in interfaceWorkQueuing
-
listen
public void listen(WorkQueuing.Listener listener)
Description copied from interface:WorkQueuing
Set the callback for debugging purpose- Specified by:
listen
in interfaceWorkQueuing
-
metrics
public WorkQueueMetrics metrics(String queueId)
Description copied from interface:WorkQueuing
Returns current metrics of queue identified by thequeueId
- Specified by:
metrics
in interfaceWorkQueuing
-
workHasState
protected static boolean workHasState(Work work, Work.State state)
Returnstrue
if the given state is notnull
and matches the state of the given work or if the state isnull
and the work's state is eitherWork.State.SCHEDULED
orWork.State.RUNNING
,false
otherwise.- Since:
- 9.3
-
supportsProcessingDisabling
public boolean supportsProcessingDisabling()
- Specified by:
supportsProcessingDisabling
in interfaceWorkQueuing
- Returns:
- true if the implementation supports processing disabling
-
-