Class Globals
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 Summary
Modifier and TypeMethodDescriptionstatic AutoCloseablesetup()Fixes global data source registrations and initializes all registered globalDataSrcinstances in registration order.static AutoCloseablesetupWithOrder(String... names) Fixes global data source registrations and initializes all registered globalDataSrcinstances, prioritizing the specified setup order.static voidRegisters a globalDataSrcunder the specified name.
-
Method Details
-
uses
Registers a globalDataSrcunder the specified name.Registrations are ignored once
setup()orsetupWithOrder(String...)has been invoked. This method is not thread-safe: call it, together withsetup, from a single thread (typically themainmethod) before any other thread creates aDataHub. Because the JVM loads classes lazily, calling this method from a static initializer of another class may run it aftersetup, 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 sourceds- theDataSrcinstance to register
-
setup
Fixes global data source registrations and initializes all registered globalDataSrcinstances in registration order.If setup fails, any already initialized data sources are closed and an
ErrwithDataHubError.FailToSetupGlobalDataSrcsis 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
DataHubafter 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
AutoCloseableonly after allDataHubinstances and logic executions have finished. Data sources are closed in the reverse order of their setup.- Returns:
- an
AutoCloseablethat closes all global data sources when closed - Throws:
com.github.sttk.errs.Err- if setting up any global data source fails
-
setupWithOrder
Fixes global data source registrations and initializes all registered globalDataSrcinstances, prioritizing the specified setup order.Data sources whose names appear in
namesare initialized first in the given order, followed by the remaining registered data sources in registration order. Duplicate names innamesare 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 benull- Returns:
- an
AutoCloseablethat closes all global data sources when closed - Throws:
com.github.sttk.errs.Err- if setting up any global data source failsNullPointerException- ifnamesor any of its elements isnull
-