java.lang.Object
org.tentackle.fx.rdc.RdcUtilities
org.tentackle.fx.rdc.RdcUtilitiesWithBackgroundPool
Extended
Replace with application specific implementation via
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected org.tentackle.session.SessionPooledExecutorCreates the executor.protected org.tentackle.session.SessionPoolcreateSessionPool(org.tentackle.session.Session session) Creates the session pool.org.tentackle.session.SessionPooledExecutorGets the session pool executor.<V> voidrunInBackground(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.<V> voidrunInBackground(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.<V> voidrunInBackground(Supplier<V> runner, Consumer<V> updateUI, Consumer<RuntimeException> failedUI) 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.Methods inherited from class org.tentackle.fx.rdc.RdcUtilities
createDragboard, displayCrudStage, displaySearchStage, displaySearchStage, getCrud, getInstance, getMainStage, getPdoFromDragboard, getPdoKeyFromDragboard, getSearch, selectFile, showSaveDiscardCancelDialog, showTree
-
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:RdcUtilitiesRuns 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
AbstractSessionTaskand runs it on behalf of theModificationTracker. If the runner itself is aSessionDependableit gets the session set as well before it is invoked. The result is then passed toupdateUIand executed viaPlatform.runLater(Runnable).- Overrides:
runInBackgroundin classRdcUtilities- Type Parameters:
V- the type returned by the runner- Parameters:
runner- the code running in another thread in parallel to the FX threadupdateUI- optional UI updater invoked from within the FX event queue, null if nonefailedUI- 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.- Type Parameters:
V- the type returned by the runners- Parameters:
runners- the runners to invoketimeoutMillis- the timeout in milliseconds for all tasks to finish, 0 if no timeoutfinishedUI- UI updater invoked from within the FX event queue when all runners finished, null if nonefailedUI- 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 invoketimeoutMillis- the timeout in milliseconds for all tasks to finish, 0 if no timeoutfinishedUI- 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
-