Generic application bootstrap that wires a container with lifecycle management. More...
Public Member Functions | |
| record | Runtime< C > (C container, Closer closer) implements AutoCloseable |
| Immutable holder for the running application state. | |
Static Public Member Functions | |
| static< C > Runtime< C > | start (final Supplier< C > containerFactory) |
| Convenience overload — starts without warmup or pre-shutdown callback. | |
| static< C > Runtime< C > | start (final Supplier< C > containerFactory, final Consumer< C > warmup) |
| Convenience overload — starts without a pre-shutdown callback. | |
| static< C > Runtime< C > | start (final Supplier< C > containerFactory, final Consumer< C > warmup, final Consumer< C > onShutdown) |
| Creates and starts the application. | |
Generic application bootstrap that wires a container with lifecycle management.
Bootstrap ties together three lifecycle concerns:
Supplier builds the application-specific container. Consumer eagerly initializes all components so startup failures surface immediately instead of at first request. Closer in LIFO order. The returned Runtime is AutoCloseable, so it integrates naturally with try-with-resources for graceful shutdown in tests and CLI applications.
var runtime = Bootstrap.start(
AppContainer::new, // factory
AppContainer::warmup, // fail-fast eager init
container -> {} // pre-shutdown callback
);
try (runtime) {
JettyServer.start(runtime.container());
}
This class has no public constructors — use the static factory methods.
Definition at line 62 of file Bootstrap.java.
| record dev.rafex.ether.di.Bootstrap.Runtime< C > | ( | C | container, |
| Closer | closer ) |
Immutable holder for the running application state.
| <C> | type of the application container |
Creates a Runtime; both parameters must be non-null.
Closes the underlying Closer, releasing all registered resources in LIFO order.
Definition at line 73 of file Bootstrap.java.
|
static |
Convenience overload — starts without warmup or pre-shutdown callback.
| <C> | type of the application container |
| containerFactory | supplier that creates the container |
Runtime holding the container and its closer Definition at line 165 of file Bootstrap.java.
References start().
|
static |
Convenience overload — starts without a pre-shutdown callback.
| <C> | type of the application container |
| containerFactory | supplier that creates the container |
| warmup | optional warmup consumer; null disables warmup |
Runtime holding the container and its closer Definition at line 152 of file Bootstrap.java.
References start().
|
static |
Creates and starts the application.
Steps performed:
Closer. containerFactory. AutoCloseable, register it with the closer. warmup is non-null, invoke it — any exception aborts startup. onShutdown (if non-null) then closes the closer. | <C> | type of the application container |
| containerFactory | supplier that creates the container; must not return null |
| warmup | optional consumer invoked after container creation to eagerly initialize all components; null disables warmup |
| onShutdown | optional consumer invoked on JVM shutdown before resources are closed; null disables the pre-shutdown callback |
Runtime holding the container and its closer Definition at line 111 of file Bootstrap.java.
Referenced by start(), and start().