java.lang.Object
app.supernaut.fx.FxLauncherAbstract
- All Implemented Interfaces:
FxLauncher
- Direct Known Subclasses:
MicronautFxLauncher
,SimpleFxLauncher
Base JavaFX implementation of
FxLauncher
. This implementation provides the following functionality:
- Starts OpenJFX applications.
-
Constructor provides an option to start
BackgroundApp
on a new thread (this allows theBackgroundApp
and the OpenJFXApplicationDelegate
to initialize in parallel.) -
Implements
FxLauncher.launchAsync(java.lang.String[], java.lang.Class<? extends app.supernaut.fx.ApplicationDelegate>, java.lang.Class<? extends app.supernaut.BackgroundApp>)
which initializes the OpenJFXApplicationDelegate
on a new thread. This is not needed for a typical, packaged OpenJFX application which can just callFxLauncher.launch(java.lang.String[], java.lang.Class<? extends app.supernaut.fx.ApplicationDelegate>, java.lang.Class<? extends app.supernaut.BackgroundApp>)
from itsstatic main()
, but is useful in various testing scenarios. -
Defines the
FxLauncherAbstract.AppFactory
interface for constructing theBackgroundApp
andApplicationDelegate
. This allows subclasses (or callers) to provide their own implementation of the application creation logic. The AppFactory interface was designed to allow usage of Dependency Injection frameworks like Micronaut to create dependency-injected implementations ofApplicationDelegate
andBackgroundApp
. TheAppFactory
interface was also designed to be lazily-instantiated so theAppFactory
(dependency-injection framework) can initialize in parallel to OpenJFX. -
Uses the same
AppFactory
(dependency-injection context) to initialize the ApplicationDelegate and Background application. ACountDownLatch
is used to make sure theAppFactory
(which may be initialized on another thread along with the BackgroundApp) is ready whenOpenJfxProxyApplication
callscreateAppDelegate(Application proxyApplication)
.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interface
Interface that can be used to create and pre-initializeApplicationDelegate
andBackgroundApp
.static class
Default implementation of AppFactory. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final CompletableFuture<ApplicationDelegate>
This future returns an initialized ApplicationDelegateprotected final CompletableFuture<BackgroundApp>
This future returns an initialized BackgroundApp -
Constructor Summary
ConstructorsConstructorDescriptionFxLauncherAbstract
(Supplier<FxLauncherAbstract.AppFactory> appFactorySupplier, boolean initializeBackgroundAppOnNewThread) Construct an Asynchronous Launcher that works with OpenJFX. -
Method Summary
Modifier and TypeMethodDescriptioncreateAppDelegate
(javafx.application.Application proxyApplication) Called byOpenJfxProxyApplication
to create its delegateApplicationDelegate
object.Get a future that will be completed when the ApplicationDelegate is initialized.Get a future that will be completed when the Background app is initialized.void
launch
(String[] args, Class<? extends ApplicationDelegate> appDelegate) Launch and run the application on the current thread.void
launch
(String[] args, Class<? extends ApplicationDelegate> appDelegate, Class<? extends BackgroundApp> backgroundApp) Launch and run the application on the current thread.launchAsync
(String[] args, Class<? extends ApplicationDelegate> appDelegate, Class<? extends BackgroundApp> backgroundApp) Launch and run the application on a newly created thread.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface app.supernaut.fx.FxLauncher
name
-
Field Details
-
futureBackgroundApp
This future returns an initialized BackgroundApp -
futureAppDelegate
This future returns an initialized ApplicationDelegate
-
-
Constructor Details
-
FxLauncherAbstract
public FxLauncherAbstract(Supplier<FxLauncherAbstract.AppFactory> appFactorySupplier, boolean initializeBackgroundAppOnNewThread) Construct an Asynchronous Launcher that works with OpenJFX.- Parameters:
appFactorySupplier
- A Supplier that will lazily instantiate an AppFactory.initializeBackgroundAppOnNewThread
- If true, initializesappFactorySupplier
andBackgroundApp
on new thread, if false start them on calling thread (typically the main thread)
-
-
Method Details
-
launchAsync
public CompletableFuture<ApplicationDelegate> launchAsync(String[] args, Class<? extends ApplicationDelegate> appDelegate, Class<? extends BackgroundApp> backgroundApp) Launch and run the application on a newly created thread. This method is useful for testing and possibly for other application startup scenarios.- Specified by:
launchAsync
in interfaceFxLauncher
- Parameters:
args
- command-line argsappDelegate
- class object for ApplicationDelegatebackgroundApp
- class object for BackgroundApp- Returns:
- A future that is completed when ApplicationDelegate app is initialized
-
launch
public void launch(String[] args, Class<? extends ApplicationDelegate> appDelegate, Class<? extends BackgroundApp> backgroundApp) Launch and run the application on the current thread. Does not return until after ApplicationDelegate closes.- Specified by:
launch
in interfaceFxLauncher
- Parameters:
args
- command-line argsappDelegate
- class object for ApplicationDelegatebackgroundApp
- class object for BackgroundApp
-
launch
Launch and run the application on the current thread. Uses default/no-op background application. Does not return until after ApplicationDelegate closes.- Specified by:
launch
in interfaceFxLauncher
- Parameters:
args
- command-line argsappDelegate
- class object for ApplicationDelegate
-
createAppDelegate
Called byOpenJfxProxyApplication
to create its delegateApplicationDelegate
object. Waits on aCountDownLatch
to make sure theAppFactory
is ready.- Specified by:
createAppDelegate
in interfaceFxLauncher
- Parameters:
proxyApplication
- The calling instance ofOpenJfxProxyApplication
- Returns:
- The newly constructed OpenJFX-compatible
ApplicationDelegate
-
getAppDelegate
Get a future that will be completed when the ApplicationDelegate is initialized.- Specified by:
getAppDelegate
in interfaceFxLauncher
- Returns:
- A future that is completed when ApplicationDelegate is initialized
-
getBackgroundApp
Get a future that will be completed when the Background app is initialized.- Specified by:
getBackgroundApp
in interfaceFxLauncher
- Returns:
- A future that is completed when Background app is initialized
-