public final class StorageFactorySwitch extends java.lang.Object implements java.util.function.Supplier<StorageFactory>
StorageFactorythat takes into account if the code runs under tests on in the production mode.
In the production mode this class obtains the instance provided by the
StorageFactorySwitch.init(Supplier, Supplier). If the production
Supplier was not initialized,
IllegalStateException will be thrown.
StorageFactory obtained from suppliers.
In both modes the reference to the
StorageFactory obtained from a
will be stored. This means that a call to
Supplier.get() method of
the suppliers passed via
StorageFactorySwitch.init(Supplier, Supplier) will be made only once.
|Modifier and Type||Method and Description|
Initializes the current singleton instance with the suppliers.
Obtains the instance of the switch that corresponds to multi-tenancy mode.
public static StorageFactorySwitch newInstance(io.spine.core.BoundedContextName boundedContextName, boolean multitenant)
boundedContextName- the name of the bounded context in which this switch works
truethe switch is requested for the multi-tenant execution context,
falsefor the single-tenant context
@CanIgnoreReturnValue public StorageFactorySwitch init(java.util.function.Supplier<StorageFactory> productionSupplier, @Nullable java.util.function.Supplier<StorageFactory> testsSupplier)
productionSupplier- the supplier for the production mode
testsSupplier- the supplier for the tests mode. If
InMemoryStorageFactorywill be used
public StorageFactory get()
StorageFactoryfor the current execution mode.