Class AbstractComponent<C,A extends C>

java.lang.Object
org.axonframework.common.configuration.AbstractComponent<C,A>
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

public abstract class AbstractComponent<C,A extends C> extends Object implements ComponentDefinition.ComponentCreator<C>, Component<C>
Base implementation of a Component and ComponentDefinition.ComponentCreator to simplify definition and creation of components through a ComponentDefinition.
Since:
3.0.0
Author:
Allard Buijze
  • 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 given identifier and given preconfigured startHandlers and shutdownHandlers lifecycle 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

      protected AbstractComponent(@Nonnull Component.Identifier<C> identifier)
      Initialize the component with given identifier.
      Parameters:
      identifier - The identifier of the component.
  • Method Details

    • createComponent

      public Component<C> createComponent()
      Description copied from interface: ComponentDefinition.ComponentCreator
      Create a component matching the requirements configured on this definition.

      Multiple invocations of this method should return the same instance.

      Specified by:
      createComponent in interface ComponentDefinition.ComponentCreator<C>
      Returns:
      A component based on this definition.
    • onStart

      public ComponentDefinition<C> onStart(int phase, @Nonnull ComponentLifecycleHandler<C> handler)
      Description copied from interface: ComponentDefinition
      Registers the given handler to be invoked during the startup lifecycle of the application in the given phase.
      Specified by:
      onStart in interface ComponentDefinition<C>
      Parameters:
      phase - The phase in which to invoke the given handler.
      handler - The start handler to execute on the component.
      Returns:
      A ComponentDefinition with the start handler defined.
    • onShutdown

      public ComponentDefinition<C> onShutdown(int phase, @Nonnull ComponentLifecycleHandler<C> handler)
      Description copied from interface: ComponentDefinition
      Registers the given handler to be invoked during the shutdown lifecycle of the application in the given phase.
      Specified by:
      onShutdown in interface ComponentDefinition<C>
      Parameters:
      phase - The phase in which to invoke the given handler.
      handler - The action to execute on the component.
      Returns:
      A ComponentDefinition with the shutdown handler defined.
    • identifier

      public Component.Identifier<C> identifier()
      Description copied from interface: Component
      The identifier of this component.
      Specified by:
      identifier in interface Component<C>
      Returns:
      The identifier of this component.
    • rawType

      public Class<C> rawType()
      Description copied from interface: ComponentDefinition
      Specified by:
      rawType in interface ComponentDefinition<C>
      Returns:
      The given type as a Class of this ComponentDefinition.
    • name

      @Nullable public String name()
      Description copied from interface: ComponentDefinition
      Returns the given name of this ComponentDefinition, set on ComponentDefinition.ofTypeAndName(Class, String).
      Specified by:
      name in interface ComponentDefinition<C>
      Returns:
      The given name of this ComponentDefinition.
    • resolve

      public C resolve(@Nonnull Configuration configuration)
      Description copied from interface: Component
      Resolves the instance of this component, allowing it to retrieve any of its required dependencies from the given configuration.

      Subsequent calls to this method will result in the same instance, even when different instances of configuration are provided.

      Specified by:
      resolve in interface Component<C>
      Parameters:
      configuration - The configuration that declared this component.
      Returns:
      The resolved instance defined in this component.
    • initLifecycle

      public void initLifecycle(@Nonnull Configuration configuration, @Nonnull LifecycleRegistry lifecycleRegistry)
      Description copied from interface: Component
      Initializes 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:
      initLifecycle in interface Component<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: Component
      Indicates whether the Component.initLifecycle(Configuration, LifecycleRegistry) method has already been invoked for this component.
      Specified by:
      isInitialized in interface Component<C>
      Returns:
      true if the component's lifecycle has been initialized, otherwise false.
    • describeTo

      public void describeTo(@Nonnull ComponentDescriptor descriptor)
      Description copied from interface: DescribableComponent
      Describe the properties of this DescribableComponent with the given descriptor.

      Components should call the appropriate describeProperty methods 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 DescribableComponent implementation 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 the describeTo method, 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:
      describeTo in interface DescribableComponent
      Parameters:
      descriptor - The component descriptor to describe this DescribableComponentn its properties in.