Interface ComponentFactory<C>

Type Parameters:
C - The component this factory builds on request.
All Superinterfaces:
DescribableComponent
All Known Implementing Classes:
AxonServerEventStorageEngineFactory

public interface ComponentFactory<C> extends DescribableComponent
A factory of components of type generic C.

It is strongly recommended to invoke start operations during construction of the components, since the Configuration is always started before a factory is consulted. Hence, failing to invoke start operations results in components in a faulty state.

When registered with a ComponentRegistry, the registry will consult the factory only when there is no registered component for a given type and name.

Since:
5.0.0
Author:
Steven van Beelen
  • Method Details

    • forType

      @Nonnull Class<C> forType()
      Returns the Class this factory constructs.

      Useful when the generic type is lost due to grouping multiple factories in a collection.

      Returns:
      The Class this factory constructs.
    • construct

      @Nonnull Optional<Component<C>> construct(@Nonnull String name, @Nonnull Configuration config)
      Constructs a Component containing an implementation of the generic type C.

      Implementations of this method may choose to reject the construction by returning an empty Optional if the name is not of an expected format, or when the given config does not contain the required components to construct a new instance with.

      Be certain to invoke any start operation on the new instance of type C before returning. This is mandatory since factories are only consulted once an application is started.

      Parameters:
      name - The name that's used to request a new instance from this factory. This parameter can be a basis to reject construction.
      config - The configuration to retrieve components from to use during the construction by this factory. A factory may return an empty Optional if the configuration does not contain the necessary components.
      Returns:
      An optional of a Component containing an implementation of the generic type C.
    • registerShutdownHandlers

      void registerShutdownHandlers(@Nonnull LifecycleRegistry registry)
      Registers this factory's shutdown process with the given registry.

      This typically means the factory registers the shutdown operations of all constructed components of type C. This operation might do nothing with the registry when the component of type C does not have any shutdown operations, for example.

      Since a component factory is consulted after start-up of a Configuration, only registered shutdown handlers will take effect.

      Parameters:
      registry - The life cycle registry to register shutdown handlers with.