Interface WorkQueuing

  • All Known Implementing Classes:
    MemoryWorkQueuing, RedisWorkQueuing

    public interface WorkQueuing
    Interface describing how the WorkManager implements queuing.

    There are 4 structures maintained per-queue:

    • the work queue managed by the ThreadPoolExecutor,
    • the set of scheduled work, this enables to list a work as being scheduled while it has been removed from the queue by the ThreadPoolExecutor and not yet executed (not yet running).
    • the set of running work,
    • the set of completed work.
    Since:
    5.8
    • Method Detail

      • setActive

        void setActive​(String queueId,
                       boolean value)
        Enable/disable this queueId processing
        Since:
        8.3
      • supportsProcessingDisabling

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

        void workSchedule​(String queueId,
                          Work work)
        Submit a work to the ThreadPoolExecutor and put it in the scheduled set.
        Parameters:
        queueId - the queue id
        work - the work instance
        Since:
        8.1
      • workCanceled

        void workCanceled​(String queueId,
                          Work work)
        Removes a work instance from scheduled set.
        Since:
        8.3
      • workRunning

        void workRunning​(String queueId,
                         Work work)
        Put the work instance into the running set.
        Parameters:
        queueId - the queue id
        work - the work instance
        Since:
        5.8
      • workCompleted

        void workCompleted​(String queueId,
                           Work work)
        Moves a work instance from the running set to the completed set.
        Parameters:
        queueId - the queue id
        work - the work instance
        Since:
        5.8
      • workReschedule

        void workReschedule​(String queueId,
                            Work work)
        Moves back a work instance from running set to the scheduled set.
        Since:
        8.3
      • find

        Work find​(String workId,
                  Work.State state)
        Finds a work instance in the scheduled or running or completed sets.
        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
      • removeScheduled

        void removeScheduled​(String queueId,
                             String workId)
        Finds a scheduled work instance and removes it from the scheduled queue.
        Parameters:
        queueId - the queue id
        workId - the id of the work to find
        Since:
        5.8
      • isWorkInState

        boolean isWorkInState​(String workId,
                              Work.State state)
        Checks if a work instance with the given id is in the given state.
        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
        Since:
        5.8
      • listWork

        List<Work> listWork​(String queueId,
                            Work.State state)
        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.

        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

        List<String> listWorkIds​(String queueId,
                                 Work.State state)
        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
      • count

        long count​(String queueId,
                   Work.State state)
        Gets the number of work instances in the given state in a given queue.
        Parameters:
        queueId - the queue id
        state - the state, SCHEDULED or RUNNING
        Returns:
        the number of scheduled work instances in the queue
        Since:
        5.8
      • metrics

        WorkQueueMetrics metrics​(String queueId)
        Returns current metrics of queue identified by the queueId
        Since:
        8.3
      • listen

        void listen​(WorkQueuing.Listener listener)
        Set the callback for debugging purpose
        Since:
        8.3