Class DefaultComponentRegistry
- All Implemented Interfaces:
ComponentRegistry,DescribableComponent
ComponentRegistry allowing for reuse of Component,
ComponentDecorator, ConfigurationEnhancer, and Module registration for the
ApplicationConfigurer and Module implementations alike.- Since:
- 5.0.0
- Author:
- Allard Buijze, Steven van Beelen
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbuild(LifecycleRegistry lifecycleRegistry) Builds theConfigurationfrom thisComponentRegistryas a root configuration.buildNested(Configuration parent, LifecycleRegistry lifecycleRegistry) Builds theConfigurationfrom thisComponentRegistryas a nested configuration under the givenparent.voiddescribeTo(ComponentDescriptor descriptor) Describe the properties ofthis DescribableComponentwith the givendescriptor.disableEnhancer(Class<? extends ConfigurationEnhancer> enhancerClass) Disables the givenConfigurationEnhancerclass from executing during the configuration initialization phase.disableEnhancer(String fullyQualifiedClassName) Disables the givenConfigurationEnhancerclass from executing during the configuration initialization phase.Completely disables scanning for enhancers on the classpath through theServiceLoadermechanism.booleanhasComponent(Class<?> type, String name, SearchScope searchScope) Check whether there is aComponentregistered with thisConfigurerfor the giventypeandnamecombination.registerComponent(ComponentDefinition<? extends C> definition) Registers aComponentbased on the givendefinition.registerDecorator(DecoratorDefinition<C, ? extends C> definition) Registers a decorator based on the givendefinition.registerEnhancer(ConfigurationEnhancer enhancer) Registers anConfigurationEnhancerwith thisComponentRegistry.registerFactory(ComponentFactory<C> factory) Registers aComponentFactorywith this registry.registerModule(Module module) Registers aModulewith this registry.setOverridePolicy(OverridePolicy overridePolicy) Sets theOverridePolicyfor thisComponentRegistry.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.axonframework.common.configuration.ComponentRegistry
hasComponent, hasComponent, hasComponent, registerComponent, registerComponent, registerDecorator, registerDecorator, registerIfNotPresent, registerIfNotPresent, registerIfNotPresent, registerIfNotPresent, registerIfNotPresent, registerIfNotPresent
-
Constructor Details
-
DefaultComponentRegistry
public DefaultComponentRegistry()
-
-
Method Details
-
registerComponent
public <C> ComponentRegistry registerComponent(@Nonnull ComponentDefinition<? extends C> definition) Description copied from interface:ComponentRegistryRegisters aComponentbased on the givendefinition.- Specified by:
registerComponentin interfaceComponentRegistry- Type Parameters:
C- The declared type of the component.- Parameters:
definition- The definition of the component to register.- Returns:
- The current instance of the
Configurerfor a fluent API.
-
registerDecorator
public <C> ComponentRegistry registerDecorator(@Nonnull DecoratorDefinition<C, ? extends C> definition) Description copied from interface:ComponentRegistryRegisters a decorator based on the givendefinition.- Specified by:
registerDecoratorin interfaceComponentRegistry- Type Parameters:
C- The declared type of the component(s) to decorate.- Parameters:
definition- The definition of the decorator to apply to components.- Returns:
- The current instance of the
Configurerfor a fluent API. - See Also:
-
hasComponent
public boolean hasComponent(@Nonnull Class<?> type, @Nullable String name, @Nonnull SearchScope searchScope) Description copied from interface:ComponentRegistryCheck whether there is aComponentregistered with thisConfigurerfor the giventypeandnamecombination.The given
searchScopeis used to define if the search only checks thecurrentregistry, only checks allancestors, or checksboththe current registry and all ancestors.- Specified by:
hasComponentin interfaceComponentRegistry- Parameters:
type- The type of theComponentto check if it exists, typically an interface.name- The name of theComponentto check if it exists. Usenullwhen there is no name or useComponentRegistry.hasComponent(Class)instead.searchScope- The enumeration defining the search scope used to check if this registry has aComponent.- Returns:
truewhen there is aComponentregistered under the giventypeandname combination,falseotherwise.
-
registerEnhancer
Description copied from interface:ComponentRegistryRegisters anConfigurationEnhancerwith thisComponentRegistry.An
enhanceris able to invoke any of the methods on thisComponentRegistry, allowing it to add (sensible) defaults, decoratecomponents, or replace components entirely.An enhancer's
ConfigurationEnhancer.enhance(ComponentRegistry)method is invoked during the initialization phase when all components have been defined. This is right before theComponentRegistrycreates itsConfiguration.When multiple enhancers have been provided, their
ConfigurationEnhancer.order()dictates the enhancement order. For enhancer with the same order, the order of execution is undefined.- Specified by:
registerEnhancerin interfaceComponentRegistry- Parameters:
enhancer- The configuration enhancer to enhance ComponentRegistry duringApplicationConfigurer.build().- Returns:
- The current instance of the
Configurerfor a fluent API.
-
registerModule
Description copied from interface:ComponentRegistryRegisters aModulewith this registry.Note that a
Moduleis able to access the components defined in thisComponentRegistryupon construction, but not vice versa. As such, theModulemaintains encapsulation.- Specified by:
registerModulein interfaceComponentRegistry- Parameters:
module- The module builder function to register.- Returns:
- The current instance of the
ComponentRegistryfor a fluent API.
-
registerFactory
Description copied from interface:ComponentRegistryRegisters aComponentFactorywith this registry.If the
Configurationthat will contain this registry does not have a component for a givenClassand name combination, it will consult all registered component factories. Only if a givenfactorycan produce therequested typewillComponentFactory.construct(String, Configuration)be invoked. When thefactorydecides to construct a new component, it will be stored in theConfigurationfor future reference to ensure it's not constructed again.- Specified by:
registerFactoryin interfaceComponentRegistry- Type Parameters:
C- The component type constructed by the givenfactory.- Parameters:
factory- The component factory to register.- Returns:
- The current instance of the
ComponentRegistryfor a fluent API.
-
build
Builds theConfigurationfrom thisComponentRegistryas a root configuration.The given
lifecycleRegistryis used to register components' lifecycle methods.- Parameters:
lifecycleRegistry- The registry where lifecycle handlers are registered.- Returns:
- A fully initialized configuration exposing all configured components.
-
buildNested
public Configuration buildNested(@Nonnull Configuration parent, @Nonnull LifecycleRegistry lifecycleRegistry) Builds theConfigurationfrom thisComponentRegistryas a nested configuration under the givenparent.Components registered in the
parentare available to components registered in this registry, but not vice versa. The givenlifecycleRegistryis used to register components' lifecycle methods.- Parameters:
parent- The parent configuration.lifecycleRegistry- The registry where lifecycle handlers are registered.- Returns:
- A fully initialized configuration exposing all configured components.
-
setOverridePolicy
Description copied from interface:ComponentRegistrySets theOverridePolicyfor thisComponentRegistry.This policy dictates what should happen when components are registered with an identifier for which another component is already present.
- Specified by:
setOverridePolicyin interfaceComponentRegistry- Parameters:
overridePolicy- The override policy for components defined in this registry.- Returns:
- The current instance of the
Configurerfor a fluent API.
-
disableEnhancer
Description copied from interface:ComponentRegistryDisables the givenConfigurationEnhancerclass from executing during the configuration initialization phase. This affects both enhancers registered through theServiceLoadermechanism and those registered programmatically viaComponentRegistry.registerEnhancer(ConfigurationEnhancer).Only specific classes can be disabled, and class hierarchies are not taken into account. If the enhancer has already been invoked when this method is called, disabling will have no effect and a warning will be logged.
This method is typically called from within another enhancer's
ConfigurationEnhancer.enhance(ComponentRegistry)method to prevent subsequent enhancers from executing.If the class cannot be found on the classpath, a warning will be logged and the call will have no effect.
- Specified by:
disableEnhancerin interfaceComponentRegistry- Parameters:
fullyQualifiedClassName- The fully qualified class name of the enhancer to disable.- Returns:
- The current instance of the
Configurerfor a fluent API.
-
disableEnhancer
public DefaultComponentRegistry disableEnhancer(Class<? extends ConfigurationEnhancer> enhancerClass) Description copied from interface:ComponentRegistryDisables the givenConfigurationEnhancerclass from executing during the configuration initialization phase. This affects both enhancers registered through theServiceLoadermechanism and those registered programmatically viaComponentRegistry.registerEnhancer(ConfigurationEnhancer).Only specific classes can be disabled, and class hierarchies are not taken into account. If the enhancer has already been invoked when this method is called, disabling will have no effect and a warning will be logged.
This method is typically called from within another enhancer's
ConfigurationEnhancer.enhance(ComponentRegistry)method to prevent subsequent enhancers from executing.- Specified by:
disableEnhancerin interfaceComponentRegistry- Parameters:
enhancerClass- The class of the enhancer to disable.- Returns:
- The current instance of the
Configurerfor a fluent API.
-
disableEnhancerScanning
Description copied from interface:ComponentRegistryCompletely disables scanning for enhancers on the classpath through theServiceLoadermechanism. Note that this may lead to missing framework functionality. It is recommended to disable specific enhancers throughComponentRegistry.disableEnhancer(Class)instead. Does not affect enhancers that are registered through theComponentRegistry.registerEnhancer(ConfigurationEnhancer)method.- Specified by:
disableEnhancerScanningin interfaceComponentRegistry- Returns:
- The current instance of the
Configurerfor a fluent API.
-
describeTo
Description copied from interface:DescribableComponentDescribe the properties ofthis DescribableComponentwith the givendescriptor.Components should call the appropriate
describePropertymethods on the descriptor to register their properties. The descriptor is responsible for determining how these properties are formatted and structured in the final output.Best Practices: As a general rule, all relevant fields of a
DescribableComponentimplementation should be described in this method. However, developers have discretion to include only the fields that make sense in the context. Not every field may be meaningful for description purposes, especially internal implementation details. Furthermore, components might want to expose different information based on their current state. The final decision on what properties to include lies with the person implementing thedescribeTomethod, who should focus on providing information that is useful for understanding the component's configuration and state.Example implementation:
public void describeTo(ComponentDescriptor descriptor) { descriptor.describeProperty("name", this.name); descriptor.describeProperty("enabled", this.enabled); descriptor.describeProperty("configuration", this.configuration); // A nested component descriptor.describeProperty("handlers", this.eventHandlers); // A collection }- Specified by:
describeToin interfaceDescribableComponent- Parameters:
descriptor- The component descriptor to describethis DescribableComponentn its properties in.
-