Class EventPoller<T>

java.lang.Object
com.github.workerframework.util.rabbitmq.EventPoller<T>
Type Parameters:
T - the sort of Event this EventPoller will use
All Implemented Interfaces:
Runnable
Direct Known Subclasses:
DefaultRabbitPublisher, RabbitConsumer

public class EventPoller<T> extends Object implements Runnable
An abstract class to poll a BlockingQueue for events and defer them for handling.
  • Constructor Details

    • EventPoller

      public EventPoller(int pollPeriod, BlockingQueue<Event<T>> eventQueue, T eventHandler)
      Create a new EventPoller.
      Parameters:
      pollPeriod - the period in which to poll the event queue, which will also affect the shutdown time
      eventQueue - the object to use for storing and polling events
      eventHandler - the implementation to handle events
  • Method Details

    • run

      public void run()
      Start a thread that will poll with the period specified when the object was created. Each event received will be handed off to the event handler which inheriting classes specify. This thread will properly query and re-raise the interrupt flag.
      Specified by:
      run in interface Runnable
    • getEventQueue

      protected final BlockingQueue<Event<T>> getEventQueue()
      Returns:
      the internal event queue
    • shutdown

      public final void shutdown()
      Signal the termination of the EventPoller. It will terminate at the next possible opportunity. If the EventPoller is not running this has no effect.