/** * Retrieves the routing keys of every command handler on the given {@code childEntityModel} to be able to correctly * route commands to Entities. * * @param field a {@link java.lang.reflect.Field} denoting the Child Entity upon which the {@code * childEntityModel} is based. * @param childEntityModel a {@link EntityModel} to retrieve the * routing key properties from. * @return a {@link java.util.Map} of key/value types {@link java.lang.String}/ * {@link org.axonframework.common.property.Property} from Command Message name to routing key. */ @SuppressWarnings("WeakerAccess") protected Map<String, Property<Object>> extractCommandHandlerRoutingKeys(Field field, EntityModel<Object> childEntityModel) { return childEntityModel.commandHandlers() .stream() .map(commandHandler -> commandHandler.unwrap(CommandMessageHandlingMember.class) .orElse(null)) .filter(Objects::nonNull) .collect(Collectors.toMap( CommandMessageHandlingMember::commandName, commandHandler -> extractCommandHandlerRoutingKey(childEntityModel, commandHandler, field ) )); }
/** * Initiates a new AnnotatedChildEntity instance that uses the provided {@code entityModel} to delegate command * and event handling to an annotated child entity. * * @param entityModel A {@link EntityModel} describing the entity. * @param forwardCommands Flag indicating whether commands should be forwarded to the entity. * @param commandTargetResolver Resolver for command handler methods on the target. * @param eventTargetResolver Resolver for event handler methods on the target. */ @SuppressWarnings("unchecked") public AnnotatedChildEntity(EntityModel<C> entityModel, boolean forwardCommands, BiFunction<CommandMessage<?>, P, C> commandTargetResolver, BiFunction<EventMessage<?>, P, Stream<C>> eventTargetResolver) { this.entityModel = entityModel; this.eventTargetResolver = eventTargetResolver; this.commandHandlers = new ArrayList<>(); if (forwardCommands) { entityModel.commandHandlers() .stream() .filter(eh -> eh.unwrap(CommandMessageHandlingMember.class).isPresent()) .forEach( (childHandler) -> commandHandlers .add(new ChildForwardingCommandMessageHandlingMember<>( entityModel.commandHandlerInterceptors(), childHandler, commandTargetResolver))); } }
/** * Retrieves the routing keys of every command handler on the given {@code childEntityModel} to be able to correctly * route commands to Entities. * * @param field a {@link java.lang.reflect.Field} denoting the Child Entity upon which the {@code * childEntityModel} is based. * @param childEntityModel a {@link EntityModel} to retrieve the * routing key properties from. * @return a {@link java.util.Map} of key/value types {@link java.lang.String}/ * {@link org.axonframework.common.property.Property} from Command Message name to routing key. */ @SuppressWarnings("WeakerAccess") protected Map<String, Property<Object>> extractCommandHandlerRoutingKeys(Field field, EntityModel<Object> childEntityModel) { return childEntityModel.commandHandlers() .stream() .map(commandHandler -> commandHandler.unwrap(CommandMessageHandlingMember.class) .orElse(null)) .filter(Objects::nonNull) .collect(Collectors.toMap( CommandMessageHandlingMember::commandName, commandHandler -> extractCommandHandlerRoutingKey(childEntityModel, commandHandler, field ) )); }
/** * Initiates a new AnnotatedChildEntity instance that uses the provided {@code entityModel} to delegate command * and event handling to an annotated child entity. * * @param entityModel A {@link EntityModel} describing the entity. * @param forwardCommands Flag indicating whether commands should be forwarded to the entity. * @param commandTargetResolver Resolver for command handler methods on the target. * @param eventTargetResolver Resolver for event handler methods on the target. */ @SuppressWarnings("unchecked") public AnnotatedChildEntity(EntityModel<C> entityModel, boolean forwardCommands, BiFunction<CommandMessage<?>, P, C> commandTargetResolver, BiFunction<EventMessage<?>, P, Stream<C>> eventTargetResolver) { this.entityModel = entityModel; this.eventTargetResolver = eventTargetResolver; this.commandHandlers = new ArrayList<>(); if (forwardCommands) { entityModel.commandHandlers() .stream() .filter(eh -> eh.unwrap(CommandMessageHandlingMember.class).isPresent()) .forEach( (childHandler) -> commandHandlers .add(new ChildForwardingCommandMessageHandlingMember<>( entityModel.commandHandlerInterceptors(), childHandler, commandTargetResolver))); } }