Interface Configuration

All Superinterfaces:
DescribableComponent
All Known Subinterfaces:
AxonConfiguration

public interface Configuration extends DescribableComponent
Interface providing access to all configured components in an Axon Framework application.
Since:
3.0.0
Author:
Allard Buijze, Steven van Beelen
  • Method Details

    • getComponent

      @Nonnull default <C> C getComponent(@Nonnull Class<C> type)
      Returns the component declared under the given type or throws a ComponentNotFoundException if it does not exist.
      Type Parameters:
      C - The type of component.
      Parameters:
      type - The type of component, typically the interface the component implements.
      Returns:
      The component registered for the given type.
      Throws:
      ComponentNotFoundException - Whenever there is no component present for the given type.
    • getComponent

      @Nonnull default <C> C getComponent(@Nonnull Class<C> type, @Nullable String name)
      Returns the component declared under the given type and name or throws a ComponentNotFoundException if it does not exist.
      Type Parameters:
      C - The type of component.
      Parameters:
      type - The type of component, typically the interface the component implements.
      name - The name of the component to retrieve. Use null when there is no name or use getComponent(Class) instead.
      Returns:
      The component registered for the given type and name.
      Throws:
      ComponentNotFoundException - Whenever there is no component present for the given type and name.
    • getOptionalComponent

      default <C> Optional<C> getOptionalComponent(@Nonnull Class<C> type)
      Returns the component declared under the given type within an Optional.
      Type Parameters:
      C - The type of component.
      Parameters:
      type - The type of component, typically the interface the component implements.
      Returns:
      An Optional wrapping the component registered for the given type. Might be empty when there is no component present for the given type.
    • getOptionalComponent

      <C> Optional<C> getOptionalComponent(@Nonnull Class<C> type, @Nullable String name)
      Returns the component declared under the given type and name within an Optional.
      Type Parameters:
      C - The type of component.
      Parameters:
      type - The type of component, typically the interface the component implements.
      name - The name of the component to retrieve. Use null when there is no name or use getOptionalComponent(Class) instead.
      Returns:
      An Optional wrapping the component registered for the given type and name. Might be empty when there is no component present for the given type and name.
    • hasComponent

      default boolean hasComponent(@Nonnull Class<?> type)
      Check whether there is a Component present in this Configuration for the given type.
      Parameters:
      type - The type of the Component to check if it exists, typically an interface.
      Returns:
      true when there is a Component registered under the given type, false otherwise.
    • hasComponent

      default boolean hasComponent(@Nonnull Class<?> type, @Nullable String name)
      Check whether there is a Component present in this Configuration for the given type and name combination.
      Parameters:
      type - The type of the Component to check if it exists, typically an interface.
      name - The name of the Component to check if it exists. Use null when there is no name or use hasComponent(Class) instead.
      Returns:
      true when there is a Component registered under the given type and name combination, false otherwise.
    • getComponent

      @Nonnull default <C> C getComponent(@Nonnull Class<C> type, @Nonnull Supplier<C> defaultImpl)
      Returns the component declared under the given type, reverting to the given defaultImpl if no such component is defined.

      When no component was previously registered, the default is then configured as the component for the given type.

      Type Parameters:
      C - The type of component.
      Parameters:
      type - The type of component, typically the interface the component implements.
      defaultImpl - The supplier of the default component to return if it was not registered.
      Returns:
      The component declared under the given type, reverting to the given defaultImpl if no such component is defined.
    • getComponent

      @Nonnull <C> C getComponent(@Nonnull Class<C> type, @Nullable String name, @Nonnull Supplier<C> defaultImpl)
      Returns the component declared under the given type and name, reverting to the given defaultImpl if no such component is defined.

      When no component was previously registered, the default is then configured as the component for the given type.

      Type Parameters:
      C - The type of component.
      Parameters:
      type - The type of component, typically the interface the component implements.
      name - The name of the component to retrieve. Use null when there is no name or use getComponent(Class, Supplier) instead.
      defaultImpl - The supplier of the default component to return if it was not registered.
      Returns:
      The component declared under the given type and name, reverting to the given defaultImpl if no such component is defined.
    • getModuleConfigurations

      List<Configuration> getModuleConfigurations()
      Returns all Configurations from the Modules that have been registered with this Configuration.
      Returns:
      The resulting Configuration from each registered module with this Configuration.
    • getModuleConfiguration

      Optional<Configuration> getModuleConfiguration(@Nonnull String name)
      Returns the Configuration from the Module with the given name.

      The module must have been registered with this Configuration directly.

      Parameters:
      name - The name of the Module to get the configuration for.
      Returns:
      An Optional with the Configuration for a Module with the given name or an empty optional if no module exists with that name.
    • getParent

      @Nullable Configuration getParent()
      Returns the parent configuration of this configuration, if the parent configuration exists. Components can use this to build hierarchical components, which prefer components from a child configuration over components from a parent configuration.
      Returns:
      The parent configuration of this configuration, or null if no parent configuration exists.
    • getComponents

      @Nonnull <C> Map<String,C> getComponents(@Nonnull Class<C> type)
      Returns all components declared under the given type as a map of component names to component instances.

      This method retrieves all registered components matching the specified type. The returned map contains:

      • An entry with null key for the component registered without a name (if one exists)
      • Entries with String keys for components registered with specific names
      This is useful when multiple components of the same type are registered, such as multiple EventProcessors.

      The method searches in the current configuration and all module configurations. It does NOT search the parent configuration. To get the full hierarchy of components, call this method on the top-level (root) configuration.

      Important: This method only returns components that are already registered or have been instantiated. Components that could be created on-demand by a ComponentFactory but have not yet been accessed will not be included in the results. If you need to access a specific component that might be factory-created, use getComponent(Class, String) or getOptionalComponent(Class, String) instead.

      Example usage:

      
       Map<String, EventProcessor> processors = configuration.getComponents(EventProcessor.class);
       EventProcessor defaultProcessor = processors.get(null);  // unnamed processor
       EventProcessor orderProcessor = processors.get("orderProcessor");  // named processor
       
      Type Parameters:
      C - The type of component.
      Parameters:
      type - The type of component, typically the interface the component implements.
      Returns:
      A map of component names to component instances for the given type. Returns an empty map if no components are registered for the given type. The map may contain a null key for the unnamed component.