|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.jboss.cache.factories.ComponentRegistry
public class ComponentRegistry
A registry where components which have been created are stored. Components are stored as singletons, registered under a specific name. When retrieving components from the registry, callers may specify a component name or just the type of component needed (in which case the fully qualified class name is used as the component name).
Components can be retrieved from the registry usinggetComponent(Class)
, or they can be constructed using
getOrCreateComponent(String, Class)
which will scan for default factories and attempt to use such
factpries to create the component if needed.
Default factories are treated as components too and will need to be wired and started before being used.
Components can exist in one of 4 states, as defined by the ComponentRegistry.State
enumeration. The component registry also
has a state for the overall component set. While some components may move to the ComponentRegistry.State.STARTED
state before others (such as factories to create other components) the ComponentRegistry's overall state depicts the lowest
possible form for all components.
In terms of the cache, overall state changes in the following manner:
Cache.create()
is calledCache.start()
is calledCache.stop()
is calledCacheStatus.STARTED
state.
Nested Class Summary | |
---|---|
static class |
ComponentRegistry.State
Represents the state of a component |
Constructor Summary | |
---|---|
ComponentRegistry(Configuration configuration)
Creates an instance of the component registry. |
Method Summary | ||
---|---|---|
protected void |
addComponentDependencies(org.jboss.cache.factories.ComponentRegistry.Component c,
boolean firstTimeAdded)
|
|
|
getComponent(Class<T> c)
|
|
|
getComponent(String name,
Class<T> c)
Retrieves a named component which can be assigned to the type passed in. |
|
protected ComponentFactory |
getFactory(Class componentClass)
Retrieves a component factory instance capable of constructing components of a specified type. |
|
|
getOrCreateComponent(Class<T> componentClass)
Retrieves a named component if one exists, and if not, attempts to find a factory capable of constructing the component (factories annotated with the DefaultFactoryFor annotation that is capable
of creating the component class). |
|
|
getOrCreateComponent(String componentName,
Class<T> componentClass)
Retrieves a named component if one exists, and if not, attempts to find a factory capable of constructing the component (factories annotated with the DefaultFactoryFor annotation that is capable
of creating the component class). |
|
ComponentRegistry.State |
getOverallState()
|
|
void |
registerComponent(Object component,
Class type)
Adds a singleton instance to the registry. |
|
void |
registerComponent(String name,
Object component,
Class type)
Adds an instance component to the registry, registering the component under the given name. |
|
void |
registerDefaultClassLoader(ClassLoader loader)
Registers the default class loader. |
|
void |
reset()
Wipes everything in the registry. |
|
void |
start()
Starts all components that contain the Start annotation. |
|
void |
stop()
Stops all components that contain the Stop annotation. |
|
void |
unregisterComponent(Class<?> clazz)
Removes a component from the registry. |
|
void |
unregisterComponent(String name)
Removes a component from the registry. |
|
void |
updateDependencies()
Updates (re-injects) any dependencies needed by all components already in the registry. |
|
void |
wire()
Injects dependencies to all components that require injection. |
|
void |
wireDependencies(Object target)
Wires an object instance with dependencies annotated with the Inject annotation, creating more components
as needed based on the Configuration passed in if these additional components don't exist in the
ComponentRegistry . |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public ComponentRegistry(Configuration configuration)
configuration
- Method Detail |
---|
public void registerDefaultClassLoader(ClassLoader loader)
loader
- a class loader to use by default. If this is null, the class loader used to load this instance of ComponentRegistry is used.public ComponentRegistry.State getOverallState()
public void registerComponent(Object component, Class type)
registerComponent(String, Object, Class)
The status of the component is updated th the overall state of the registry, which may involve calling of methods annotated
with Inject
, Start
or
Stop
.
component
- component to add to the registry.public void registerComponent(String name, Object component, Class type)
Inject
, Start
or
Stop
.
name
- name of the instancecomponent
- component to addprotected void addComponentDependencies(org.jboss.cache.factories.ComponentRegistry.Component c, boolean firstTimeAdded)
public <T> T getComponent(Class<T> c)
public <T> T getComponent(String name, Class<T> c)
c
- type to be able to assign component to.
public <T> T getOrCreateComponent(Class<T> componentClass)
DefaultFactoryFor
annotation that is capable
of creating the component class).
If an instance needs to be constructed, dependencies are then automatically wired into the instance, based on methods
on the component type annotated with Inject
.
Summing it up, component retrieval happens in the following order:Configuration
that may be injected from an external system.
2. Look for a class definition passed in to the Configuration
- such as an EvictionPolicy implementation
3. Attempt to create it by looking for an appropriate factory (annotated with DefaultFactoryFor
)
componentClass
- type of component to be retrieved. Should not be null.
ConfigurationException
- if there is a problem with consructing or wiring the instance.public <T> T getOrCreateComponent(String componentName, Class<T> componentClass)
DefaultFactoryFor
annotation that is capable
of creating the component class).
If an instance needs to be constructed, dependencies are then automatically wired into the instance, based on methods
on the component type annotated with Inject
.
Summing it up, component retrieval happens in the following order:Configuration
that may be injected from an external system.
2. Look for a class definition passed in to the Configuration
- such as an EvictionPolicy implementation
3. Attempt to create it by looking for an appropriate factory (annotated with DefaultFactoryFor
)
componentName
- name of component to be created. If null, uses the fully qualified class name as component name.componentClass
- type of component to be retrieved. Should not be null.
ConfigurationException
- if there is a problem with consructing or wiring the instance.public void updateDependencies()
public void unregisterComponent(Class<?> clazz)
updateDependencies()
to ensure dependencies are updated.
clazz
- class of component to remove.public void unregisterComponent(String name)
updateDependencies()
to ensure dependencies are updated.
name
- name of the component to remove.public void wireDependencies(Object target) throws ConfigurationException
Inject
annotation, creating more components
as needed based on the Configuration passed in if these additional components don't exist in the
ComponentRegistry
. Strictly for components that don't otherwise live in the registry and have a lifecycle, such as Nodes.
target
- object to wire
ConfigurationException
- if there is a problem wiring the instanceprotected ComponentFactory getFactory(Class componentClass)
ComponentRegistry.State.STARTED
before returning.
componentClass
- type of component to construct
public void reset()
public void start()
Start
annotation.
public void stop()
Stop
annotation.
public void wire()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |