Added support for the <poller/> sub-element within <service-activator/> and <channel-adapter/>.
This commit is contained in:
@@ -21,9 +21,12 @@ import org.w3c.dom.Element;
|
||||
import org.springframework.beans.factory.config.BeanDefinitionHolder;
|
||||
import org.springframework.beans.factory.parsing.BeanComponentDefinition;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionReaderUtils;
|
||||
import org.springframework.beans.factory.xml.BeanDefinitionParserDelegate;
|
||||
import org.springframework.beans.factory.xml.ParserContext;
|
||||
import org.springframework.integration.endpoint.DefaultEndpointPoller;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.util.xml.DomUtils;
|
||||
|
||||
/**
|
||||
* Shared utility methods for integration namespace parsers.
|
||||
@@ -80,4 +83,48 @@ public abstract class IntegrationNamespaceUtils {
|
||||
return beanDefinitionHolder.getBeanName();
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse a "poller" element and return the bean name of the poller instance.
|
||||
* The name will be generated for a newly created bean, or if the poller
|
||||
* element simply provides a "ref", that value will be returned.
|
||||
*
|
||||
* @param element the "poller" element to parse
|
||||
* @param parserContext the parserContext for registering a newly created bean definition
|
||||
* @return the name of the poller bean definition
|
||||
*/
|
||||
public static String parsePoller(Element element, ParserContext parserContext) {
|
||||
String ref = element.getAttribute("ref");
|
||||
String taskExecutorRef = element.getAttribute("task-executor");
|
||||
Element txElement = DomUtils.getChildElementByTagName(element, "transactional");
|
||||
if (StringUtils.hasText(ref)) {
|
||||
if (StringUtils.hasText(taskExecutorRef) || (txElement != null)) {
|
||||
parserContext.getReaderContext().error(
|
||||
"Neither the 'task-executor' attribute or 'transactional' sub-element "
|
||||
+ "should be provided when using the 'ref' attribute.",
|
||||
parserContext.extractSource(element));
|
||||
}
|
||||
return ref;
|
||||
}
|
||||
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(DefaultEndpointPoller.class);
|
||||
if (txElement != null) {
|
||||
builder.addPropertyReference("transactionManager", txElement.getAttribute("transaction-manager"));
|
||||
builder.addPropertyValue("propagationBehaviorName", txElement.getAttribute("propagation"));
|
||||
builder.addPropertyValue("isolationLevelName", txElement.getAttribute("isolation"));
|
||||
builder.addPropertyValue("transactionTimeout", txElement.getAttribute("timeout"));
|
||||
builder.addPropertyValue("transactionReadOnly", txElement.getAttribute("read-only"));
|
||||
}
|
||||
if (StringUtils.hasText(taskExecutorRef)) {
|
||||
builder.addPropertyReference("taskExecutor", taskExecutorRef);
|
||||
}
|
||||
String receiveTimeout = element.getAttribute("receive-timeout");
|
||||
if (StringUtils.hasText(receiveTimeout)) {
|
||||
builder.addPropertyValue("receiveTimeout", Long.parseLong(receiveTimeout));
|
||||
}
|
||||
String sendTimeout = element.getAttribute("send-timeout");
|
||||
if (StringUtils.hasText(sendTimeout)) {
|
||||
builder.addPropertyValue("sendTimeout", Long.parseLong(sendTimeout));
|
||||
}
|
||||
return BeanDefinitionReaderUtils.registerWithGeneratedName(builder.getBeanDefinition(), parserContext.getRegistry());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -242,6 +242,7 @@
|
||||
<xsd:extension base="beans:identifiedType">
|
||||
<xsd:all>
|
||||
<xsd:element ref="schedule" minOccurs="0" maxOccurs="1"/>
|
||||
<xsd:element ref="poller" minOccurs="0" maxOccurs="1"/>
|
||||
<xsd:element name="interceptors" type="interceptorsType" minOccurs="0" maxOccurs="1"/>
|
||||
</xsd:all>
|
||||
<xsd:attribute name="ref" type="xsd:string" use="required"/>
|
||||
@@ -263,6 +264,23 @@
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
|
||||
<xsd:element name="poller">
|
||||
<xsd:complexType>
|
||||
<xsd:annotation>
|
||||
<xsd:documentation>
|
||||
Defines a poller.
|
||||
</xsd:documentation>
|
||||
</xsd:annotation>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="transactional" type="transactionalType" minOccurs="0" maxOccurs="1"/>
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="ref" type="xsd:string"/>
|
||||
<xsd:attribute name="task-executor" type="xsd:string"/>
|
||||
<xsd:attribute name="receive-timeout" type="xsd:long"/>
|
||||
<xsd:attribute name="send-timeout" type="xsd:long"/>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
|
||||
<xsd:element name="handler-chain">
|
||||
<xsd:complexType>
|
||||
<xsd:annotation>
|
||||
@@ -328,6 +346,36 @@
|
||||
<xsd:attribute name="keep-alive" type="xsd:int"/>
|
||||
</xsd:complexType>
|
||||
|
||||
<xsd:element name="pool-executor">
|
||||
<xsd:complexType>
|
||||
<xsd:annotation>
|
||||
<xsd:documentation>
|
||||
Defines a ThreadPoolTaskExecutor.
|
||||
</xsd:documentation>
|
||||
</xsd:annotation>
|
||||
<xsd:attribute name="id" type="xsd:ID" use="required"/>
|
||||
<xsd:attribute name="core-size" type="xsd:int" use="optional" default="1"/>
|
||||
<xsd:attribute name="max-size" type="xsd:int" use="optional" default="10"/>
|
||||
<xsd:attribute name="queue-capacity" type="xsd:int" use="optional" default="0"/>
|
||||
<xsd:attribute name="keep-alive-seconds" type="xsd:int" use="optional" default="60"/>
|
||||
<xsd:attribute name="rejection-policy" default="CALLER_RUNS">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
The RejectedExecutionHandler type.
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
<xsd:simpleType>
|
||||
<xsd:restriction base="xsd:string">
|
||||
<xsd:enumeration value="ABORT"/>
|
||||
<xsd:enumeration value="CALLER_RUNS"/>
|
||||
<xsd:enumeration value="DISCARD"/>
|
||||
<xsd:enumeration value="DISCARD_OLDEST"/>
|
||||
</xsd:restriction>
|
||||
</xsd:simpleType>
|
||||
</xsd:attribute>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
|
||||
<xsd:element name="router" type="inputHandlerEndpointType">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation>
|
||||
@@ -413,18 +461,18 @@
|
||||
<xsd:attribute name="bean" use="required"/>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="transaction-interceptor" type="transactionInterceptorType" minOccurs="0" maxOccurs="1"/>
|
||||
<xsd:element name="transaction-interceptor" type="transactionalType" minOccurs="0" maxOccurs="1"/>
|
||||
<xsd:element name="concurrency-interceptor" type="concurrencyInterceptorType" minOccurs="0" maxOccurs="1"/>
|
||||
<xsd:any namespace="##other" processContents="strict" minOccurs="0" maxOccurs="unbounded"/>
|
||||
</xsd:choice>
|
||||
</xsd:sequence>
|
||||
</xsd:complexType>
|
||||
|
||||
<xsd:complexType name="transactionInterceptorType">
|
||||
<xsd:attribute name="transaction-manager" type="xsd:string">
|
||||
<xsd:complexType name="transactionalType">
|
||||
<xsd:attribute name="transaction-manager" type="xsd:string" default="transactionManager">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
The bean name of the PlatformTransactionManager to use. The default is "transactionManager".
|
||||
The bean name of the PlatformTransactionManager to use.
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
|
||||
@@ -37,7 +37,7 @@ public class SourceEndpoint extends AbstractEndpoint {
|
||||
|
||||
@Override
|
||||
public void initialize() {
|
||||
if (this.getOutputChannelName() == null && this.getOutputChannel() == null) {
|
||||
if (this.getOutputChannel() == null) {
|
||||
throw new ConfigurationException(
|
||||
"no output channel has been configured for source endpoint '" + this.getName() + "'");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user