Class Globals

java.lang.Object
com.github.sttk.sabi.Globals

public final class Globals extends Object
Manages global DataSrc registrations and their lifecycle for the sabi framework.

Global data sources are registered via uses(String, DataSrc) before calling setup() or setupWithOrder(String...). Once setup completes, the registered global data sources are inherited by subsequently created DataHub instances until the AutoCloseable returned by setup is closed.

  • Method Details

    • uses

      public static void uses(String name, DataSrc ds)
      Registers a global DataSrc under the specified name.

      Registrations are ignored once setup() or setupWithOrder(String...) has been invoked. This method is not thread-safe: call it, together with setup, from a single thread (typically the main method) before any other thread creates a DataHub. Because the JVM loads classes lazily, calling this method from a static initializer of another class may run it after setup, in which case the registration is silently ignored.

      If the same name is registered more than once, only the first registration is used. Later ones are neither set up nor closed.

      Parameters:
      name - the logical name of the data source
      ds - the DataSrc instance to register
    • setup

      public static AutoCloseable setup() throws com.github.sttk.errs.Err
      Fixes global data source registrations and initializes all registered global DataSrc instances in registration order.

      If setup fails, any already initialized data sources are closed and an Err with DataHubError.FailToSetupGlobalDataSrcs is thrown. Global setup cannot be retried after a failure, and the global data sources are unavailable, so the application is expected to terminate. Calling this method again after a failure does not throw and does not set anything up.

      Once setup completes, the global data sources are never modified, so they can be read by multiple threads. Start any thread that creates a DataHub after this method returns. This method itself is not thread-safe, and only the first call performs the setup; later calls have no effect and return another handle that closes the same global data sources.

      Close the returned AutoCloseable only after all DataHub instances and logic executions have finished. Data sources are closed in the reverse order of their setup.

      Returns:
      an AutoCloseable that closes all global data sources when closed
      Throws:
      com.github.sttk.errs.Err - if setting up any global data source fails
    • setupWithOrder

      public static AutoCloseable setupWithOrder(String... names) throws com.github.sttk.errs.Err
      Fixes global data source registrations and initializes all registered global DataSrc instances, prioritizing the specified setup order.

      Data sources whose names appear in names are initialized first in the given order, followed by the remaining registered data sources in registration order. Duplicate names in names are ignored (the first occurrence is used), and names with no registered data source are skipped.

      The failure handling, thread-safety, and closing rules are the same as those of setup().

      Parameters:
      names - the ordered logical names of global data sources to initialize first; neither the array nor its elements may be null
      Returns:
      an AutoCloseable that closes all global data sources when closed
      Throws:
      com.github.sttk.errs.Err - if setting up any global data source fails
      NullPointerException - if names or any of its elements is null