/** * Finds all configuration modules of given {@code moduleType} within this configuration. * * @param moduleType The type of the configuration module * @param <T> The type of the configuration module * @return configuration modules of {@code moduleType} defined in this configuration */ @SuppressWarnings("unchecked") default <T extends ModuleConfiguration> List<T> findModules(Class<T> moduleType) { return getModules().stream() .filter(m -> m.isType(moduleType)) .map(m -> (T) m.unwrap()) .collect(Collectors.toList()); }
/** * Returns the {@link EventProcessingConfiguration} defined in this Configuration. If there aren't any defined, * {@code null} will be returned. If there is exactly one, it will be returned. For case when there are multiple, * an {@link AxonConfigurationException} is thrown and the {@link #getModules()} API should be used instead. * * @return the {@link EventProcessingConfiguration} defined in this Configuration * * @throws AxonConfigurationException thrown if there are more than one Event Processing Configurations defined with * this configuration */ default EventProcessingConfiguration eventProcessingConfiguration() throws AxonConfigurationException { List<EventProcessingConfiguration> eventProcessingModules = getModules().stream() .filter(module -> module.isType(EventProcessingConfiguration.class)) .map(module -> (EventProcessingConfiguration) module.unwrap()) .collect(Collectors.toList()); switch (eventProcessingModules.size()) { case 0: return null; case 1: return eventProcessingModules.get(0); default: throw new AxonConfigurationException( "There are several EventProcessingConfigurations defined. Use findModules(Class<T>) method instead."); } }
@Override public EventProcessingConfigurer eventProcessing() { List<EventProcessingConfigurer> eventProcessingConfigurers = modules.stream() .filter(module -> module.isType(EventProcessingConfigurer.class)) .map(module -> (EventProcessingConfigurer) module.unwrap()) // It's safe to unwrap it since it isn't dependent on anything else. .collect(toList()); switch (eventProcessingConfigurers.size()) { case 0: EventProcessingModule eventProcessingModule = new EventProcessingModule(); registerModule(eventProcessingModule); return eventProcessingModule; case 1: return eventProcessingConfigurers.get(0); default: throw new AxonConfigurationException( "There are several EventProcessingConfigurers defined. " + "The `eventProcessing()` method is used to retrieve a 'singleton' EventProcessingConfigurer." ); } }
/** * Finds all configuration modules of given {@code moduleType} within this configuration. * * @param moduleType The type of the configuration module * @param <T> The type of the configuration module * @return configuration modules of {@code moduleType} defined in this configuration */ @SuppressWarnings("unchecked") default <T extends ModuleConfiguration> List<T> findModules(Class<T> moduleType) { return getModules().stream() .filter(m -> m.isType(moduleType)) .map(m -> (T) m.unwrap()) .collect(Collectors.toList()); }
/** * Returns the {@link EventProcessingConfiguration} defined in this Configuration. If there aren't any defined, * {@code null} will be returned. If there is exactly one, it will be returned. For case when there are multiple, * an {@link AxonConfigurationException} is thrown and the {@link #getModules()} API should be used instead. * * @return the {@link EventProcessingConfiguration} defined in this Configuration * * @throws AxonConfigurationException thrown if there are more than one Event Processing Configurations defined with * this configuration */ default EventProcessingConfiguration eventProcessingConfiguration() throws AxonConfigurationException { List<EventProcessingConfiguration> eventProcessingModules = getModules().stream() .filter(module -> module.isType(EventProcessingConfiguration.class)) .map(module -> (EventProcessingConfiguration) module.unwrap()) .collect(Collectors.toList()); switch (eventProcessingModules.size()) { case 0: return null; case 1: return eventProcessingModules.get(0); default: throw new AxonConfigurationException( "There are several EventProcessingConfigurations defined. Use findModules(Class<T>) method instead."); } }
@Override public EventProcessingConfigurer eventProcessing() { List<EventProcessingConfigurer> eventProcessingConfigurers = modules.stream() .filter(module -> module.isType(EventProcessingConfigurer.class)) .map(module -> (EventProcessingConfigurer) module.unwrap()) // It's safe to unwrap it since it isn't dependent on anything else. .collect(toList()); switch (eventProcessingConfigurers.size()) { case 0: EventProcessingModule eventProcessingModule = new EventProcessingModule(); registerModule(eventProcessingModule); return eventProcessingModule; case 1: return eventProcessingConfigurers.get(0); default: throw new AxonConfigurationException( "There are several EventProcessingConfigurers defined. " + "The `eventProcessing()` method is used to retrieve a 'singleton' EventProcessingConfigurer." ); } }