public class GlobalBus extends Object
A globally accessible dependency injection container with service lookup capabilities.
The container is usually initialized from the class path and looks for a file called "/com/escenic/configuraion/bootstrap/Nursery.properties". This file must be define a component of the class neo.nursery.Bootstrapper pointing to the different configuration layers that should be used by the global bus.
If this file does not exist, the GlobalBus will not load.
Instead of loading the different layers from the class path, it is possible to bootstrap the configuration using the system property "com.escenic.configuration.bootstrap.layers". If set, it must be a path specification (i.e. separated by File.PATH_SEPARATOR) each pointing to either a directory or a ZIP compressed file.
PropertyFileConfigurator
Modifier and Type | Method and Description |
---|---|
static Bus |
createBus(Configurator configurator) |
static void |
createTestBus(Configurator configurator)
Create a global bus from scratch if there is no global bus
created before, or if the system has been wired for test earlier.
|
static String |
getComponentNameFor(Object component)
Returns the name of a given component, or null if the component does not
exist.
|
static Bus |
getGlobalBus()
Returns the single global bus, a form of Singleton object.
|
static <O> O |
lookup(String name)
Returns the object defined by the given name.
|
static <O> O |
lookupSafe(String name)
Returns the object defined by the given name.
|
static void |
main(String[] args) |
public static Bus getGlobalBus() throws BusException
BusException
- When the instantiation of the specific bus fails.public static String getComponentNameFor(Object component)
Bus.getComponentNameFor()
public static <O> O lookupSafe(String name)
lookup
method of the Bus.name
- the name of the objectBusImpl.lookup(java.lang.String)
public static <O> O lookup(String name) throws BusException
lookup
method of the Bus.name
- the name of the objectBusException
- if the object does not exist or if the name is nullBusImpl.lookup(java.lang.String)
public static Bus createBus(Configurator configurator)
public static void createTestBus(Configurator configurator) throws BusException
This test bus is for use in closed testing environments
who set up MemoryConfigurator
s:
Properties props; props = new Properties(); props.put("$class", "neo.nursery.Initial"); props.put("service.1", "/my/first/component"); props.put("service.2", "/my/second/component"); MemoryConfigurator mc = new MemoryConfigurator(); mc.add("/Initial",props); GlobalBus.createTestBus(mc); GlobalBus.lookup("/my/first/component");
BusException
public static void main(String[] args) throws BusException
BusException
© 1998- 2021 Escenic AS