Class BasicComponentRegistryImpl
- java.lang.Object
-
- org.infinispan.factories.impl.BasicComponentRegistryImpl
-
- All Implemented Interfaces:
BasicComponentRegistry
public class BasicComponentRegistryImpl extends Object implements BasicComponentRegistry
- Since:
- 8.2
- Author:
- Dan Berindei
-
-
Constructor Summary
Constructors Constructor Description BasicComponentRegistryImpl(ClassLoader classLoader, ComponentMetadataRepo metadataRepo, Scopes scope, BasicComponentRegistry next)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addDynamicDependency(String ownerComponentName, String dependencyComponentName)
Add a dynamic dependency between two components.<T> ComponentRef<T>
getComponent(String name, Class<T> componentType)
Looks up a running component namedname
in the registry, or registers it if necessary.<T> ComponentRef<T>
getComponent0(String name, Class<T> componentType, boolean needInstance)
Collection<ComponentRef<?>>
getRegisteredComponents()
Runconsumer
for each registered component in the current scope.void
registerAlias(String aliasName, String targetComponentName, Class<?> targetComponentType)
Register an alias to another component.<T> ComponentRef<T>
registerComponent(String componentName, T instance, boolean manageLifecycle)
Register a component namedcomponentName
.void
replaceComponent(String componentName, Object newInstance, boolean manageLifecycle)
Replace an existing component.void
rewire()
Rewire all the injections after a component was replaced withBasicComponentRegistry.replaceComponent(String, Object, boolean)
.void
stop()
void
wireDependencies(Object target, boolean startDependencies)
Look up the dependencies oftarget
as if it were a component, and inject them.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.infinispan.factories.impl.BasicComponentRegistry
getComponent, registerComponent
-
-
-
-
Constructor Detail
-
BasicComponentRegistryImpl
public BasicComponentRegistryImpl(ClassLoader classLoader, ComponentMetadataRepo metadataRepo, Scopes scope, BasicComponentRegistry next)
-
-
Method Detail
-
getComponent
public <T> ComponentRef<T> getComponent(String name, Class<T> componentType)
Description copied from interface:BasicComponentRegistry
Looks up a running component namedname
in the registry, or registers it if necessary.If another thread is registering the component, wait for the other thread to finish.
The component is wired (dependencies are injected) during registration. Use
ComponentRef.running()
to start the component.- Specified by:
getComponent
in interfaceBasicComponentRegistry
- Parameters:
name
- The component name.componentType
- The expected component type, not used to identify the component.
-
getComponent0
public <T> ComponentRef<T> getComponent0(String name, Class<T> componentType, boolean needInstance)
-
wireDependencies
public void wireDependencies(Object target, boolean startDependencies)
Description copied from interface:BasicComponentRegistry
Look up the dependencies oftarget
as if it were a component, and inject them.Behaves as if every dependency was resolved with
getComponent(String, Class)
.- Specified by:
wireDependencies
in interfaceBasicComponentRegistry
- Parameters:
target
- An instance of a class withInject
annotations.startDependencies
- Iftrue
, start the dependencies before injecting them.
-
registerComponent
public <T> ComponentRef<T> registerComponent(String componentName, T instance, boolean manageLifecycle)
Description copied from interface:BasicComponentRegistry
Register a component namedcomponentName
.If the component has dependencies, look them up using
BasicComponentRegistry.getComponent(String, Class)
and inject them.- Specified by:
registerComponent
in interfaceBasicComponentRegistry
- Parameters:
componentName
- The component name.instance
- The component instance.manageLifecycle
-false
if the registry should ignore methods annotated with Start and Stop
-
registerAlias
public void registerAlias(String aliasName, String targetComponentName, Class<?> targetComponentType)
Description copied from interface:BasicComponentRegistry
Register an alias to another component.Components that depend on the alias will behave as if they depended on the original component directly.
- Specified by:
registerAlias
in interfaceBasicComponentRegistry
-
addDynamicDependency
public void addDynamicDependency(String ownerComponentName, String dependencyComponentName)
Description copied from interface:BasicComponentRegistry
Add a dynamic dependency between two components.- Specified by:
addDynamicDependency
in interfaceBasicComponentRegistry
- Parameters:
ownerComponentName
- The dependent component's name.dependencyComponentName
- The component depended on.Note: doesn't have any effect if the owner component is already started. The stop order is determined exclusively by the start order.
-
replaceComponent
public void replaceComponent(String componentName, Object newInstance, boolean manageLifecycle)
Description copied from interface:BasicComponentRegistry
Replace an existing component. For testing purposes only, NOT THREAD-SAFE.Dependencies will be injected, and the start/stop methods will run if
manageLifecycle
istrue
. The new component is stopped exactly when the replaced component would have been stopped, IGNORING DEPENDENCY CHANGES. Need to callBasicComponentRegistry.rewire()
to inject the new component in all the components that depend on it. If the component is global, need to callBasicComponentRegistry.rewire()
on all the cache component registries as well.- Specified by:
replaceComponent
in interfaceBasicComponentRegistry
-
rewire
public void rewire()
Description copied from interface:BasicComponentRegistry
Rewire all the injections after a component was replaced withBasicComponentRegistry.replaceComponent(String, Object, boolean)
. For testing purposes only.- Specified by:
rewire
in interfaceBasicComponentRegistry
-
getRegisteredComponents
public Collection<ComponentRef<?>> getRegisteredComponents()
Description copied from interface:BasicComponentRegistry
Runconsumer
for each registered component in the current scope.- Specified by:
getRegisteredComponents
in interfaceBasicComponentRegistry
-
stop
public void stop()
- Specified by:
stop
in interfaceBasicComponentRegistry
-
-