Class EventPersistenceContext

java.lang.Object
io.hypersistence.optimizer.core.event.persistence.EventPersistenceContext

public class EventPersistenceContext extends Object
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 Details

  • Method Details

    • start

      public boolean start()
      Start the runtime aggregator after the bootstrap scanner has prepared the schema. The web app is started separately, via startWebApp().
      Returns:
      true if the feature started successfully, false otherwise
    • persistBootstrapEvents

      public void persistBootstrapEvents(String hibernateVersion, List<Event> bootstrapEvents)
      Persist the configuration and mapping events collected during scanning, as a single run.
      Parameters:
      hibernateVersion - the current Hibernate version
      bootstrapEvents - the collected configuration and mapping events
    • getEventHandler

      public EventHandler getEventHandler()
      Get the EventHandler that 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

      public RuntimeEventAggregator getRuntimeEventAggregator()
      Returns:
      the RuntimeEventAggregator
    • getSettings

      public EventPersistenceSettings getSettings()
      Get the resolved EventPersistenceSettings.
      Returns:
      the resolved settings
    • isActive

      public boolean isActive()
      Check whether the feature is currently active.
      Returns:
      true if the feature is active
    • startWebApp

      public void startWebApp()
      Start the web app, reusing the host application's SessionFactory. The bootstrap calls it automatically when Config.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

      public String getWebAppUrl()
      Get the URL the web app is available at, or null if it is not running.
      Returns:
      the web app URL, or null
    • stop

      public void stop()
      Stop the feature, flushing any pending runtime rollups.