Class AbstractRunnableBlockingQueueConsumer<E>

  • Type Parameters:
    E - The type of elements held in the queue.
    All Implemented Interfaces:
    Consumer<E>, java.lang.Runnable

    public abstract class AbstractRunnableBlockingQueueConsumer<E>
    extends java.lang.Object
    implements Consumer<E>, java.lang.Runnable
    A runnable consumer that takes elements from a blocking queue and consume them. Normally this consumer is run in a separate thread so that consuming can occur asynchronously. Each element is taken using BlockingQueue.take() and processed using consume(Object). This runnable's interruption policy is to end execution.
    Author:
    Garret Wilson
    See Also:
    BlockingQueue.take()
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      abstract void consume​(E element)
      Consumes an element from the queue.
      protected java.util.concurrent.BlockingQueue<E> getBlockingQueue()  
      void run()
      The main functionality of the consumer, which consumes data from the blocking queue and calls consume(Object).
      protected void started()
      Called when the consumer is started before processing ends.
      protected void stopped()
      Called when the consumer is stopped after processing ends.
      • Methods inherited from class java.lang.Object

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

      • AbstractRunnableBlockingQueueConsumer

        public AbstractRunnableBlockingQueueConsumer​(java.util.concurrent.BlockingQueue<E> blockingQueue)
        Blocking queue constructor.
        Parameters:
        blockingQueue - The blocking queue from which elements will be consumed.
        Throws:
        java.lang.NullPointerException - if the given blocking queue is null.
    • Method Detail

      • getBlockingQueue

        protected java.util.concurrent.BlockingQueue<E> getBlockingQueue()
        Returns:
        The blocking queue from which elements are being consumed.
      • run

        public void run()
        The main functionality of the consumer, which consumes data from the blocking queue and calls consume(Object).
        Specified by:
        run in interface java.lang.Runnable
      • started

        protected void started()
        Called when the consumer is started before processing ends.
      • consume

        public abstract void consume​(E element)
        Consumes an element from the queue.
        Specified by:
        consume in interface Consumer<E>
        Parameters:
        element - The element to consume.
      • stopped

        protected void stopped()
        Called when the consumer is stopped after processing ends.