public class BasicComponentRegistryImpl extends Object implements BasicComponentRegistry
Constructor and Description |
---|
BasicComponentRegistryImpl(ModuleRepository moduleRepository,
boolean isGlobal,
BasicComponentRegistry next) |
Modifier and Type | Method and Description |
---|---|
void |
addDynamicDependency(String ownerComponentName,
String dependencyComponentName)
Add a dynamic dependency between two components.
|
<T,U extends T> |
getComponent(String name,
Class<U> componentType)
Looks up a running component named
name in the registry, or registers it if necessary. |
MBeanMetadata |
getMBeanMetadata(String className) |
Collection<ComponentRef<?>> |
getRegisteredComponents()
Run
consumer for each registered component in the current scope. |
boolean |
hasComponentAccessor(String componentClassName)
Check if a component accessor has been registered for class
componentClassName |
<T> ComponentRef<T> |
lazyGetComponent(Class<T> componentType)
Looks up a component named
name in the registry, or registers it if necessary. |
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 named
componentName . |
void |
replaceComponent(String componentName,
Object newInstance,
boolean manageLifecycle)
Replace an existing component.
|
void |
rewire()
Rewire all the injections after a component was replaced with
BasicComponentRegistry.replaceComponent(String, Object, boolean) . |
void |
stop()
Stop the registry and all the components that have been started.
|
String |
toString() |
void |
wireDependencies(Object target,
boolean startDependencies)
Look up the dependencies of
target as if it were a component, and inject them. |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
getComponent, registerComponent
public BasicComponentRegistryImpl(ModuleRepository moduleRepository, boolean isGlobal, BasicComponentRegistry next)
public <T,U extends T> ComponentRef<T> getComponent(String name, Class<U> componentType)
BasicComponentRegistry
name
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.
getComponent
in interface BasicComponentRegistry
name
- The component name.componentType
- The expected component type, not used to identify the component.public <T> ComponentRef<T> lazyGetComponent(Class<T> componentType)
BasicComponentRegistry
name
in the registry, or registers it if necessary.
The component isn't instantiated neither running. Invoke ComponentRef.running()
to instantiate and start it.lazyGetComponent
in interface BasicComponentRegistry
componentType
- The expected component type, not used to identify the component.public MBeanMetadata getMBeanMetadata(String className)
getMBeanMetadata
in interface BasicComponentRegistry
className
public void wireDependencies(Object target, boolean startDependencies)
BasicComponentRegistry
target
as if it were a component, and inject them.
Behaves as if every dependency was resolved with getComponent(String, Class)
.
wireDependencies
in interface BasicComponentRegistry
target
- An instance of a class with Inject
annotations.startDependencies
- If true
, start the dependencies before injecting them.public <T> ComponentRef<T> registerComponent(String componentName, T instance, boolean manageLifecycle)
BasicComponentRegistry
componentName
.
If the component has dependencies, look them up using BasicComponentRegistry.getComponent(String, Class)
and inject them.
registerComponent
in interface BasicComponentRegistry
componentName
- The component name.instance
- The component instance.manageLifecycle
- false
if the registry should ignore methods annotated with
Start and Stoppublic void registerAlias(String aliasName, String targetComponentName, Class<?> targetComponentType)
BasicComponentRegistry
Components that depend on the alias will behave as if they depended on the original component directly.
registerAlias
in interface BasicComponentRegistry
public void addDynamicDependency(String ownerComponentName, String dependencyComponentName)
BasicComponentRegistry
addDynamicDependency
in interface BasicComponentRegistry
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.
public void replaceComponent(String componentName, Object newInstance, boolean manageLifecycle)
BasicComponentRegistry
Dependencies will be injected, and the start/stop methods will run if manageLifecycle
is true
.
The new component is stopped exactly when the replaced component would have been stopped,
IGNORING DEPENDENCY CHANGES.
Need to call BasicComponentRegistry.rewire()
to inject the new component in all the components that depend on it.
If the component is global, need to call BasicComponentRegistry.rewire()
on all the cache component registries as well.
replaceComponent
in interface BasicComponentRegistry
public void rewire()
BasicComponentRegistry
BasicComponentRegistry.replaceComponent(String, Object, boolean)
.
For testing purposes only.rewire
in interface BasicComponentRegistry
public Collection<ComponentRef<?>> getRegisteredComponents()
BasicComponentRegistry
consumer
for each registered component in the current scope.getRegisteredComponents
in interface BasicComponentRegistry
public void stop()
BasicComponentRegistry
Components cannot be instantiated or started after this.
stop
in interface BasicComponentRegistry
public boolean hasComponentAccessor(String componentClassName)
BasicComponentRegistry
componentClassName
hasComponentAccessor
in interface BasicComponentRegistry
Copyright © 2021 JBoss by Red Hat. All rights reserved.