The <endpoint/> element is now <handler-endpoint/>, and its "handler-method" attribute is now "method".

This commit is contained in:
Mark Fisher
2008-04-27 05:01:38 +00:00
parent 412c5b3134
commit 9eaa088052
25 changed files with 68 additions and 70 deletions

View File

@@ -34,7 +34,7 @@ public class MethodInvokingHandler implements MessageHandler, InitializingBean {
private volatile Object object;
private volatile String method;
private volatile String methodName;
private volatile MessageMapper messageMapper;
@@ -48,9 +48,9 @@ public class MethodInvokingHandler implements MessageHandler, InitializingBean {
this.object = object;
}
public void setMethod(String method) {
Assert.notNull(method, "'method' must not be null");
this.method = method;
public void setMethodName(String methodName) {
Assert.notNull(methodName, "'methodName' must not be null");
this.methodName = methodName;
}
public void setMessageMapper(MessageMapper messageMapper) {
@@ -62,7 +62,7 @@ public class MethodInvokingHandler implements MessageHandler, InitializingBean {
}
public void afterPropertiesSet() {
this.invoker = new HandlerMethodInvoker(this.object, this.method);
this.invoker = new HandlerMethodInvoker(this.object, this.methodName);
}
public Message<?> handle(Message<?> message) {

View File

@@ -134,7 +134,7 @@ public abstract class AbstractTargetEndpointParser extends AbstractSingleBeanDef
if (!StringUtils.hasText(ref)) {
throw new ConfigurationException("The '" + attribute + "' attribute is required.");
}
String method = element.getAttribute(attribute + "-method");
String method = element.getAttribute("method");
if (StringUtils.hasText(method)) {
String adapterBeanName = this.parseAdapter(ref, method, parserContext);
builder.addConstructorArgReference(adapterBeanName);

View File

@@ -52,7 +52,7 @@ public class IntegrationNamespaceHandler extends NamespaceHandlerSupport {
registerBeanDefinitionParser("source-adapter", new MethodInvokingAdapterParser());
registerBeanDefinitionParser("target-adapter", new MethodInvokingAdapterParser());
registerBeanDefinitionParser("source-endpoint", new SourceEndpointParser());
registerBeanDefinitionParser("endpoint", new EndpointParser());
registerBeanDefinitionParser("handler-endpoint", new EndpointParser());
registerBeanDefinitionParser("target-endpoint", new TargetEndpointParser());
registerBeanDefinitionParser("handler", new HandlerParser());
registerBeanDefinitionParser("handler-chain", new HandlerParser());

View File

@@ -185,7 +185,7 @@ public class MessageEndpointAnnotationPostProcessor implements BeanPostProcessor
}
MethodInvokingTarget target = new MethodInvokingTarget();
target.setObject(bean);
target.setMethod(method.getName());
target.setMethodName(method.getName());
target.afterPropertiesSet();
MessageHandler handler = endpoint.getHandler();
((MessageHandlerChain) handler).add(target);

View File

@@ -139,7 +139,7 @@
</xsd:annotation>
</xsd:element>
<xsd:element name="endpoint">
<xsd:element name="handler-endpoint">
<xsd:complexType>
<xsd:annotation>
<xsd:documentation>
@@ -150,7 +150,7 @@
<xsd:extension base="targetEndpointType">
<xsd:attribute name="default-output-channel" type="xsd:string"/>
<xsd:attribute name="handler" type="xsd:string" use="required"/>
<xsd:attribute name="handler-method" type="xsd:string"/>
<xsd:attribute name="method" type="xsd:string"/>
<xsd:attribute name="reply-handler" type="xsd:string"/>
<xsd:attribute name="return-address-overrides" type="xsd:boolean" default="false"/>
</xsd:extension>

View File

@@ -44,7 +44,7 @@ public class MethodInvokingTargetTests {
public void testValidMethod() {
MethodInvokingTarget target = new MethodInvokingTarget();
target.setObject(new TestSink());
target.setMethod("validMethod");
target.setMethodName("validMethod");
target.afterPropertiesSet();
boolean result = target.send(new GenericMessage<String>("test"));
assertTrue(result);
@@ -54,7 +54,7 @@ public class MethodInvokingTargetTests {
public void testInvalidMethodWithNoArgs() {
MethodInvokingTarget target = new MethodInvokingTarget();
target.setObject(new TestSink());
target.setMethod("invalidMethodWithNoArgs");
target.setMethodName("invalidMethodWithNoArgs");
target.afterPropertiesSet();
target.send(new StringMessage("test"));
}
@@ -63,7 +63,7 @@ public class MethodInvokingTargetTests {
public void testMethodWithReturnValue() {
MethodInvokingTarget target = new MethodInvokingTarget();
target.setObject(new TestSink());
target.setMethod("methodWithReturnValue");
target.setMethodName("methodWithReturnValue");
target.afterPropertiesSet();
boolean result = target.send(new StringMessage("test"));
assertTrue(result);
@@ -73,7 +73,7 @@ public class MethodInvokingTargetTests {
public void testNoMatchingMethodName() {
MethodInvokingTarget target = new MethodInvokingTarget();
target.setObject(new TestSink());
target.setMethod("noSuchMethod");
target.setMethodName("noSuchMethod");
target.afterPropertiesSet();
target.send(new StringMessage("test"));
}
@@ -84,7 +84,7 @@ public class MethodInvokingTargetTests {
TestBean testBean = new TestBean(queue);
MethodInvokingTarget target = new MethodInvokingTarget();
target.setObject(testBean);
target.setMethod("foo");
target.setMethodName("foo");
target.afterPropertiesSet();
QueueChannel channel = new QueueChannel();
Subscription subscription = new Subscription(channel);

View File

@@ -29,7 +29,7 @@
<bean id="target" class="org.springframework.integration.adapter.MethodInvokingTarget">
<property name="object" ref="sink"/>
<property name="method" value="store"/>
<property name="methodName" value="store"/>
</bean>
<bean id="targetEndpoint" class="org.springframework.integration.endpoint.TargetEndpoint">

View File

@@ -15,12 +15,10 @@
<si:schedule period="100"/>
</si:source-endpoint>
<si:endpoint handler="targetAdapter" input-channel="channel"/>
<si:target-endpoint target="sink" method="store" input-channel="channel"/>
<si:source-adapter id="sourceAdapter" ref="source" method="foo"/>
<si:target-adapter id="targetAdapter" ref="sink" method="store"/>
<bean id="source" class="org.springframework.integration.adapter.TestSource"/>
<bean id="sink" class="org.springframework.integration.adapter.TestSink"/>

View File

@@ -11,13 +11,13 @@
<channel id="testChannel"/>
<endpoint id="defaultConcurrencyEndpoint" input-channel="testChannel" handler="testHandler">
<handler-endpoint id="defaultConcurrencyEndpoint" input-channel="testChannel" handler="testHandler">
<concurrency/>
</endpoint>
</handler-endpoint>
<endpoint id="configuredConcurrencyEndpoint" input-channel="testChannel" handler="testHandler">
<handler-endpoint id="configuredConcurrencyEndpoint" input-channel="testChannel" handler="testHandler">
<concurrency core="7" max="77" queue-capacity="777" keep-alive="7777"/>
</endpoint>
</handler-endpoint>
<beans:bean id="testHandler" class="org.springframework.integration.config.TestHandler">
<beans:constructor-arg value="1"/>

View File

@@ -11,7 +11,7 @@
<channel id="testChannel"/>
<endpoint id="endpoint" input-channel="testChannel" handler="testHandler" error-handler="errorHandler"/>
<handler-endpoint id="endpoint" input-channel="testChannel" handler="testHandler" error-handler="errorHandler"/>
<beans:bean id="testHandler" class="org.springframework.integration.config.ExceptionThrowingTestHandler"/>

View File

@@ -19,9 +19,9 @@
<handler ref="handler3"/>
</handler-chain>
<endpoint input-channel="testChannel" handler="chain" default-output-channel="replyChannel">
<handler-endpoint input-channel="testChannel" handler="chain" default-output-channel="replyChannel">
<schedule period="100"/>
</endpoint>
</handler-endpoint>
<beans:bean id="handler1" class="org.springframework.integration.config.TestConcatenatingHandler">
<beans:constructor-arg value="-1"/>

View File

@@ -11,7 +11,7 @@
<channel id="testChannel"/>
<endpoint id="endpoint" input-channel="testChannel" handler="testHandler" reply-handler="replyHandler"/>
<handler-endpoint id="endpoint" input-channel="testChannel" handler="testHandler" reply-handler="replyHandler"/>
<beans:bean id="testHandler" class="org.springframework.integration.config.TestHandler">
<beans:property name="replyMessageText" value="foo"/>

View File

@@ -11,10 +11,10 @@
<channel id="testChannel" capacity="50"/>
<endpoint id="endpoint" input-channel="testChannel" handler="testHandler">
<handler-endpoint id="endpoint" input-channel="testChannel" handler="testHandler">
<schedule period="100"/>
<selector ref="typeSelector"/>
</endpoint>
</handler-endpoint>
<beans:bean id="typeSelector" class="org.springframework.integration.message.selector.PayloadTypeSelector">
<beans:constructor-arg value="java.lang.String"/>

View File

@@ -11,9 +11,9 @@
<channel id="testChannel" capacity="50"/>
<endpoint input-channel="testChannel" handler="testBean" handler-method="store">
<handler-endpoint input-channel="testChannel" handler="testBean" method="store">
<schedule period="100"/>
</endpoint>
</handler-endpoint>
<beans:bean id="testBean" class="org.springframework.integration.config.TestBean">
<beans:constructor-arg value="1"/>

View File

@@ -13,11 +13,11 @@
<channel id="channel"/>
<endpoint id="endpoint1" handler="testHandler" input-channel="channel"/>
<handler-endpoint id="endpoint1" handler="testHandler" input-channel="channel"/>
<endpoint id="endpoint2" handler="testHandler" input-channel="channel">
<handler-endpoint id="endpoint2" handler="testHandler" input-channel="channel">
<concurrency core="14" max="17"/>
</endpoint>
</handler-endpoint>
<beans:bean id="testHandler" class="org.springframework.integration.config.TestHandler">
<beans:constructor-arg value="3"/>

View File

@@ -11,9 +11,9 @@
<channel id="testChannel" capacity="50"/>
<endpoint input-channel="testChannel" handler="testHandler">
<handler-endpoint input-channel="testChannel" handler="testHandler">
<schedule period="100"/>
</endpoint>
</handler-endpoint>
<beans:bean id="testHandler" class="org.springframework.integration.config.TestHandler">
<beans:constructor-arg value="1"/>

View File

@@ -18,16 +18,16 @@
<si:channel id="replyChannel"/>
<si:channel id="errorChannel"/>
<si:endpoint input-channel="channel1WithOverride" handler="testBean" handler-method="duplicate"
<si:handler-endpoint input-channel="channel1WithOverride" handler="testBean" method="duplicate"
default-output-channel="channel2" return-address-overrides="true"/>
<si:endpoint input-channel="channel3WithOverride" handler="testBean" handler-method="duplicate"
<si:handler-endpoint input-channel="channel3WithOverride" handler="testBean" method="duplicate"
return-address-overrides="true"/>
<si:endpoint input-channel="channel1" handler="testBean" handler-method="duplicate" default-output-channel="channel2"/>
<si:endpoint input-channel="channel2" handler="testBean" handler-method="duplicate" default-output-channel="channel3"/>
<si:endpoint input-channel="channel3" handler="testBean" handler-method="duplicate"/>
<si:endpoint input-channel="channel4" handler="testBean" handler-method="duplicate" default-output-channel="replyChannel"/>
<si:handler-endpoint input-channel="channel1" handler="testBean" method="duplicate" default-output-channel="channel2"/>
<si:handler-endpoint input-channel="channel2" handler="testBean" method="duplicate" default-output-channel="channel3"/>
<si:handler-endpoint input-channel="channel3" handler="testBean" method="duplicate"/>
<si:handler-endpoint input-channel="channel4" handler="testBean" method="duplicate" default-output-channel="replyChannel"/>
<bean id="testBean" class="org.springframework.integration.endpoint.TestBean"/>

View File

@@ -11,7 +11,7 @@
<channel id="requestChannel"/>
<endpoint handler="handler" input-channel="requestChannel"/>
<handler-endpoint handler="handler" input-channel="requestChannel"/>
<beans:bean id="proxy" class="org.springframework.integration.gateway.GatewayProxyFactoryBean">
<beans:property name="serviceInterface" value="org.springframework.integration.gateway.TestService"/>

View File

@@ -15,7 +15,7 @@
<interceptor ref="interceptor"/>
</channel>
<endpoint handler="handler" input-channel="requestChannel"/>
<handler-endpoint handler="handler" input-channel="requestChannel"/>
<beans:bean id="proxy" class="org.springframework.integration.gateway.GatewayProxyFactoryBean">
<beans:property name="serviceInterface" value="org.springframework.integration.gateway.TestService"/>

View File

@@ -124,15 +124,15 @@
<section id="namespace-endpoint">
<title>Configuring Message Endpoints</title>
<para>
To create a Message Endpoint instance, use the 'endpoint' element with the 'input-channel' and 'handler'
To create a Message Endpoint instance, use the 'handler-endpoint' element with the 'input-channel' and 'handler'
attributes:
<programlisting>&lt;endpoint input-channel="exampleChannel" handler="exampleHandler"/&gt;</programlisting>
</para>
<para>
The configuration above assumes that "exampleHandler" is an actual implementation of the
<interfacename>MessageHandler</interfacename> interface as described in <xref linkend="api-messagehandler"/>.
To delegate to an arbitrary method of any object, simply add the "handler-method" attribute.
<programlisting>&lt;endpoint input-channel="exampleChannel" handler="somePojo" handler-method="someMethod"/&gt;</programlisting>
To delegate to an arbitrary method of any object, simply add the "method" attribute.
<programlisting>&lt;endpoint input-channel="exampleChannel" handler="somePojo" method="someMethod"/&gt;</programlisting>
</para>
<para>
In either case (<interfacename>MessageHandler</interfacename> or arbitrary object/method), when the handling
@@ -147,16 +147,16 @@
default output channel when using the XML namespace, provide the 'default-output-channel' attribute:
<programlisting>&lt;endpoint input-channel="exampleChannel"
handler="somePojo"
handler-method="someMethod"
method="someMethod"
default-output-channel="replyChannel"/&gt;</programlisting>
</para>
<para>
Endpoint's also support <interfacename>MessageSelectors</interfacename> as described in
Endpoints also support <interfacename>MessageSelectors</interfacename> as described in
<xref linkend="api-messageselector"/>. To configure selectors with namespace support, simply add one or more
&lt;selector&gt; sub-elements to the endpoint definition:
<programlisting><![CDATA[<endpoint id="endpoint" input-channel="channel" handler="handler">
<programlisting><![CDATA[<handler-endpoint id="endpoint" input-channel="channel" handler="handler">
]]><emphasis><![CDATA[<selector ref="exampleSelector"/>]]></emphasis><![CDATA[
</endpoint>]]></programlisting>
</handler-endpoint>]]></programlisting>
</para>
<para>
When the <interfacename>MessageBus</interfacename> registers the endpoint, it will activate the subscription
@@ -164,9 +164,9 @@
endpoint subscriptions for its channel and delegates to a scheduler for managing the tasks that pull messages
from the channel and push them to the endpoints. To configure the polling period for an individual endpoint's
schedule, provide a 'schedule' sub-element with the 'period' in milliseconds:
<programlisting><![CDATA[<endpoint input-channel="exampleChannel" handler="exampleHandler"/>
<programlisting><![CDATA[<handler-endpoint input-channel="exampleChannel" handler="exampleHandler"/>
]]><emphasis><![CDATA[<schedule period="3000"/>]]></emphasis><![CDATA[
</endpoint>]]></programlisting>
</handler-endpoint>]]></programlisting>
</para>
<note>
Individual endpoint schedules only apply for "Point-to-Point" channels, since in that case only a single
@@ -182,9 +182,9 @@
consider (the other major factor being the expected volume on the channel to which the endpoint subscribes).
To enable concurrency for an endpoint that is configured with the XML namespace support, provide the
'concurrency' sub-element and one or more of the properties shown below:
<programlisting><![CDATA[<endpoint input-channel="exampleChannel" handler="exampleHandler"/>
<programlisting><![CDATA[<handler-endpoint input-channel="exampleChannel" handler="exampleHandler"/>
]]><emphasis><![CDATA[<concurrency core="5" max="25" queue-capacity="20" keep-alive="120"/>]]></emphasis><![CDATA[
</endpoint>]]></programlisting>
</handler-endpoint>]]></programlisting>
Recall the default concurrency policy values as listed in <xref linkend="api-messagebus-concurrencypolicy"/>.
If no concurrency settings are provided (i.e. a <emphasis>null</emphasis>
<classname>ConcurrencyPolicy</classname>), the endpoint's handler will be invoked in the caller's thread.

View File

@@ -49,11 +49,11 @@
<channel id="coldDrinks"/>
<channel id="hotDrinks"/>
<endpoint input-channel="coldDrinks" handler="barista"
handler-method="prepareColdDrink"/>
<handler-endpoint input-channel="coldDrinks" handler="barista"
method="prepareColdDrink"/>
<endpoint input-channel="hotDrinks" handler="barista"
handler-method="prepareHotDrink"/>
<handler-endpoint input-channel="hotDrinks" handler="barista"
method="prepareHotDrink"/>
<beans:bean id="cafe" class="org.springframework.integration.samples.cafe.Cafe">
<beans:property name="orderChannel" ref="orders"/>
@@ -163,11 +163,11 @@ public class Barista {
However, by configuring the endpoint concurrency, you can dramatically change the results. For example, on my
machine, the following single modification causes all 100 hot drinks to be prepared before the 4th cold drink is
ready:
<programlisting><![CDATA[<endpoint input-channel="coldDrinks" handler="barista" handler-method="prepareColdDrink"/>
<programlisting><![CDATA[<handler-endpoint input-channel="coldDrinks" handler="barista" method="prepareColdDrink"/>
<endpoint input-channel="hotDrinks" handler="barista" handler-method="prepareHotDrink">
<handler-endpoint input-channel="hotDrinks" handler="barista" method="prepareHotDrink">
]]><emphasis><![CDATA[<concurrency core="25" max="50"/>]]></emphasis><![CDATA[
</endpoint>]]></programlisting>
</handler-endpoint>]]></programlisting>
</para>
<para>
In addition to experimenting with the 'concurrency' settings, you can also try adding the 'schedule' sub-element

View File

@@ -20,8 +20,8 @@
<channel id="coldDrinks"/>
<channel id="hotDrinks"/>
<endpoint input-channel="coldDrinks" handler="barista" handler-method="prepareColdDrink"/>
<endpoint input-channel="hotDrinks" handler="barista" handler-method="prepareHotDrink"/>
<handler-endpoint input-channel="coldDrinks" handler="barista" method="prepareColdDrink"/>
<handler-endpoint input-channel="hotDrinks" handler="barista" method="prepareHotDrink"/>
<beans:bean id="cafe" class="org.springframework.integration.samples.cafe.Cafe">
<beans:property name="orderChannel" ref="orders"/>

View File

@@ -20,8 +20,8 @@
<channel id="coldDrinks"/>
<channel id="hotDrinks"/>
<endpoint input-channel="coldDrinks" handler="barista" handler-method="prepareColdDrink"/>
<endpoint input-channel="hotDrinks" handler="barista" handler-method="prepareHotDrink"/>
<handler-endpoint input-channel="coldDrinks" handler="barista" method="prepareColdDrink"/>
<handler-endpoint input-channel="hotDrinks" handler="barista" method="prepareHotDrink"/>
<beans:bean id="cafe" class="org.springframework.integration.samples.cafe.Cafe">
<beans:property name="orderChannel" ref="orders"/>

View File

@@ -19,8 +19,8 @@
<schedule period="30000"/>
</source-endpoint>
<endpoint input-channel="channel1" default-output-channel="channel2"
handler="exclaimer" handler-method="exclaim"/>
<handler-endpoint input-channel="channel1" default-output-channel="channel2"
handler="exclaimer" method="exclaim"/>
<file-source id="fileSource" directory="${java.io.tmpdir}/spring-integration-samples/input"/>

View File

@@ -9,10 +9,10 @@
<message-bus auto-create-channels="true"/>
<endpoint input-channel="inputChannel"
<handler-endpoint input-channel="inputChannel"
default-output-channel="outputChannel"
handler="helloService"
handler-method="sayHello"/>
method="sayHello"/>
<beans:bean id="helloService" class="org.springframework.integration.samples.helloworld.HelloService"/>