java.lang.Object
io.john.amiscaray.quak.core.Application
- Direct Known Subclasses:
WebApplication
Represents the base functionality of a quak application. This contains lifecycle hooks you can add callbacks to and methods to start or end the application.
Lifecycle hooks include: PRE_START, CONTEXT_LOADED, POST_START, PRE_STOP, POST_STOP.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumRepresents states during an application's lifecycle -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected String[]The program arguments passed to the application.protected StringThe package from which Quak scans for dependencies.protected booleanWhether the application context loaded.protected booleanWhether the application has started.protected Map<Application.LifecycleState, List<Consumer<Application>>> A map from lifecycle state to list of lifecycle event consumer.protected Class<?> The class that contains the application's main method. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidawait()Block while the application is running.protected voidprotected abstract voidfinish()Unimplemented tear down logic for your application.protected voidprotected voidInitializes a map of lifecycle states to lifecycle event consumers.protected voidvoidon(Application.LifecycleState state, Consumer<Application> consumer) Register an application lifecycle state listener.protected voidprotected voidpostStop()protected voidpreStart()protected voidpreStop()voidstart()Starts the application.voidStarts the application asynchronously.protected abstract voidstartUp()Unimplemented startup logic for your application.final voidstop()Stops the application.
-
Field Details
-
hasStarted
protected boolean hasStartedWhether the application has started. -
contextLoaded
protected boolean contextLoadedWhether the application context loaded. -
classScanPackage
The package from which Quak scans for dependencies. This should be an upmost package containing all classes. -
args
The program arguments passed to the application. -
main
The class that contains the application's main method. -
lifecycleListeners
A map from lifecycle state to list of lifecycle event consumer. The consumers accept this application instance.
-
-
Constructor Details
-
Application
Initialize an application.- Parameters:
main- The class containing the application's main method.args- The program arguments passed to the application.
-
-
Method Details
-
initLifecycleListeners
protected void initLifecycleListeners()Initializes a map of lifecycle states to lifecycle event consumers. -
start
Starts the application. In this initialization sequence, in this order, the application: calls any "pre-start" listeners, initializes the application properties, loads the application context, invokes the "context loaded" listeners, calls thestartup method, and calls the "post start" listeners.- Throws:
Exception- any exceptions from this method will be thrown.
-
stop
Stops the application. In this order, this method: calls any "pre stop" listeners, invokes thefinish method, and calls any "post stop" listeners.- Throws:
Exception- any exceptions from this method will be thrown.
-
finish
Unimplemented tear down logic for your application.- Throws:
Exception- any exception in this method is thrown.
-
startUp
Unimplemented startup logic for your application.- Throws:
Exception- any exception in this method is thrown.
-
startAsync
public void startAsync()Starts the application asynchronously. Notifies anything blocking on this application to stop when it does stop. -
await
Block while the application is running.- Throws:
InterruptedException- if there is a thread interruption.
-
initContext
protected void initContext() -
initProperties
protected void initProperties() -
on
Register an application lifecycle state listener.- Parameters:
state- The lifecycle state.consumer- A consumer that is called when this lifecycle state occurs. Accepts this.
-
preStart
protected void preStart() -
contextLoaded
protected void contextLoaded() -
postStart
protected void postStart() -
preStop
protected void preStop() -
postStop
protected void postStop()
-