Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#6 ErrorHandler and ListenerInvocationErrorHandler recognition #8

Merged
merged 2 commits into from
May 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 4.1.1-RC2

* [**#6** ErrorHandler and ListenerInvocationErrorHandler recognition](https://github.com/Scalified/axonframework-cdi/issues/6)

# 4.1.1-RC1

* [**#3** Axon Properties And Events](https://github.com/Scalified/axonframework-cdi/issues/3)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,10 @@
import org.axonframework.common.AxonConfigurationException;
import org.axonframework.common.transaction.TransactionManager;
import org.axonframework.config.*;
import org.axonframework.eventhandling.ErrorHandler;
import org.axonframework.eventhandling.EventBus;
import org.axonframework.eventhandling.EventHandler;
import org.axonframework.eventhandling.ListenerInvocationErrorHandler;
import org.axonframework.eventsourcing.eventstore.EventStorageEngine;
import org.axonframework.messaging.MessageDispatchInterceptor;
import org.axonframework.messaging.correlation.CorrelationDataProvider;
Expand Down Expand Up @@ -182,6 +184,16 @@ public class CdiExtension implements Extension {
*/
private Component queryUpdateEmitterComponent;

/**
* {@link ErrorHandler} component
*/
private Component errorHandlerComponent;

/**
* {@link ListenerInvocationErrorHandler} component
*/
private Component listenerInvocationErrorHandlerComponent;

/**
* {@link CommandDispatchInterceptor} components
*/
Expand Down Expand Up @@ -364,6 +376,12 @@ private void initAxonComponent(AxonComponent annotation, Component component) {
if (TypeUtils.isAssignable(actualType, QueryUpdateEmitter.class)) {
initialized = initQueryUpdateEmitterComponent(component) || initialized;
}
if (TypeUtils.isAssignable(actualType, ErrorHandler.class)) {
initialized = initErrorHandlerComponent(component) || initialized;
}
if (TypeUtils.isAssignable(actualType, ListenerInvocationErrorHandler.class)) {
initialized = initListenerInvocationErrorHandlerComponent(component) || initialized;
}

if (TypeUtils.isAssignable(actualType, CommandDispatchInterceptor.class)) {
initialized = initCommandDispatchInterceptorComponent(component) || initialized;
Expand Down Expand Up @@ -637,7 +655,39 @@ private boolean initQueryUpdateEmitterComponent(Component component) {
throw new AxonConfigurationException("Multiple QueryUpdateEmitter components declared");
}
queryUpdateEmitterComponent = component;
log.trace("Initialized QueryUpdateEmitterConfigurable producer: {}", component);
log.trace("Initialized QueryUpdateEmitter component: {}", component);
return true;
}

/**
* Initializes {@code errorHandlerComponent} from the given {@code component}
*
* @param component component to initialize
* @return {@code true} if the {@code component} was initialized, {@code false} otherwise
* @throws AxonConfigurationException in case of initialization error
*/
private boolean initErrorHandlerComponent(Component component) {
if (nonNull(errorHandlerComponent)) {
throw new AxonConfigurationException("Multiple ErrorHandler components declared");
}
errorHandlerComponent = component;
log.trace("Initialized ErrorHandler component: {}", component);
return true;
}

/**
* Initializes {@code listenerInvocationErrorHandlerComponent} from the given {@code component}
*
* @param component component to initialize
* @return {@code true} if the {@code component} was initialized, {@code false} otherwise
* @throws AxonConfigurationException in case of initialization error
*/
private boolean initListenerInvocationErrorHandlerComponent(Component component) {
if (nonNull(listenerInvocationErrorHandlerComponent)) {
throw new AxonConfigurationException("Multiple ListenerInvocationErrorHandler components declared");
}
listenerInvocationErrorHandlerComponent = component;
log.trace("Initialized ListenerInvocationErrorHandler component: {}", component);
return true;
}

Expand Down Expand Up @@ -762,6 +812,8 @@ void afterDeploymentValidation(@Observes AfterDeploymentValidation event, BeanMa
configureQueryBus(beanManager);
configureResourceInjector(beanManager);
configureQueryUpdateEmitter(beanManager);
configureErrorHandler(beanManager);
configureListenerInvocationErrorHandler(beanManager);

configureEventUpcasters(beanManager);
configureModules(beanManager);
Expand Down Expand Up @@ -1067,7 +1119,39 @@ private void configureQueryUpdateEmitter(BeanManager beanManager) {
Configurable<QueryUpdateEmitter> configurable =
ConfigurableComponentResolver.of(queryUpdateEmitterComponent).resolve(beanManager);
configurer = configurer.configureQueryUpdateEmitter(configurable);
log.debug("Configured QueryUpdateEmitter: {}", configurable);
log.debug("Configured QueryUpdateEmitter: {}", queryUpdateEmitterComponent);
}
}

/**
* Configures <b>Axon</b> default {@link ErrorHandler}
*
* @param beanManager current {@link BeanManager}
* @see EventProcessingConfigurer#registerDefaultErrorHandler(Function)
*/
private void configureErrorHandler(BeanManager beanManager) {
if (nonNull(errorHandlerComponent)) {
Configurable<ErrorHandler> configurable =
ConfigurableComponentResolver.of(errorHandlerComponent).resolve(beanManager);
configurer = configurer.eventProcessing(eventProcessingConfigurer ->
eventProcessingConfigurer.registerDefaultErrorHandler(configurable));
log.debug("Configured default ErrorHandler: {}", errorHandlerComponent);
}
}

/**
* Configures <b>Axon</b> default {@link ListenerInvocationErrorHandler}
*
* @param beanManager current {@link BeanManager}
* @see EventProcessingConfigurer#registerDefaultListenerInvocationErrorHandler(Function)
*/
private void configureListenerInvocationErrorHandler(BeanManager beanManager) {
if (nonNull(listenerInvocationErrorHandlerComponent)) {
Configurable<ListenerInvocationErrorHandler> configurable =
ConfigurableComponentResolver.of(listenerInvocationErrorHandlerComponent).resolve(beanManager);
configurer = configurer.eventProcessing(eventProcessingConfigurer ->
eventProcessingConfigurer.registerDefaultListenerInvocationErrorHandler(configurable));
log.debug("Configured default ListenerInvocationErrorHandler: {}", listenerInvocationErrorHandlerComponent);
}
}

Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ allprojects {
val axonVersion by extra("4.1.1")

group = "com.scalified"
version = "$axonVersion-RC1"
version = "$axonVersion-RC2"

repositories {
mavenCentral()
Expand Down