@Override public Configurer registerModule(ModuleConfiguration module) { if (initialized) { module.initialize(config); startHandlers.add(new RunnableHandler(module.phase(), module::start)); shutdownHandlers.add(new RunnableHandler(module.phase(), module::shutdown)); } this.modules.add(module); return this; }
/** * 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()); }
@Override public void stop() { eventProcessingConfiguration.shutdown(); running = false; }
/** * Prepare the registered modules for initialization. This ensures all lifecycle handlers are registered. */ protected void prepareModules() { modules.forEach(module -> { initHandlers.add(new ConsumerHandler(module.phase(), module::initialize)); startHandlers.add(new RunnableHandler(module.phase(), module::start)); shutdownHandlers.add(new RunnableHandler(module.phase(), module::shutdown)); }); }
@Override public void afterPropertiesSet() { if (!initialized) { initialized = true; eventProcessingConfiguration.initialize(axonConfiguration); } } }
/** * 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 -> moduleType.isInstance(m.unwrap())) .map(m -> (T) m.unwrap()) .collect(Collectors.toList()); }
@Override public void start() { eventProcessingConfiguration.start(); running = true; }
@Override public int phase() { return getDelegate().phase(); }
@Override public void initialize(Configuration config) { getDelegate().initialize(config); }
@Override public Configuration buildConfiguration() { if (!initialized) { verifyIdentifierFactory(); boolean missingEventProcessingConfiguration = modules.stream() .noneMatch(m -> m.unwrap() instanceof EventProcessingConfiguration); if (missingEventProcessingConfiguration) { registerModule(new EventProcessingConfiguration()); } prepareModules(); invokeInitHandlers(); } return config; }
@Override public void start() { getDelegate().start(); }
@Override public Configurer registerModule(ModuleConfiguration module) { if (initialized) { module.initialize(config); startHandlers.add(new RunnableHandler(module.phase(), module::start)); shutdownHandlers.add(new RunnableHandler(module.phase(), module::shutdown)); } this.modules.add(module); return this; }
/** * 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."); } }
/** * Prepare the registered modules for initialization. This ensures all lifecycle handlers are registered. */ protected void prepareModules() { modules.forEach(module -> { initHandlers.add(new ConsumerHandler(module.phase(), module::initialize)); startHandlers.add(new RunnableHandler(module.phase(), module::start)); shutdownHandlers.add(new RunnableHandler(module.phase(), module::shutdown)); }); }
@Override public void shutdown() { getDelegate().shutdown(); }
@Override public Configurer registerModule(ModuleConfiguration module) { if (initialized) { module.initialize(config); startHandlers.add(new RunnableHandler(module.phase(), module::start)); shutdownHandlers.add(new RunnableHandler(module.phase(), module::shutdown)); } this.modules.add(module); return this; }
@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." ); } }
/** * Prepare the registered modules for initialization. This ensures all lifecycle handlers are registered. */ protected void prepareModules() { modules.forEach(module -> { initHandlers.add(new ConsumerHandler(module.phase(), module::initialize)); startHandlers.add(new RunnableHandler(module.phase(), module::start)); shutdownHandlers.add(new RunnableHandler(module.phase(), module::shutdown)); }); }
/** * 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()); }
@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." ); } }