Class EventPersistenceContext
java.lang.Object
io.hypersistence.optimizer.core.event.persistence.EventPersistenceContext
The
EventPersistenceContext wires together the collaborators of the event persistence
feature (EventStore, RuntimeEventAggregator and
PersistentEventHandler) and manages their lifecycle.
All failures are contained: if the feature cannot be started (e.g. the database is unreachable), it disables itself and logs a warning, but never propagates the failure into the host application.
- Since:
- 2.14.0
- Author:
- Vlad Mihalcea
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidFlush all currently buffered runtime rollups to the database, regardless of whether their time window has closed.Get theEventHandlerthat persists runtime events.Get theRuntimeEventAggregator.Get the resolvedEventPersistenceSettings.Get the URL the web app is available at, ornullif it is not running.booleanisActive()Check whether the feature is currently active.voidpersistBootstrapEvents(String hibernateVersion, List<Event> bootstrapEvents) Persist the configuration and mapping events collected during scanning, as a single run.booleanstart()Start the runtime aggregator after the bootstrap scanner has prepared the schema.voidStart the web app, reusing the host application'sSessionFactory.voidstop()Stop the feature, flushing any pending runtime rollups.voidStop the web app, if it is running, while keeping the event persistence feature active.
-
Constructor Details
-
EventPersistenceContext
-
-
Method Details
-
start
public boolean start()Start the runtime aggregator after the bootstrap scanner has prepared the schema. The web app is started separately, viastartWebApp().- Returns:
trueif the feature started successfully,falseotherwise
-
persistBootstrapEvents
Persist the configuration and mapping events collected during scanning, as a single run.- Parameters:
hibernateVersion- the current Hibernate versionbootstrapEvents- the collected configuration and mapping events
-
getEventHandler
Get theEventHandlerthat persists runtime events.- Returns:
- the runtime
EventHandler
-
flushRuntimeEvents
public void flushRuntimeEvents()Flush all currently buffered runtime rollups to the database, regardless of whether their time window has closed. Mostly useful for tests and for on-demand flushing. -
getRuntimeEventAggregator
Get theRuntimeEventAggregator.- Returns:
- the
RuntimeEventAggregator
-
getSettings
Get the resolvedEventPersistenceSettings.- Returns:
- the resolved settings
-
isActive
public boolean isActive()Check whether the feature is currently active.- Returns:
trueif the feature is active
-
startWebApp
public void startWebApp()Start the web app, reusing the host application'sSessionFactory. The bootstrap calls it automatically whenConfig.EventPersistence#setWebAppEnabled(true)is set, but it can also be called programmatically, regardless of that setting. It has no effect if the feature is not active or the web app is already running. Never throws. -
stopWebApp
public void stopWebApp()Stop the web app, if it is running, while keeping the event persistence feature active. Never throws. -
getWebAppUrl
Get the URL the web app is available at, ornullif it is not running.- Returns:
- the web app URL, or
null
-
stop
public void stop()Stop the feature, flushing any pending runtime rollups.
-