Class QueuedTasksProcessor<T>

  • Type Parameters:
    T -

    public class QueuedTasksProcessor<T>
    extends Object
    This class can be used to process data in some queue asynchronously without occupying many threads. Processing is always performed in a single thread which is allocated from the executor specified in constructor.
    Since:
    2018.2.3
    • Constructor Detail

      • QueuedTasksProcessor

        public QueuedTasksProcessor​(@NotNull
                                    QueuedTasksProcessor.ManyTasksProcessor<T> tasksProcessor,
                                    @NotNull
                                    ExecutorService executor,
                                    int queueSize,
                                    int maxTasksToHandle,
                                    @NotNull
                                    String name)
        Parameters:
        tasksProcessor - processor which can handle several tasks at once
        executor -
        queueSize -
        maxTasksToHandle - max tasks to take from the queue and pass to processor at once
        name -
      • QueuedTasksProcessor

        public QueuedTasksProcessor​(@NotNull
                                    QueuedTasksProcessor.ManyTasksProcessor<T> tasksProcessor,
                                    @NotNull
                                    ExecutorService executor,
                                    @NotNull
                                    BlockingQueue<T> queue,
                                    int maxTasksToHandle,
                                    @NotNull
                                    String name)
        Parameters:
        tasksProcessor - processor which can handle several tasks at once
        executor -
        queue -
        maxTasksToHandle - max tasks to take from the queue and pass to processor at once
        name -
    • Method Detail

      • addToQueue

        public void addToQueue​(@NotNull
                               T data)
        Adds data to the queue. If queue is full, this method will block until some space will be available.
        Parameters:
        data -
      • isQueueEmpty

        public boolean isQueueEmpty()
        Returns:
        true if queue is empty and no processing is performed
      • isQueueFull

        public boolean isQueueFull()
        Returns:
        true if queue is full
      • getQueuedTasks

        public List<T> getQueuedTasks()
      • waitForEmptyQueue

        public void waitForEmptyQueue()
      • clearQueue

        public void clearQueue()