Class Components

java.lang.Object
org.axonframework.common.configuration.Components
All Implemented Interfaces:
DescribableComponent

@Internal public class Components extends Object implements DescribableComponent
Wrapper around a Map of Components stored per Component.Identifier.

Provides a cleaner interface to the ComponentRegistry and Configuration when interacting with the configured Components.

Since:
5.0.0
Author:
Steven van Beelen
  • Constructor Details

    • Components

      public Components()
  • Method Details

    • get

      @Nonnull public <C> Optional<Component<C>> get(@Nonnull Component.Identifier<C> identifier)
      Get an Optional on the Component registered under the given identifier.

      When no exact match is found with the given identifier, a Class.isAssignableFrom(Class) check is done between the stored types and the type of the given identifier.

      Type Parameters:
      C - The type of the component to retrieve.
      Parameters:
      identifier - The identifier to retrieve a Component for.
      Returns:
      An Optional on the Component registered under the given identifier.
      Throws:
      AmbiguousComponentMatchException - When multiple matching Components are found for the given identifier.
    • put

      @Nullable public <C> Component<C> put(@Nonnull Component<C> component)
      Puts the given component, identified by the given identifier, in this collection.
      Type Parameters:
      C - The type of the component to put.
      Parameters:
      component - The component to put in this collection.
      Returns:
      A previous component registered under the given identifier, if present.
    • computeIfAbsent

      @Nonnull public <C> Component<C> computeIfAbsent(@Nonnull Component.Identifier<C> identifier, @Nonnull Supplier<Component<C>> compute)
      Computes a Component for the given identifier when absent, otherwise returns the Component put(Component) under the identifier.

      The given compute operation is only invoked when there is no Component present for the given identifier.

      Type Parameters:
      C - The type of the component to get and compute if absent.
      Parameters:
      identifier - The identifier for which to check if a Component is already present.
      compute - The lambda computing the Component to put into this collection when absent.
      Returns:
      The previously put Component identifier by the given identifier. When absent, the outcome of the compute operation is returned
    • contains

      public boolean contains(@Nonnull Component.Identifier<?> identifier)
      Check whether there is a Component present for the given identifier.

      If the given identifier has a nullable name, all identifiers of this collection trigger a match if their type is assignable to the given identifier's type.

      Parameters:
      identifier - The identifier for which to check if there is a Component present.
      Returns:
      true if this collection contains a Component identified by the given identifier, false otherwise.
    • identifiers

      public Set<Component.Identifier<?>> identifiers()
      Returns the identifiers of the components currently registered.
      Returns:
      A set with the identifiers of registered components.
    • replace

      public <C> boolean replace(@Nonnull Component.Identifier<C> identifier, @Nonnull UnaryOperator<Component<C>> replacement)
      Replace the component registered under the given identifier with the instance returned by given replacement function. If no component is registered under the given identifier, nothing happens.

      If the given replacement function returns null, the component registration is removed.

      Type Parameters:
      C - The type of component registered.
      Parameters:
      identifier - The identifier of the component to replace.
      replacement - The function providing the replacement value, based on the currently registered component.
      Returns:
      true if a component is present and has been replaced, false if no component was present, or has been removed by the replacement function.
    • postProcessComponents

      public void postProcessComponents(@Nonnull Consumer<Component<?>> processor)
      Invoke the given processor on all components that are registered in this collection.

      Exceptions thrown by the processor will be rethrown to the caller before all components have been processed.

      Parameters:
      processor - The action to invoke for each component.
    • 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.