Class AggregateConfigurer<A>

java.lang.Object
org.axonframework.config.AggregateConfigurer<A>
Type Parameters:
A - the type of Aggregate configured
All Implemented Interfaces:
AggregateConfiguration<A>, ModuleConfiguration

public class AggregateConfigurer<A> extends Object implements AggregateConfiguration<A>
Axon Configuration API extension that allows the definition of an Aggregate. This component will automatically set up all components required for the Aggregate to operate.
Since:
3.0
Author:
Allard Buijze
  • Constructor Details

    • AggregateConfigurer

      protected AggregateConfigurer(Class<A> aggregate)
      Creates a default configuration as described in defaultConfiguration(Class). This constructor is available for subclasses that provide additional configuration possibilities.
      Parameters:
      aggregate - The type of aggregate to configure
  • Method Details

    • defaultConfiguration

      public static <A> AggregateConfigurer<A> defaultConfiguration(Class<A> aggregateType)
      Creates a default Configuration for an aggregate of the given aggregateType. This required either a Repository to be configured using configureRepository(Function), or that the Global Configuration contains an Event Store and the Aggregate support Event Sourcing.
      Type Parameters:
      A - The type of Aggregate to configure
      Parameters:
      aggregateType - The type of Aggregate to configure
      Returns:
      An AggregateConfigurer instance for further configuration of the Aggregate
    • jpaMappedConfiguration

      public static <A> AggregateConfigurer<A> jpaMappedConfiguration(Class<A> aggregateType)
      Creates a Configuration for an aggregate of given aggregateType, which is mapped to a relational database using an EntityManager obtained from the main configuration. The given aggregateType is expected to be a proper JPA Entity.

      The EntityManagerProvider is expected to have been registered with the Configurer (which would be the case when using DefaultConfigurer.jpaConfiguration(EntityManagerProvider). If that is not the case, consider using jpaMappedConfiguration(Class, EntityManagerProvider) instead.

      Type Parameters:
      A - The type of Aggregate to configure
      Parameters:
      aggregateType - The type of Aggregate to configure
      Returns:
      An AggregateConfigurer instance for further configuration of the Aggregate
    • jpaMappedConfiguration

      public static <A> AggregateConfigurer<A> jpaMappedConfiguration(Class<A> aggregateType, EntityManagerProvider entityManagerProvider)
      Creates a Configuration for an aggregate of given aggregateType, which is mapped to a relational database using an EntityManager provided by given entityManagerProvider. The given aggregateType is expected to be a proper JPA Entity.
      Type Parameters:
      A - The type of Aggregate to configure
      Parameters:
      aggregateType - The type of Aggregate to configure
      entityManagerProvider - The provider for Axon to retrieve the EntityManager from
      Returns:
      An AggregateConfigurer instance for further configuration of the Aggregate
    • configureRepository

      public AggregateConfigurer<A> configureRepository(Function<Configuration,Repository<A>> repositoryBuilder)
      Defines the repository to use to load and store Aggregates of this type. The builder function receives the global configuration object from which it can retrieve components the repository depends on.
      Parameters:
      repositoryBuilder - The builder function for the repository
      Returns:
      this configurer instance for chaining
    • configureAggregateFactory

      public AggregateConfigurer<A> configureAggregateFactory(Function<Configuration,AggregateFactory<A>> aggregateFactoryBuilder)
      Defines the factory to use to create new Aggregates instances of the type under configuration.
      Parameters:
      aggregateFactoryBuilder - The builder function for the AggregateFactory
      Returns:
      this configurer instance for chaining
    • configureCreationPolicyAggregateFactory

      public AggregateConfigurer<A> configureCreationPolicyAggregateFactory(Function<Configuration,CreationPolicyAggregateFactory<A>> creationPolicyAggregateFactoryBuilder)
      Defines the factory to create new aggregate instances of the type under configuration when initializing those instances from non-constructor command handlers annotated with CreationPolicy.

      When subtypes are provided, the given CreationPolicyAggregateFactory is used for every implementation of the aggregate under construction.

      Parameters:
      creationPolicyAggregateFactoryBuilder - The builder function for the CreationPolicyAggregateFactory.
      Returns:
      This configurer instance for chaining.
    • configureLockFactory

      public AggregateConfigurer<A> configureLockFactory(Function<Configuration,LockFactory> lockFactory)
      Defines the LockFactory to use in the Repository for the aggregate under configuration. Defaults to the PessimisticLockFactory for the EventSourcingRepository and NullLockFactory for a GenericJpaRepository.
      Parameters:
      lockFactory - a Function building the LockFactory to use based on the Configuration
      Returns:
      this configurer instance for chaining
    • configureCommandHandler

      public AggregateConfigurer<A> configureCommandHandler(Function<Configuration,AggregateAnnotationCommandHandler<A>> aggregateCommandHandlerBuilder)
      Defines the AggregateAnnotationCommandHandler instance to use.
      Parameters:
      aggregateCommandHandlerBuilder - The builder function for the AggregateCommandHandler
      Returns:
      this configurer instance for chaining
    • configureCommandTargetResolver

      public AggregateConfigurer<A> configureCommandTargetResolver(Function<Configuration,CommandTargetResolver> commandTargetResolverBuilder)
      Defines the CommandTargetResolver to use for the Aggregate type under configuration. The CommandTargetResolver defines which Aggregate instance must be loaded to handle a specific Command.
      Parameters:
      commandTargetResolverBuilder - the builder function for the CommandTargetResolver.
      Returns:
      this configurer instance for chaining
    • configureSnapshotTrigger

      public AggregateConfigurer<A> configureSnapshotTrigger(Function<Configuration,SnapshotTriggerDefinition> snapshotTriggerDefinition)
      Configures snapshotting for the Aggregate type under configuration.

      Note that this configuration is ignored if a custom repository instance is configured.

      Parameters:
      snapshotTriggerDefinition - The function creating the SnapshotTriggerDefinition
      Returns:
      this configurer instance for chaining
    • configureSnapshotFilter

      public AggregateConfigurer<A> configureSnapshotFilter(Function<Configuration,SnapshotFilter> snapshotFilter)
      Configure a SnapshotFilter for the Aggregate type under configuration. Note that SnapshotFilter instances will be combined and should return true if they handle a snapshot they wish to ignore.
      Parameters:
      snapshotFilter - the function creating the SnapshotFilter
      Returns:
      this configurer instance for chaining
    • configureEventStreamFilter

      public AggregateConfigurer<A> configureEventStreamFilter(Function<Configuration,Predicate<? super DomainEventMessage<?>>> filterBuilder)
      Configures an event stream filter for the EventSourcingRepository for the Aggregate type under configuration. By default, no filter is applied to the event stream.

      Note that this configuration is ignored if a custom repository instance is configured.

      Parameters:
      filterBuilder - The function creating the filter.
      Returns:
      this configurer instance for chaining
      See Also:
    • configureCache

      public AggregateConfigurer<A> configureCache(Function<Configuration,Cache> cache)
      Configures the Cache to use for the repository created for this Aggregate type. Note that this setting is ignored when explicitly configuring a Repository using configureRepository(Function).
      Parameters:
      cache - the function that defines the Cache to use
      Returns:
      this configurer instance for chaining
    • configureWeakReferenceCache

      public AggregateConfigurer<A> configureWeakReferenceCache()
      Configures a WeakReferenceCache to be used for the repository created for this Aggregate type. Note that this setting is ignored when explicitly configuring a Repository using configureRepository(Function).
      Returns:
      this configurer instance for chaining
    • configureFilterEventsByType

      public AggregateConfigurer<A> configureFilterEventsByType(Function<Configuration,Boolean> filterConfigurationPredicate)
      Configures a function that determines whether or not the EventSourcingRepository for the Aggregate type under configuration should filter out events with non-matching types. This may be used to support installations where multiple Aggregate types share overlapping Aggregate IDs.

      Note that this configuration is ignored if a custom repository instance is configured, and that configureEventStreamFilter(Function) overrides this.

      Parameters:
      filterConfigurationPredicate - The function determining whether or not to filter events by Aggregate type.
      Returns:
      this configurer instance for chaining
      See Also:
    • initialize

      public void initialize(Configuration config)
      Description copied from interface: ModuleConfiguration
      Initialize the module configuration using the given global config. Any specific start up or shut down processes should be added here by using the provided config and invoke LifecycleOperations.onStart(int, LifecycleHandler) and LifecycleOperations.onShutdown(int, LifecycleHandler) respectively.
      Specified by:
      initialize in interface ModuleConfiguration
      Parameters:
      config - the global configuration, providing access to generic components
    • repository

      public Repository<A> repository()
      Description copied from interface: AggregateConfiguration
      Returns the repository defined to load instances of the Aggregate type defined in this configuration.
      Specified by:
      repository in interface AggregateConfiguration<A>
      Returns:
      the repository to load aggregates
    • aggregateType

      public Class<A> aggregateType()
      Description copied from interface: AggregateConfiguration
      Returns the type of Aggregate defined in this configuration.
      Specified by:
      aggregateType in interface AggregateConfiguration<A>
      Returns:
      the type of Aggregate defined in this configuration
    • aggregateFactory

      public AggregateFactory<A> aggregateFactory()
      Description copied from interface: AggregateConfiguration
      Returns the AggregateFactory defined in this configuration.
      Specified by:
      aggregateFactory in interface AggregateConfiguration<A>
      Returns:
      the AggregateFactory defined in this configuration.
    • snapshotFilter

      public SnapshotFilter snapshotFilter()
      Description copied from interface: AggregateConfiguration
      Returns the SnapshotFilter defined in this configuration.
      Specified by:
      snapshotFilter in interface AggregateConfiguration<A>
      Returns:
      the SnapshotFilter defined in this configuration
    • withSubtypes

      @SafeVarargs public final AggregateConfigurer<A> withSubtypes(Class<? extends A>... subtypes)
      Registers subtypes of this aggregate to support aggregate polymorphism. Command Handlers defined on this subtypes will be considered part of this aggregate's handlers.
      Parameters:
      subtypes - subtypes in this polymorphic hierarchy
      Returns:
      this configurer for fluent interfacing
    • withSubtypes

      public AggregateConfigurer<A> withSubtypes(Collection<Class<? extends A>> subtypes)
      Registers subtypes of this aggregate to support aggregate polymorphism. Command Handlers defined on this subtypes will be considered part of this aggregate's handlers.
      Parameters:
      subtypes - subtypes in this polymorphic hierarchy
      Returns:
      this configurer for fluent interfacing
    • creationPolicyAggregateFactory

      public CreationPolicyAggregateFactory<A> creationPolicyAggregateFactory()
      Returns the CreationPolicyAggregateFactory defined in this configuration.
      Returns:
      the CreationPolicyAggregateFactory defined in this configuration.