Class DecoupledEventProcessor

java.lang.Object
swingtree.threading.DecoupledEventProcessor
All Implemented Interfaces:
EventProcessor

public final class DecoupledEventProcessor extends Object implements EventProcessor
This is a synchronized singleton wrapping a BlockingQueue.
  • Field Summary

    Fields inherited from interface swingtree.threading.EventProcessor

    COUPLED, COUPLED_STRICT, DECOUPLED
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    A fully blocking call to the decoupled thread event processor causing this thread to join its event queue so that it can continuously process events produced by the UI.
    void
    joinFor(long numberOfEvents)
    A fully blocking call to the decoupled thread event processor causing this thread to join its event queue so that it can process the given number of events produced by the UI.
    void
    A temporarily blocking call to the decoupled thread event processor causing this thread to join its event queue so that it can continuously process events produced by the UI until all events have been processed or an exception is thrown by the event processor.
    void
    A fully blocking call to the decoupled thread event processor causing this thread to join its event queue so that it can continuously process events produced by the UI.
    void
    joinUntilExceptionFor(long numberOfEvents)
    A temporarily blocking call to the decoupled thread event processor causing this thread to join its event queue so that it can process the given number of events produced by the UI.
    void
    Adds the supplied task to an event queue for processing application events and then waits for the task to be processed on the application thread.
    void
    Adds the supplied task to an event queue for processing UI events and then waits for the task to be processed on the GUI thread.
    void
    Adds the supplied task to an event queue for processing application events.
    void
    Adds the supplied task to an event queue for processing UI events.

    Methods inherited from class java.lang.Object

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

    • DecoupledEventProcessor

      public DecoupledEventProcessor()
  • Method Details

    • registerAppEvent

      public void registerAppEvent(Runnable task)
      Description copied from interface: EventProcessor
      Adds the supplied task to an event queue for processing application events. The task is executed in the application thread, which may be the GUI thread (but shouldn't be if you are doing clean software development). This method returns immediately.
      Specified by:
      registerAppEvent in interface EventProcessor
      Parameters:
      task - The task to be executed in the application thread.
    • registerAndRunAppEventNow

      public void registerAndRunAppEventNow(Runnable runnable)
      Description copied from interface: EventProcessor
      Adds the supplied task to an event queue for processing application events and then waits for the task to be processed on the application thread. The task is executed in the application thread, which, depending on your implementation, may also be the GUI thread (but shouldn't be if you are doing clean software development). This method returns when the task has been processed.
      Specified by:
      registerAndRunAppEventNow in interface EventProcessor
      Parameters:
      runnable - The task to be executed in the application thread.
    • registerUIEvent

      public void registerUIEvent(Runnable runnable)
      Description copied from interface: EventProcessor
      Adds the supplied task to an event queue for processing UI events. The task is executed in the GUI thread, which is the EDT in Swing. This method returns immediately.
      Specified by:
      registerUIEvent in interface EventProcessor
      Parameters:
      runnable - The task to be executed in the GUI thread.
    • registerAndRunUIEventNow

      public void registerAndRunUIEventNow(Runnable runnable)
      Description copied from interface: EventProcessor
      Adds the supplied task to an event queue for processing UI events and then waits for the task to be processed on the GUI thread. The task is executed in the GUI thread, which is the EDT in Swing. This method returns when the task has been processed.
      Specified by:
      registerAndRunUIEventNow in interface EventProcessor
      Parameters:
      runnable - The task to be executed in the GUI thread.
    • join

      public void join()
      A fully blocking call to the decoupled thread event processor causing this thread to join its event queue so that it can continuously process events produced by the UI.

      This method wither be called by the main thread of the application after the UI has been built and shown to the user, or alternatively a new thread dedicated to processing events. (things like button clicks, etc.)

      Throws:
      IllegalStateException - If this method is called from the UI thread.
    • joinUntilException

      public void joinUntilException() throws InterruptedException
      A fully blocking call to the decoupled thread event processor causing this thread to join its event queue so that it can continuously process events produced by the UI.

      This method should be called by the main thread of the application after the UI has been built and shown to the user, or alternatively a new thread dedicated to processing events. (things like button clicks, etc.)

      This method will block until an exception is thrown by the event processor. This is useful for debugging purposes.

      Throws:
      InterruptedException - If the thread is interrupted while waiting for the event processor to join.
    • joinFor

      public void joinFor(long numberOfEvents)
      A fully blocking call to the decoupled thread event processor causing this thread to join its event queue so that it can process the given number of events produced by the UI.

      This method should be called by the main thread of the application after the UI has been built and shown to the user, or alternatively a new thread dedicated to processing events. (things like button clicks, etc.)

      This method will block until the given number of events have been processed.

      Parameters:
      numberOfEvents - The number of events to wait for.
    • joinUntilExceptionFor

      public void joinUntilExceptionFor(long numberOfEvents) throws InterruptedException
      A temporarily blocking call to the decoupled thread event processor causing this thread to join its event queue so that it can process the given number of events produced by the UI.

      This method should be called by the main thread of the application after the UI has been built and shown to the user, or alternatively a new thread dedicated to processing events. (things like button clicks, etc.)

      This method will block until the given number of events have been processed or an exception is thrown by the event processor.

      Parameters:
      numberOfEvents - The number of events to wait for.
      Throws:
      InterruptedException - If the thread is interrupted while waiting for the event processor to join.
    • joinUntilDoneOrException

      public void joinUntilDoneOrException() throws InterruptedException
      A temporarily blocking call to the decoupled thread event processor causing this thread to join its event queue so that it can continuously process events produced by the UI until all events have been processed or an exception is thrown by the event processor.

      This method should be called by the main thread of the application after the UI has been built and shown to the user, or alternatively a new thread dedicated to processing events. (things like button clicks, etc.)

      Throws:
      InterruptedException - If the thread is interrupted while waiting.