Interface WorkManager

All Known Implementing Classes:
StreamWorkManager, WorkManagerImpl

public interface WorkManager
A WorkManager executes Work instances asynchronously.

A Work can be scheduled by calling schedule(org.nuxeo.ecm.core.work.api.Work).

Work is executed in a thread pool and a work queue that depends on the work's category.

Since:
5.6
  • Method Details

    • schedule

      void schedule(Work work)
      Schedules work for execution at a later time.

      This method is identical to schedule(Work, boolean) with afterCommit = false.

      Parameters:
      work - the work to execute
    • schedule

      void schedule(Work work, boolean afterCommit)
      Schedules work for execution at a later time, after the current transaction (if any) has committed.
      Parameters:
      work - the work to execute
      afterCommit - if true and the work is scheduled, it will only be run after the current transaction (if any) has committed
    • schedule

      void schedule(Work work, WorkManager.Scheduling scheduling)
      Schedules work for execution at a later time, with a specific scheduling policy.

      This method is identical to schedule(Work, Scheduling, boolean) with afterCommit = false.

      Parameters:
      work - the work to execute
      scheduling - the scheduling policy
      See Also:
    • schedule

      void schedule(Work work, WorkManager.Scheduling scheduling, boolean afterCommit)
      Schedules work for execution at a later time, with a specific scheduling policy.
      Parameters:
      work - the work to execute
      scheduling - the scheduling policy
      afterCommit - if true and the work is scheduled, it will only be run after the current transaction (if any) has committed
      See Also:
    • getWorkQueueIds

      List<String> getWorkQueueIds()
      Lists the ids of the existing work queues.
      Returns:
      the list of queue ids
    • getCategoryQueueId

      String getCategoryQueueId(String category)
      Gets the queue id used for a given work category.
      Parameters:
      category - the category
      Returns:
      the queue id
    • getWorkQueueDescriptor

      WorkQueueDescriptor getWorkQueueDescriptor(String queueId)
      Gets the work queue descriptor for a given queue id.
      Parameters:
      queueId - the queue id
      Returns:
      the work queue descriptor, or null
    • isProcessingEnabled

      boolean isProcessingEnabled()
      Is processing enabled for at least one queue
      Since:
      8.3
    • supportsProcessingDisabling

      boolean supportsProcessingDisabling()
      Returns:
      true if the implementation supports processing disabling
      Since:
      10.3
    • enableProcessing

      void enableProcessing(boolean value)
      Set processing for all queues
      Since:
      8.3
    • isProcessingEnabled

      boolean isProcessingEnabled(String queueId)
      Is processing enabled for a given queue id.
      Since:
      8.3
    • enableProcessing

      void enableProcessing(String queueId, boolean value)
      Set processing for a given queue id.
      Since:
      8.3
    • isQueuingEnabled

      boolean isQueuingEnabled(String queueId)
      Is queuing enabled for a given queue id.
      Since:
      8.3
    • init

      void init()
      Starts up this WorkManager and attempts to resume work previously suspended and saved at shutdown(long, java.util.concurrent.TimeUnit) time.
    • shutdownQueue

      boolean shutdownQueue(String queueId, long timeout, TimeUnit unit) throws InterruptedException
      Shuts down a work queue and attempts to suspend and save the running and scheduled work instances.
      Parameters:
      queueId - the queue id
      timeout - the time to wait
      unit - the timeout unit
      Returns:
      true if shutdown is done, false if there are still some threads executing after the timeout
      Throws:
      InterruptedException
    • shutdown

      boolean shutdown(long timeout, TimeUnit unit) throws InterruptedException
      Shuts down this WorkManager and attempts to suspend and save the running and scheduled work instances.
      Parameters:
      timeout - the time to wait
      unit - the timeout unit
      Returns:
      true if shutdown is done, false if there are still some threads executing after the timeout
      Throws:
      InterruptedException
    • getMetrics

      WorkQueueMetrics getMetrics(String queueId)
      Gets the metrics for the queueId
      Since:
      8.3
    • awaitCompletion

      boolean awaitCompletion(String queueId, long timeout, TimeUnit unit) throws InterruptedException
      Waits for completion of work in a given queue.
      Parameters:
      queueId - the queue id
      timeout - the time to wait
      unit - the timeout unit
      Returns:
      true if all work completed in the queue, or false if there is still some non-completed work after the timeout
      Throws:
      InterruptedException
    • awaitCompletion

      boolean awaitCompletion(long timeout, TimeUnit unit) throws InterruptedException
      Waits for completion of all work.
      Parameters:
      timeout - the time to wait
      unit - the timeout unit
      Returns:
      true if all work completed, or false if there is still some non-completed work after the timeout
      Throws:
      InterruptedException
    • isStarted

      boolean isStarted()
      Returns:
      true if active
      Since:
      6.0
      See Also:
    • getWorkState

      @Deprecated Work.State getWorkState(String workId)
      Deprecated.
      Gets the state in which a work instance is.

      This can be SCHEDULED, RUNNING, or null.

      Parameters:
      workId - the id of the work to find
      Returns:
      the work state, or null if not found
      Since:
      5.8
    • find

      @Deprecated Work find(String workId, Work.State state)
      Deprecated.
      since 10.2 not scalable
      Finds a work instance.
      Parameters:
      workId - the id of the work to find
      state - the state defining the state to look into, SCHEDULED, RUNNING, or null for non-completed
      Returns:
      the found work instance, or null if not found
      Since:
      7.3
    • listWork

      @Deprecated List<Work> listWork(String queueId, Work.State state)
      Deprecated.
      since 10.2 not scalable
      Lists the work instances in a given queue in a defined state.
      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

      @Deprecated List<String> listWorkIds(String queueId, Work.State state)
      Deprecated.
      since 10.2 not scalable
      Lists the work ids in a given queue in a defined state.
      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
      Since:
      5.8