Class AbstractComponent<C,A extends C>
- Type Parameters:
C- The declared type of the component.A- The actual implementation type of the component.
- All Implemented Interfaces:
Component<C>,ComponentDefinition<C>,ComponentDefinition.ComponentCreator<C>,DescribableComponent
- Direct Known Subclasses:
InstantiatedComponentDefinition,LazyInitializedComponentDefinition
Component and
ComponentDefinition.ComponentCreator to simplify definition and creation of
components through a ComponentDefinition.- Since:
- 3.0.0
- Author:
- Allard Buijze
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordAn entry holding the lifecyclehandlerand its correspondingphase.Nested classes/interfaces inherited from interface org.axonframework.common.configuration.Component
Component.Identifier<C>Nested classes/interfaces inherited from interface org.axonframework.common.configuration.ComponentDefinition
ComponentDefinition.ComponentCreator<C>, ComponentDefinition.IncompleteComponentDefinition<C> -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractComponent(Component.Identifier<C> identifier) Initialize the component with givenidentifier.protectedAbstractComponent(Component.Identifier<C> identifier, List<AbstractComponent.HandlerRegistration<A>> startHandlers, List<AbstractComponent.HandlerRegistration<A>> shutdownHandlers) Initialize the component with givenidentifierand given preconfiguredstartHandlersandshutdownHandlerslifecycle handlers. -
Method Summary
Modifier and TypeMethodDescriptionCreate a component matching the requirements configured on this definition.voiddescribeTo(ComponentDescriptor descriptor) Describe the properties ofthis DescribableComponentwith the givendescriptor.The identifier of this component.voidinitLifecycle(Configuration configuration, LifecycleRegistry lifecycleRegistry) Initializes the lifecycle handlers associated with this component.booleanIndicates whether theComponent.initLifecycle(Configuration, LifecycleRegistry)method has already been invoked for this component.name()Returns the given name of thisComponentDefinition, set onComponentDefinition.ofTypeAndName(Class, String).onShutdown(int phase, ComponentLifecycleHandler<C> handler) Registers the givenhandlerto be invoked during the shutdown lifecycle of the application in the givenphase.onStart(int phase, ComponentLifecycleHandler<C> handler) Registers the givenhandlerto be invoked during the startup lifecycle of the application in the givenphase.rawType()Returns the giventype as a Classof thisComponentDefinition, set onComponentDefinition.ofType(Class)orComponentDefinition.ofTypeAndName(Class, String).resolve(Configuration configuration) Resolves the instance of this component, allowing it to retrieve any of its required dependencies from the givenconfiguration.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.Component
isInstantiatedMethods inherited from interface org.axonframework.common.configuration.ComponentDefinition
onShutdown, onShutdown, onStart, onStart
-
Constructor Details
-
AbstractComponent
protected AbstractComponent(@Nonnull Component.Identifier<C> identifier, @Nonnull List<AbstractComponent.HandlerRegistration<A>> startHandlers, @Nonnull List<AbstractComponent.HandlerRegistration<A>> shutdownHandlers) Initialize the component with givenidentifierand given preconfiguredstartHandlersandshutdownHandlerslifecycle handlers.- Parameters:
identifier- The identifier of the component.startHandlers- A list of preconfigured startup handlers for this component.shutdownHandlers- A list of preconfigured shutdown handlers for this component.
-
AbstractComponent
Initialize the component with givenidentifier.- Parameters:
identifier- The identifier of the component.
-
-
Method Details
-
createComponent
Description copied from interface:ComponentDefinition.ComponentCreatorCreate a component matching the requirements configured on this definition.Multiple invocations of this method should return the same instance.
- Specified by:
createComponentin interfaceComponentDefinition.ComponentCreator<C>- Returns:
- A component based on this definition.
-
onStart
Description copied from interface:ComponentDefinitionRegisters the givenhandlerto be invoked during the startup lifecycle of the application in the givenphase.- Specified by:
onStartin interfaceComponentDefinition<C>- Parameters:
phase- The phase in which to invoke the givenhandler.handler- The start handler to execute on the component.- Returns:
- A
ComponentDefinitionwith the start handler defined.
-
onShutdown
Description copied from interface:ComponentDefinitionRegisters the givenhandlerto be invoked during the shutdown lifecycle of the application in the givenphase.- Specified by:
onShutdownin interfaceComponentDefinition<C>- Parameters:
phase- The phase in which to invoke the givenhandler.handler- The action to execute on the component.- Returns:
- A
ComponentDefinitionwith the shutdown handler defined.
-
identifier
Description copied from interface:ComponentThe identifier of this component.- Specified by:
identifierin interfaceComponent<C>- Returns:
- The identifier of this component.
-
rawType
Description copied from interface:ComponentDefinitionReturns the giventype as a Classof thisComponentDefinition, set onComponentDefinition.ofType(Class)orComponentDefinition.ofTypeAndName(Class, String).- Specified by:
rawTypein interfaceComponentDefinition<C>- Returns:
- The given
type as a Classof thisComponentDefinition.
-
name
Description copied from interface:ComponentDefinitionReturns the given name of thisComponentDefinition, set onComponentDefinition.ofTypeAndName(Class, String).- Specified by:
namein interfaceComponentDefinition<C>- Returns:
- The given name of this
ComponentDefinition.
-
resolve
Description copied from interface:ComponentResolves the instance of this component, allowing it to retrieve any of its required dependencies from the givenconfiguration.Subsequent calls to this method will result in the same instance, even when different instances of
configurationare provided. -
initLifecycle
public void initLifecycle(@Nonnull Configuration configuration, @Nonnull LifecycleRegistry lifecycleRegistry) Description copied from interface:ComponentInitializes the lifecycle handlers associated with this component.Subsequent calls to this method will not result in additional invocations of the lifecycle handlers registered with this component.
- Specified by:
initLifecyclein interfaceComponent<C>- Parameters:
configuration- The configuration in which the component was defined, allowing retrieval of dependencies during the component's lifecycle.lifecycleRegistry- The registry in which to register the lifecycle handlers.
-
isInitialized
public boolean isInitialized()Description copied from interface:ComponentIndicates whether theComponent.initLifecycle(Configuration, LifecycleRegistry)method has already been invoked for this component.- Specified by:
isInitializedin interfaceComponent<C>- Returns:
trueif the component's lifecycle has been initialized, otherwisefalse.
-
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.
-