Class MemoryWorkQueuing

java.lang.Object
org.nuxeo.ecm.core.work.MemoryWorkQueuing
All Implemented Interfaces:
WorkQueuing

public class MemoryWorkQueuing extends Object implements WorkQueuing
Implementation of a WorkQueuing using in-memory queuing.
Since:
5.8
  • Field Details

  • Constructor Details

  • Method Details

    • init

      Description copied from interface: WorkQueuing
      Starts up this WorkQueuing and attempts to resume work previously suspended and saved at shutdown time.
      Specified by:
      init in interface WorkQueuing
    • getQueue

      public MemoryBlockingQueue getQueue(String queueId)
      Description copied from interface: WorkQueuing
      Gets the blocking queue of work used by the ThreadPoolExecutor.
      Specified by:
      getQueue in interface WorkQueuing
    • workSchedule

      public void workSchedule(String queueId, Work work)
      Description copied from interface: WorkQueuing
      Submit a work to the ThreadPoolExecutor and put it in the scheduled set.
      Specified by:
      workSchedule in interface WorkQueuing
      Parameters:
      queueId - the queue id
      work - 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 interface WorkQueuing
    • 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 interface WorkQueuing
      Parameters:
      queueId - the queue id
      work - 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 interface WorkQueuing
      Parameters:
      queueId - the queue id
      work - 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 interface WorkQueuing
    • 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 interface WorkQueuing
      Parameters:
      workId - the id of the work to find
      state - the state defining the state to look into, SCHEDULED, RUNNING, or null 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 interface WorkQueuing
      Parameters:
      workId - the work id
      state - the state, SCHEDULED, RUNNING, or null 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 or Work.State.RUNNING.

      Specified by:
      getWorkState in interface WorkQueuing
      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 interface WorkQueuing
      Parameters:
      queueId - the queue id
      state - the state defining the state to look into, SCHEDULED, RUNNING, or null 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 interface WorkQueuing
      Parameters:
      queueId - the queue id
      state - the state defining the state to look into, SCHEDULED, RUNNING, or null 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 interface WorkQueuing
      Parameters:
      queueId - the queue id
      state - the state, SCHEDULED or RUNNING
      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 interface WorkQueuing
      Parameters:
      queueId - the queue id
      workId - the id of the work to find
    • setActive

      public void setActive(String queueId, boolean value)
      Description copied from interface: WorkQueuing
      Enable/disable this queueId processing
      Specified by:
      setActive in interface WorkQueuing
    • listen

      public void listen(WorkQueuing.Listener listener)
      Description copied from interface: WorkQueuing
      Set the callback for debugging purpose
      Specified by:
      listen in interface WorkQueuing
    • metrics

      public WorkQueueMetrics metrics(String queueId)
      Description copied from interface: WorkQueuing
      Returns current metrics of queue identified by the queueId
      Specified by:
      metrics in interface WorkQueuing
    • workHasState

      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.
      Since:
      9.3
    • supportsProcessingDisabling

      public boolean supportsProcessingDisabling()
      Specified by:
      supportsProcessingDisabling in interface WorkQueuing
      Returns:
      true if the implementation supports processing disabling