nn.pp.core

## Class EventDispatcher

- java.lang.Object
- - nn.pp.core.EventDispatcher

-     public abstract class EventDispatcher
      extends java.lang.Object

  Helper class to dispatch events from the cores.

  All types of "core" objects (KVM, Virtual Media, Audio, ...) emit events using event listeners. These events are emitted on a specific thread. To configure what thread is used, a custom event dispatcher can be set.

  The event dispatcher is a global setting. It applies to all types of core objects.

  By default (no custom event dispatcher is set), all events are dispatched on the Java Swing event dispatch thread.

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static EventDispatcher` | `swingEventDispatcher` The pre-defined event dispatcher which uses the Java Swing event dispatch thread

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `EventDispatcher()`

  - ### Method Summary

    All Methods Static Methods Instance Methods Abstract Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static EventDispatcher` | `getEventDispatcher()` Get the current event dispatcher.
    `abstract void` | `invokeOnEventDispatchThread(java.lang.Runnable runnable)` Invoke a runnable on the event dispatch thread.
    `abstract void` | `invokeOnEventDispatchThreadAndWait(java.lang.Runnable runnable)` Invoke a runnable on the event dispatch thread.
    `abstract boolean` | `isEventDispatchThread()` Return whether the current thread is the thread that events should be emitted on.
    `static <V> V` | `scheduleCallWithResult(java.util.concurrent.Callable<V> callable)` Schedule a callable for a method call with a return value.
    `static void` | `scheduleVoidCall(java.lang.Runnable runnable)` Schedule a runnable for a method call that has no return values.
    `static void` | `scheduleVoidCallAndWait(java.lang.Runnable runnable)` Schedule a runnable for a method call that has no return values.
    `static void` | `setEventDispatcher(EventDispatcher dispatcher)` Set a event dispatcher.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### swingEventDispatcher

          public static EventDispatcher swingEventDispatcher

      The pre-defined event dispatcher which uses the Java Swing event dispatch thread

  - ### Constructor Detail

    - #### EventDispatcher

          public EventDispatcher()

  - ### Method Detail

    - #### isEventDispatchThread

          public abstract boolean isEventDispatchThread()

      Return whether the current thread is the thread that events should be emitted on.

      This needs to be implemented by any custom event dispatcher.

      Returns:
        `true` if the current thread is the event dispatch thread, `false` otherwise.

    - #### invokeOnEventDispatchThread

          public abstract void invokeOnEventDispatchThread(java.lang.Runnable runnable)

      Invoke a runnable on the event dispatch thread. The event is dispatched and is it not waited for the result. The strategy is "fire and forget".

      This needs to be implemented by any custom event dispatcher.

      Parameters:
        `runnable` - the code that should be invoked on the event dispatch thread

    - #### invokeOnEventDispatchThreadAndWait

          public abstract void invokeOnEventDispatchThreadAndWait(java.lang.Runnable runnable)
                                                           throws java.lang.reflect.InvocationTargetException,
                                                                  java.lang.InterruptedException

      Invoke a runnable on the event dispatch thread. The event is dispatched and the method waits for the event to end.

      Parameters:
        `runnable` - the code that should be invoked on the event dispatch thread
      Throws:
        `java.lang.reflect.InvocationTargetException` - if an exception is thrown while running `runnable`
        `java.lang.InterruptedException` - if we're interrupted while waiting for the event dispatching thread to finish executing `runnable.run()`

    - #### getEventDispatcher

          public static EventDispatcher getEventDispatcher()

      Get the current event dispatcher. If no custom dispatcher is set, then the default Java Swing event dispatcher is returned.
      Returns:
        the current event dispatcher

    - #### setEventDispatcher

          public static void setEventDispatcher(EventDispatcher dispatcher)

      Set a event dispatcher. If there is already an event dispatcher set, this method will throw an IllegalStateException. It is not allowed to change the dispatcher when one is already set.
      Parameters:
        `dispatcher` - the event dispatcher to set

    - #### scheduleVoidCall

          public static void scheduleVoidCall(java.lang.Runnable runnable)

      Schedule a runnable for a method call that has no return values. The action is performed asynchronously, we don't wait for it to finish. Any exceptions will be ignored.
      Parameters:
        `runnable` - The runnable to schedule

    - #### scheduleVoidCallAndWait

          public static void scheduleVoidCallAndWait(java.lang.Runnable runnable)

      Schedule a runnable for a method call that has no return values. We will wait for the action to finish. Any exceptions are thrown back encapsulated in a RuntimeException.
      Parameters:
        `runnable` - The runnable to schedule
      Throws:
        `java.lang.RuntimeException` - if an exception occurred within the callable, this exception is encapsulated in a RuntimeException

    - #### scheduleCallWithResult

          public static <V> V scheduleCallWithResult(java.util.concurrent.Callable<V> callable)

      Schedule a callable for a method call with a return value. We will wait for the action to finish in order to return the result. Any exceptions are thrown back encapsulated in a RuntimeException.
      Type Parameters:
        `V` - The return type of the callable
      Parameters:
        `callable` - The callable to schedule
      Returns:
        The return value of the callable
      Throws:
        `java.lang.RuntimeException` - if an exception occurred within the callable, this exception is encapsulated in a RuntimeException

Copyright © 2025 Raritan Inc. All Rights Reserved.