public abstract class AbstractComponentRegistry extends Object implements Lifecycle, Cloneable
getComponent(Class)
.
Components can be registered using registerComponent(Object, Class)
, which will cause any dependencies to be
wired in as well. Components that need to be created as a result of wiring will be done using getOrCreateComponent(Class)
, which will look up the default factory for the component type (factories annotated
with the appropriate DefaultFactoryFor
annotation.
Default factories are treated as components too and will need to be wired before being used.
The registry can exist in one of several states, as defined by the ComponentStatus
enumeration. In terms of the cache, state changes in the following manner: Lifecycle.start()
is calledLifecycle.stop()
is calledComponentStatus.RUNNING
state.
Thread Safety: instances of GlobalComponentRegistry
can be concurrently updated so all
the write operations are serialized through class intrinsic lock.Modifier and Type | Class and Description |
---|---|
class |
AbstractComponentRegistry.Component
A wrapper representing a component in the registry
|
Modifier and Type | Field and Description |
---|---|
static boolean |
DEBUG_DEPENDENCIES
Set the system property infinispan.debugDependencies to true to enable some extra information to
errors generated by the component factory.
|
protected ComponentStatus |
state |
Constructor and Description |
---|
AbstractComponentRegistry() |
Modifier and Type | Method and Description |
---|---|
protected void |
addShutdownHook() |
AbstractComponentRegistry |
clone() |
protected AbstractComponentFactory |
createComponentFactoryInternal(Class<?> componentClass,
String cfClass) |
<T> T |
getComponent(Class<T> type)
Retrieves a component of a specified type from the registry, or null if it cannot be found.
|
<T> T |
getComponent(Class<T> componentClass,
String name) |
<T> T |
getComponent(String componentClassName) |
<T> T |
getComponent(String componentClassName,
String name) |
<T> T |
getComponent(String componentClassName,
String name,
boolean nameIsFQCN) |
abstract ComponentMetadataRepo |
getComponentMetadataRepo() |
protected Configuration |
getConfiguration()
Retrieves the configuration component.
|
protected AbstractComponentFactory |
getFactory(Class<?> componentClass)
Retrieves a component factory instance capable of constructing components of a specified type.
|
protected abstract Log |
getLog() |
protected <T> T |
getOrCreateComponent(Class<T> componentClass)
Retrieves a 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). |
protected <T> T |
getOrCreateComponent(Class<T> componentClass,
String name) |
protected <T> T |
getOrCreateComponent(Class<T> componentClass,
String name,
boolean nameIsFQCN) |
Set<AbstractComponentRegistry.Component> |
getRegisteredComponents()
Returns an immutable set containing all the components that exists in the repository at this moment.
|
ComponentStatus |
getStatus()
Retrieves the state of the registry
|
boolean |
invocationsAllowed(boolean originLocal)
Asserts whether invocations are allowed on the cache or not.
|
protected AbstractComponentRegistry.Component |
lookupComponent(String componentClassName,
String componentName,
boolean nameIsFQCN) |
void |
registerComponent(Object component,
Class<?> type)
Registers a component in the registry under the given type, and injects any dependencies needed.
|
void |
registerComponent(Object component,
String name) |
void |
registerComponent(Object component,
String name,
boolean nameIsFQCN) |
protected void |
registerComponentInternal(Object component,
String name,
boolean nameIsFQCN) |
protected ClassLoader |
registerDefaultClassLoader(ClassLoader loader)
Registers the default class loader.
|
protected void |
registerNonVolatileComponent(Object component,
Class<?> type) |
protected void |
registerNonVolatileComponent(Object component,
String name) |
protected void |
registerNullComponent(String name)
registers a special "null" component that has no dependencies.
|
protected void |
removeShutdownHook() |
void |
resetVolatileComponents()
Removes any components not annotated as @SurvivesRestarts.
|
void |
rewire()
Rewires components.
|
void |
start()
This starts the components in the cache, connecting to channels, starting service threads, etc.
|
void |
stop()
Stops the cache and sets the cache status to
ComponentStatus.TERMINATED once it
is done. |
protected void |
throwStackAwareConfigurationException(String message) |
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 . |
public static final boolean DEBUG_DEPENDENCIES
protected volatile ComponentStatus state
public ComponentStatus getStatus()
protected abstract Log getLog()
public abstract ComponentMetadataRepo getComponentMetadataRepo()
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 Commands.target
- object to wireConfigurationException
- if there is a problem wiring the instancepublic final void registerComponent(Object component, Class<?> type)
component
- component to registertype
- type of componentpublic final void registerComponent(Object component, String name, boolean nameIsFQCN)
protected final void registerNonVolatileComponent(Object component, String name)
protected final void registerNonVolatileComponent(Object component, Class<?> type)
protected void registerComponentInternal(Object component, String name, boolean nameIsFQCN)
protected <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. 3. Look for a class definition passed in to the Configuration
-
such as an EvictionPolicy implementation 4. 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 constructing or wiring the instance.protected <T> T getOrCreateComponent(Class<T> componentClass, String name, boolean nameIsFQCN)
protected AbstractComponentFactory getFactory(Class<?> componentClass)
componentClass
- type of component to constructprotected AbstractComponentFactory createComponentFactoryInternal(Class<?> componentClass, String cfClass)
protected AbstractComponentRegistry.Component lookupComponent(String componentClassName, String componentName, boolean nameIsFQCN)
protected final void registerNullComponent(String name)
name
- name of component to register as a nullprotected Configuration getConfiguration()
public <T> T getComponent(Class<T> type)
type
- type to findpublic <T> T getComponent(String componentClassName)
protected ClassLoader 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 void rewire()
public void resetVolatileComponents()
public void start()
ComponentStatus.INITIALIZING
state, it will be initialized first.public void stop()
ComponentStatus.TERMINATED
once it
is done. If the cache is not in the ComponentStatus.RUNNING
state, this is a
no-op.protected void addShutdownHook()
protected void removeShutdownHook()
public boolean invocationsAllowed(boolean originLocal)
ComponentStatus.INITIALIZING
, this method will block for up to Configuration.getStateRetrievalTimeout()
millis, checking for a valid state.originLocal
- true if the call originates locally (i.e., from the CacheImpl
or false
if it originates remotely, i.e., from the InboundInvocationHandler
.public Set<AbstractComponentRegistry.Component> getRegisteredComponents()
public AbstractComponentRegistry clone() throws CloneNotSupportedException
clone
in class Object
CloneNotSupportedException
protected void throwStackAwareConfigurationException(String message)
Copyright © 2017 JBoss, a division of Red Hat. All Rights Reserved.