Package 

Class AsyncQueueHandler


  • 
    final class AsyncQueueHandler<T>
    
                        

    Asynchronously reads items from provided queue on separate thread borrowed from executor and process items with specified handler. Thread is not blocked when queue is empty and returned back to executor pool. New or existing thread is borrowed from executor when queue is non empty and reader is not running

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      interface AsyncQueueHandler.Handler

      A simple interface to handle enqueued T items.

    • Method Summary

      Modifier and Type Method Description
      void cancel() Attempts to stop execution of reader if running
      void handleQueueItemsUntilEmpty() Checks if reader is running on one of executor thread and if no submits execution of reader on executor.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • AsyncQueueHandler

        AsyncQueueHandler(BlockingQueue<T> queue, AsyncQueueHandler.Handler<T> handler, String id, ExecutorService executor, long maxSequentiallyHandledItems)
        Constructs instance of AsyncQueueHandler which is capable of asynchronous reading provided queue from thread borrowed from executor to process items with provided handler.
        Parameters:
        queue - thread-safe queue which holds items to process
        handler - an implementation of handler routine which will beinvoked per each item placed in the queue.
        id - optional identifier of current handler for debug purpose
        executor - optional executor service to borrow threads from
        maxSequentiallyHandledItems - maximum number of items sequentiallyhandled on thread borrowed from before temporaryreleasing thread and re-acquiring it from .
    • Method Detail

      • cancel

         void cancel()

        Attempts to stop execution of reader if running

      • handleQueueItemsUntilEmpty

         void handleQueueItemsUntilEmpty()

        Checks if reader is running on one of executor thread and if no submits execution of reader on executor.