commandHandler = new Component<>(() -> parent, "aggregateCommandHandler<" + aggregate.getSimpleName() + ">", c -> AggregateAnnotationCommandHandler.<A>builder() .repository(repository.get()) .commandTargetResolver(commandTargetResolver.get()) .aggregateModel(metaModel.get()) .build());
/** * Instantiate a {@link AggregateAnnotationCommandHandler} based on the fields contained in the {@link Builder}. * <p> * Will assert that the {@link Repository} and {@link CommandTargetResolver} are not {@code null}, and will throw * an {@link AxonConfigurationException} if either of them is {@code null}. Next to that, the provided Builder's * goal is to create an {@link AggregateModel} (describing the structure of a given aggregate). To instantiate this * AggregateModel, either an {@link AggregateModel} can be provided directly or an {@code aggregateType} of type * {@link Class} can be used. The latter will internally resolve to an AggregateModel. Thus, either the * AggregateModel <b>or</b> the {@code aggregateType} should be provided. An AxonConfigurationException is thrown * if this criteria is not met. * * @param builder the {@link Builder} used to instantiate a {@link AggregateAnnotationCommandHandler} instance */ protected AggregateAnnotationCommandHandler(Builder<T> builder) { builder.validate(); this.repository = builder.repository; this.commandTargetResolver = builder.commandTargetResolver; this.supportedCommandNames = new HashSet<>(); this.handlers = initializeHandlers(builder.buildAggregateModel()); }
commandHandler = new Component<>(() -> parent, "aggregateCommandHandler<" + aggregate.getSimpleName() + ">", c -> AggregateAnnotationCommandHandler.<A>builder() .repository(repository.get()) .commandTargetResolver(commandTargetResolver.get()) .aggregateModel(metaModel.get()) .build());
/** * Instantiate a Builder to be able to create a {@link AggregateAnnotationCommandHandler}. * <p> * The {@link CommandTargetResolver} is defaulted to amn {@link AnnotationCommandTargetResolver} * The {@link Repository} is a <b>hard requirement</b> and as such should be provided. * Next to that, this Builder's goal is to provide an {@link AggregateModel} (describing the structure of a given * aggregate). To instantiate this AggregateModel, either an {@link AggregateModel} can be provided directly or an * {@code aggregateType} of type {@link Class} can be used. The latter will internally resolve to an * AggregateModel. Thus, either the AggregateModel <b>or</b> the {@code aggregateType} should be provided. * * @param <T> the type of aggregate this {@link AggregateAnnotationCommandHandler} handles commands for * @return a Builder to be able to create a {@link AggregateAnnotationCommandHandler} */ public static <T> Builder<T> builder() { return new Builder<>(); }
/** * Instantiate a {@link AggregateAnnotationCommandHandler} based on the fields contained in the {@link Builder}. * <p> * Will assert that the {@link Repository} and {@link CommandTargetResolver} are not {@code null}, and will throw * an {@link AxonConfigurationException} if either of them is {@code null}. Next to that, the provided Builder's * goal is to create an {@link AggregateModel} (describing the structure of a given aggregate). To instantiate this * AggregateModel, either an {@link AggregateModel} can be provided directly or an {@code aggregateType} of type * {@link Class} can be used. The latter will internally resolve to an AggregateModel. Thus, either the * AggregateModel <b>or</b> the {@code aggregateType} should be provided. An AxonConfigurationException is thrown * if this criteria is not met. * * @param builder the {@link Builder} used to instantiate a {@link AggregateAnnotationCommandHandler} instance */ protected AggregateAnnotationCommandHandler(Builder<T> builder) { builder.validate(); this.repository = builder.repository; this.commandTargetResolver = builder.commandTargetResolver; this.supportedCommandNames = new HashSet<>(); this.handlers = initializeHandlers(builder.buildAggregateModel()); }
/** * Instantiate the {@link AggregateModel} of generic type {@code T} describing the structure of the Aggregate * this {@link AggregateAnnotationCommandHandler} will handle commands for. * * @return a {@link AggregateModel} of generic type {@code T} describing the Aggregate this {@link * AggregateAnnotationCommandHandler} will handle commands for */ private AggregateModel<T> buildAggregateModel() { if (aggregateModel == null) { return inspectAggregateModel(); } else { return aggregateModel; } }
/** * Instantiate the {@link AggregateModel} of generic type {@code T} describing the structure of the Aggregate * this {@link AggregateAnnotationCommandHandler} will handle commands for. * * @return a {@link AggregateModel} of generic type {@code T} describing the Aggregate this {@link * AggregateAnnotationCommandHandler} will handle commands for */ private AggregateModel<T> buildAggregateModel() { if (aggregateModel == null) { return inspectAggregateModel(); } else { return aggregateModel; } }
/** * Instantiate a Builder to be able to create a {@link AggregateAnnotationCommandHandler}. * <p> * The {@link CommandTargetResolver} is defaulted to amn {@link AnnotationCommandTargetResolver} * The {@link Repository} is a <b>hard requirement</b> and as such should be provided. * Next to that, this Builder's goal is to provide an {@link AggregateModel} (describing the structure of a given * aggregate). To instantiate this AggregateModel, either an {@link AggregateModel} can be provided directly or an * {@code aggregateType} of type {@link Class} can be used. The latter will internally resolve to an * AggregateModel. Thus, either the AggregateModel <b>or</b> the {@code aggregateType} should be provided. * * @param <T> the type of aggregate this {@link AggregateAnnotationCommandHandler} handles commands for * @return a Builder to be able to create a {@link AggregateAnnotationCommandHandler} */ public static <T> Builder<T> builder() { return new Builder<>(); }
@SuppressWarnings("unchecked") @Before public void setUp() { eventStore = spy(EmbeddedEventStore.builder().storageEngine(new InMemoryEventStorageEngine()).build()); Repository<MyAggregate> myAggregateRepository = EventSourcingRepository.builder(MyAggregate.class) .eventStore(eventStore) .build(); CommandBus commandBus = SimpleCommandBus.builder().build(); commandGateway = DefaultCommandGateway.builder().commandBus(commandBus).build(); AggregateAnnotationCommandHandler<MyAggregate> myAggregateCommandHandler = AggregateAnnotationCommandHandler.<MyAggregate>builder() .aggregateType(MyAggregate.class) .repository(myAggregateRepository) .build(); myAggregateCommandHandler.subscribe(commandBus); }
private void registerAggregateCommandHandlers() { ensureRepositoryConfiguration(); if (!explicitCommandHandlersSet) { AggregateAnnotationCommandHandler.Builder<T> builder = AggregateAnnotationCommandHandler.<T>builder() .aggregateType(aggregateType) .parameterResolverFactory(parameterResolverFactory) .repository(this.repository); if (commandTargetResolver != null) { builder.commandTargetResolver(commandTargetResolver); } AggregateAnnotationCommandHandler<T> handler = builder.build(); handler.subscribe(commandBus); } }