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.protected voidrestoreDefaultCursor(javafx.scene.Node node, javafx.scene.Cursor oldCursor) Restores the cursor to the default.<V> voidrunInBackground(javafx.scene.Node node, 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(javafx.scene.Node node, 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 beforefinishedUI.<V> voidrunInBackground(javafx.scene.Node node, 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, getCrud, getInstance, getMainStage, getPdoFromDragboard, getPdoKeyFromDragboard, getPdoKeysFromDragboard, getPdosFromDragboard, getSearch, invalidateCaches, isCrudCachingEnabled, isSearchCachingEnabled, 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(javafx.scene.Node node, 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 optional node will get the wait cursor set, while the task is executed in background.
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:
node- the optional node this background task is related to, null if nonerunner- 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(javafx.scene.Node node, 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 beforefinishedUI.- Type Parameters:
V- the type returned by the runners- Parameters:
node- the optional node the background execution is related to, null if nonerunners- 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(javafx.scene.Node node, 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:
node- the optional node the background execution is related to, null if nonerunners- 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
-
restoreDefaultCursor
protected void restoreDefaultCursor(javafx.scene.Node node, javafx.scene.Cursor oldCursor) Restores the cursor to the default.- Parameters:
node- the node, null if noneoldCursor- the old cursor of the node (null, if it was the default cursor)
-