Class SwingExecutors

java.lang.Object
org.jtrim2.swing.concurrent.SwingExecutors

public final class SwingExecutors extends Object
Defines factory methods for executor implementations executing scheduled tasks on the AWT Event Dispatch Thread.
  • Method Details

    • getDefaultInstance

      public static TaskExecutorService getDefaultInstance()
      Returns a TaskExecutorService which executes tasks submitted to them on the AWT Event Dispatch Thread. This method always returns the same TaskExecutorService instance and is intended to be used as a sensible default value when an executor is need which executes task on the EDT. The returned TaskExecutorService cannot be shutted down, attempting to do so will cause an unchecked exception to be thrown.
      Returns:
      a TaskExecutorService which executes tasks submitted to them on the AWT Event Dispatch Thread. This method never returns null.
    • getSwingUpdateExecutor

      public static UpdateTaskExecutor getSwingUpdateExecutor()
      Returns an UpdateTaskExecutor implementation which executes tasks on the AWT Event Dispatch Thread. The returned executor will not call the scheduled tasks on the calling thread even if the calling thread is the AWT Event Dispatch Thread.

      This method is effectively the same as calling getSwingUpdateExecutor(true).

      Returns:
      an UpdateTaskExecutor implementation which executes tasks on the AWT Event Dispatch Thread. This method never returns null.
    • getSwingUpdateExecutor

      public static UpdateTaskExecutor getSwingUpdateExecutor(boolean alwaysInvokeLater)
      Returns an UpdateTaskExecutor implementation which executes tasks on the AWT Event Dispatch Thread.
      Parameters:
      alwaysInvokeLater - if this argument is true, submitted tasks are never executed synchronously on the calling thread (i.e.: they are always submitted as SwingUtilities.invokeLater does it). In case this argument is false, tasks submitted from the AWT Event Dispatch Thread will be executed immediately on the calling thread (this may not always possible to execute tasks in the order they were submitted).
      Returns:
      an UpdateTaskExecutor implementation which executes tasks on the AWT Event Dispatch Thread. This method never returns null.
    • getSwingExecutorService

      public static TaskExecutorService getSwingExecutorService(boolean alwaysInvokeLater)
      Returns a TaskExecutorService which executes submitted tasks on the AWT Event Dispatch Thread. Submitted tasks are executed in the order they were submitted. Unlike TaskExecutorService implementations in general, SwingTaskExecutor instances does not need to be shutted down (although shutdown is still possible).

      In case the services provided by the TaskExecutor service are adequate, consider using the more efficient implementations returned by the static getSimpleExecutor or getStrictExecutor methods.

      A static instance can be retrieved by the getDefaultInstance method. The instance returned by this method can be used as a sensible default value.

      Parameters:
      alwaysInvokeLater - if this argument is true, submitted tasks are never executed synchronously on the calling thread (i.e.: they are always submitted as SwingUtilities.invokeLater does it). In case this argument is false, tasks submitted from the AWT Event Dispatch Thread will be executed immediately on the calling thread (this may not always possible to execute tasks in the order they were submitted).
      Returns:
      a TaskExecutorService which executes submitted tasks on the AWT Event Dispatch Thread. This method never returns null.
      See Also:
    • getSimpleExecutor

      public static TaskExecutor getSimpleExecutor(boolean alwaysInvokeLater)
      Returns a TaskExecutor which executes tasks submitted to them on the AWT Event Dispatch Thread. The returned executor does not necessarily executes tasks in the same order as the tasks were submitted. In case tasks needed to be executed in the same order as they were submitted to the executor: Use the getStrictExecutor(boolean) method.

      The returned executor is more efficient than an instance returned by getSwingExecutorService(boolean).

      Parameters:
      alwaysInvokeLater - if this argument is true, submitted tasks are never executed synchronously on the calling thread (i.e.: they are always submitted as SwingUtilities.invokeLater does it). In case this argument is false, tasks submitted from the AWT Event Dispatch Thread will be executed immediately on the calling thread.
      Returns:
      a TaskExecutor which executes tasks submitted to them on the AWT Event Dispatch Thread. This method never returns null.
      See Also:
    • getStrictExecutor

      public static TaskExecutor getStrictExecutor(boolean alwaysInvokeLater)
      Returns a TaskExecutor which executes tasks submitted to them on the AWT Event Dispatch Thread. The returned executor executes tasks in the same order as the tasks were submitted. If you don't need to execute them in the same order, consider using the getSimpleExecutor(boolean) method.

      The returned executor is more efficient than an instance returned by getSwingExecutorService(boolean).

      Parameters:
      alwaysInvokeLater - if this argument is true, submitted tasks are never executed synchronously on the calling thread (i.e.: they are always submitted as SwingUtilities.invokeLater does it). In case this argument is false, tasks submitted from the AWT Event Dispatch Thread will be executed immediately on the calling thread (this may not always possible to execute tasks in the order they were submitted).
      Returns:
      a TaskExecutor which executes tasks submitted to them on the AWT Event Dispatch Thread. This method never returns null.
      See Also:
    • getSwingExecutorProvider

      public static UiExecutorProvider getSwingExecutorProvider()
      Returns an implementation of UiExecutorProvider executing scheduled tasks on the AWT Event Dispatch Thread.
      Returns:
      an implementation of UiExecutorProvider executing scheduled tasks on the AWT Event Dispatch Thread. This method never returns null.
    • getSwingBackgroundTaskExecutor

      public static <IDType, RightType> BackgroundTaskExecutor<IDType,RightType> getSwingBackgroundTaskExecutor(AccessManager<IDType,RightType> accessManager, TaskExecutor executor)
      Creates a new BackgroundTaskExecutor to be used with Swing with the given access manager and TaskExecutor.

      The specified TaskExecutor is recommended to execute tasks on a separate thread instead of the calling thread, however for debugging purposes it may be beneficial to use the SyncTaskExecutor. The executor should execute tasks on a separate thread to allow methods of this class to be called from the AWT Event Dispatch Thread without actually blocking the EDT.

      Type Parameters:
      IDType - the type of the request ID of the underlying access manager
      RightType - the type of the rights handled by the underlying access manager
      Parameters:
      accessManager - the AccessManager from which access tokens are requested to execute tasks in their context. This argument cannot be null.
      executor - the TaskExecutor which actually executes submitted tasks. This argument cannot be null.
      Returns:
      a new BackgroundTaskExecutor to be used with Swing with the given access manager and TaskExecutor. This method never returns null.