INT-4361: Add a role() hook to Java DSL
JIRA: https://jira.spring.io/browse/INT-4361 * To get a gain of the method chain code flow and avoid extra annotation parsing, add `.role(String)` hook to the `EndpointSpec` * Delegate the provided `role` property to the `AbstractEndpoint` * Register `AbstractEndpoint` as itself `SmartLifecycle` in the `SmartLifecycleRoleController` * Add `destroy()` to the `AbstractEndpoint` and remove it from the `SmartLifecycleRoleController` * Provide some Java 8 code style refactoring * Rework XML parsers and Annotation processors to populate `role` property on the `AbstractEndpoint` * Wrap `roleController` bean extraction to the `NoSuchBeanDefinitionException` catch * Fix several `AbstractEndpoint` implementation to properly call `super.onInit()` which has been missed before
This commit is contained in:
committed by
Gary Russell
parent
a61327766e
commit
f7e75223c7
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2016 the original author or authors.
|
||||
* Copyright 2016-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -89,6 +89,7 @@ public class JmsInboundGateway extends MessagingGatewaySupport implements Dispos
|
||||
@Override
|
||||
public void destroy() throws Exception {
|
||||
this.endpoint.destroy();
|
||||
super.destroy();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -150,6 +150,8 @@ public class JmsMessageDrivenEndpoint extends MessageProducerSupport implements
|
||||
|
||||
@Override
|
||||
protected void onInit() {
|
||||
super.onInit();
|
||||
|
||||
this.listener.afterPropertiesSet();
|
||||
if (!this.listenerContainer.isActive()) {
|
||||
this.listenerContainer.afterPropertiesSet();
|
||||
@@ -161,7 +163,7 @@ public class JmsMessageDrivenEndpoint extends MessageProducerSupport implements
|
||||
}
|
||||
Integer acknowledgeMode = JmsAdapterUtils.parseAcknowledgeMode(sessionAcknowledgeMode);
|
||||
if (acknowledgeMode != null) {
|
||||
if (acknowledgeMode.intValue() == JmsAdapterUtils.SESSION_TRANSACTED) {
|
||||
if (JmsAdapterUtils.SESSION_TRANSACTED == acknowledgeMode) {
|
||||
this.listenerContainer.setSessionTransacted(true);
|
||||
}
|
||||
else {
|
||||
@@ -191,16 +193,15 @@ public class JmsMessageDrivenEndpoint extends MessageProducerSupport implements
|
||||
this.stop();
|
||||
}
|
||||
this.listenerContainer.destroy();
|
||||
super.destroy();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int beforeShutdown() {
|
||||
this.stop();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int afterShutdown() {
|
||||
return 0;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -110,20 +110,14 @@ public class JmsMessageDrivenEndpointParser extends AbstractSingleBeanDefinition
|
||||
|
||||
@Override
|
||||
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
|
||||
String containerBeanName = this.parseMessageListenerContainer(element, parserContext, builder.getRawBeanDefinition());
|
||||
String listenerBeanName = this.parseMessageListener(element, parserContext, builder.getRawBeanDefinition());
|
||||
String containerBeanName = parseMessageListenerContainer(element, parserContext, builder.getRawBeanDefinition());
|
||||
String listenerBeanName = parseMessageListener(element, parserContext, builder.getRawBeanDefinition());
|
||||
builder.addConstructorArgReference(containerBeanName);
|
||||
builder.addConstructorArgReference(listenerBeanName);
|
||||
builder.addConstructorArgValue(hasExternalContainer(element));
|
||||
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, IntegrationNamespaceUtils.AUTO_STARTUP);
|
||||
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, IntegrationNamespaceUtils.PHASE);
|
||||
String role = element.getAttribute(IntegrationNamespaceUtils.ROLE);
|
||||
if (StringUtils.hasText(role)) {
|
||||
if (!StringUtils.hasText(element.getAttribute(ID_ATTRIBUTE))) {
|
||||
parserContext.getReaderContext().error("When using 'role', 'id' is required", element);
|
||||
}
|
||||
IntegrationNamespaceUtils.putLifecycleInRole(role, element.getAttribute(ID_ATTRIBUTE), parserContext);
|
||||
}
|
||||
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, IntegrationNamespaceUtils.ROLE);
|
||||
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "acknowledge", "sessionAcknowledgeMode");
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user