Class RdcUtilitiesWithBackgroundPool

java.lang.Object
org.tentackle.fx.rdc.RdcUtilities
org.tentackle.fx.rdc.RdcUtilitiesWithBackgroundPool

public class RdcUtilitiesWithBackgroundPool extends RdcUtilities
Extended RdcUtilities with a thread- and session pool for background execution.
Replace with application specific implementation via Service annotation.

Example:

 @Service(RdcUtilities.class)
 public class MyRdcUtilities extends RdcUtilitiesWithBackgroundPool {

   public static MyRdcUtilities getInstance() {   // to access the extra methods
     return (MyRdcUtilities) RdcUtilities.getInstance();
   }

   @Override
   protected SessionPool createSessionPool(Session session) {
     // 10 sessions max, at least 1 open (default is 3 and none open)
     return SessionPoolFactory.getInstance().create("BG", session, 1, 1, 1, 10, 5, 0);
   }
 }
 
  • Constructor Details

    • RdcUtilitiesWithBackgroundPool

      public RdcUtilitiesWithBackgroundPool()
      Creates the extended RDC utilities.
  • Method Details

    • getExecutor

      public org.tentackle.session.SessionPooledExecutor getExecutor()
      Gets the session pool executor.
      Returns:
      the executor
    • runInBackground

      public <V> void runInBackground(Supplier<V> runner, Consumer<V> updateUI, Consumer<RuntimeException> failedUI)
      Description copied from class: RdcUtilities
      Runs some code in another thread and optionally updates the UI.
      The method is provided to hide the concrete implementation and make it replaceable.
      Use this method whenever some lengthy operation (database I/O, for example) would otherwise block the event queue.

      The default implementation creates a AbstractSessionTask and runs it on behalf of the ModificationTracker. If the runner itself is a SessionDependable it gets the session set as well before it is invoked. The result is then passed to updateUI and executed via Platform.runLater(Runnable).

      Overrides:
      runInBackground in class RdcUtilities
      Type Parameters:
      V - the type returned by the runner
      Parameters:
      runner - the code running in another thread in parallel to the FX thread
      updateUI - optional UI updater invoked from within the FX event queue, null if none
      failedUI - optional UI updater invoked if execution failed, null if log only as error
    • runInBackground

      public <V> void runInBackground(Collection<Supplier<V>> runners, long timeoutMillis, Consumer<Map<Supplier<V>,V>> finishedUI, Consumer<Map<Supplier<V>,RuntimeException>> failedUI)
      Runs a collection of runners in background in parallel.
      If there are failures, failedUI (if any) will be invoked before finishedUI.
      Type Parameters:
      V - the type returned by the runners
      Parameters:
      runners - the runners to invoke
      timeoutMillis - the timeout in milliseconds for all tasks to finish, 0 if no timeout
      finishedUI - UI updater invoked from within the FX event queue when all runners finished, null if none
      failedUI - UI updater invoked from within the FX event queue only if execution of some runner failed, null if log only as error
    • runInBackground

      public <V> void runInBackground(Collection<Supplier<V>> runners, long timeoutMillis, Consumer<Map<Supplier<V>,V>> finishedUI)
      Runs a collection of runners in background in parallel.
      Failures will be presented to the user in an error dialog.
      Type Parameters:
      V - the type returned by the runners
      Parameters:
      runners - the runners to invoke
      timeoutMillis - the timeout in milliseconds for all tasks to finish, 0 if no timeout
      finishedUI - optional UI updater always invoked from within the FX event queue if all runners finished, null if none
    • createExecutor

      protected org.tentackle.session.SessionPooledExecutor createExecutor()
      Creates the executor.
      Returns:
      the executor
    • createSessionPool

      protected org.tentackle.session.SessionPool createSessionPool(org.tentackle.session.Session session)
      Creates the session pool.
      Parameters:
      session - the template session
      Returns:
      the session pool