From 15b4488ca70ea2c8d02b591d1e6cd21a80bd1950 Mon Sep 17 00:00:00 2001 From: Mark Fisher Date: Tue, 1 Feb 2011 17:52:33 -0500 Subject: [PATCH] INT-1772 The 'send-timeout' attribute is now available on inbound-channel-adapter elements --- .../SourcePollingChannelAdapterFactoryBean.java | 11 ++++++++++- ...stractPollingInboundChannelAdapterParser.java | 3 ++- .../config/xml/spring-integration-1.0.xsd | 16 +++++++++++++++- .../config/ChannelAdapterParserTests-context.xml | 11 +++++++++++ .../config/ChannelAdapterParserTests.java | 13 ++++++++++++- 5 files changed, 50 insertions(+), 4 deletions(-) diff --git a/org.springframework.integration/src/main/java/org/springframework/integration/config/SourcePollingChannelAdapterFactoryBean.java b/org.springframework.integration/src/main/java/org/springframework/integration/config/SourcePollingChannelAdapterFactoryBean.java index 94d65c3b25..c4a0995a1f 100644 --- a/org.springframework.integration/src/main/java/org/springframework/integration/config/SourcePollingChannelAdapterFactoryBean.java +++ b/org.springframework.integration/src/main/java/org/springframework/integration/config/SourcePollingChannelAdapterFactoryBean.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2008 the original author or authors. + * Copyright 2002-2011 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. @@ -45,6 +45,8 @@ public class SourcePollingChannelAdapterFactoryBean private volatile PollerMetadata pollerMetadata; + private volatile Long sendTimeout; + private volatile boolean autoStartup = true; private volatile String beanName; @@ -72,6 +74,10 @@ public class SourcePollingChannelAdapterFactoryBean this.pollerMetadata = pollerMetadata; } + public void setSendTimeout(Long sendTimeout) { + this.sendTimeout = sendTimeout; + } + public void setAutoStartup(boolean autoStartup) { this.autoStartup = autoStartup; } @@ -126,6 +132,9 @@ public class SourcePollingChannelAdapterFactoryBean } spca.setTrigger(this.pollerMetadata.getTrigger()); spca.setMaxMessagesPerPoll(this.pollerMetadata.getMaxMessagesPerPoll()); + if (this.sendTimeout != null) { + spca.setSendTimeout(this.sendTimeout); + } spca.setTaskExecutor(this.pollerMetadata.getTaskExecutor()); spca.setTransactionManager(this.pollerMetadata.getTransactionManager()); spca.setTransactionDefinition(this.pollerMetadata.getTransactionDefinition()); diff --git a/org.springframework.integration/src/main/java/org/springframework/integration/config/xml/AbstractPollingInboundChannelAdapterParser.java b/org.springframework.integration/src/main/java/org/springframework/integration/config/xml/AbstractPollingInboundChannelAdapterParser.java index 27a4b1ca30..7eef9707ad 100644 --- a/org.springframework.integration/src/main/java/org/springframework/integration/config/xml/AbstractPollingInboundChannelAdapterParser.java +++ b/org.springframework.integration/src/main/java/org/springframework/integration/config/xml/AbstractPollingInboundChannelAdapterParser.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2008 the original author or authors. + * Copyright 2002-2011 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. @@ -45,6 +45,7 @@ public abstract class AbstractPollingInboundChannelAdapterParser extends Abstrac if (pollerElement != null) { IntegrationNamespaceUtils.configurePollerMetadata(pollerElement, adapterBuilder, parserContext); } + IntegrationNamespaceUtils.setValueIfAttributeDefined(adapterBuilder, element, "send-timeout"); IntegrationNamespaceUtils.setValueIfAttributeDefined(adapterBuilder, element, "auto-startup"); return adapterBuilder.getBeanDefinition(); } diff --git a/org.springframework.integration/src/main/resources/org/springframework/integration/config/xml/spring-integration-1.0.xsd b/org.springframework.integration/src/main/resources/org/springframework/integration/config/xml/spring-integration-1.0.xsd index 0d7ac73456..f0b7eec7b0 100644 --- a/org.springframework.integration/src/main/resources/org/springframework/integration/config/xml/spring-integration-1.0.xsd +++ b/org.springframework.integration/src/main/resources/org/springframework/integration/config/xml/spring-integration-1.0.xsd @@ -339,7 +339,7 @@ - + Defines a Channel Adapter that receives from a @@ -347,6 +347,20 @@ MessageChannel. + + + + + + + Maximum amount of time in milliseconds to wait when sending a message to the channel if such channel may block. + For example, a Queue Channel can block until space is available if its maximum capacity has been reached. + + + + + + diff --git a/org.springframework.integration/src/test/java/org/springframework/integration/config/ChannelAdapterParserTests-context.xml b/org.springframework.integration/src/test/java/org/springframework/integration/config/ChannelAdapterParserTests-context.xml index e1d37b6d0c..ac99984555 100644 --- a/org.springframework.integration/src/test/java/org/springframework/integration/config/ChannelAdapterParserTests-context.xml +++ b/org.springframework.integration/src/test/java/org/springframework/integration/config/ChannelAdapterParserTests-context.xml @@ -21,6 +21,17 @@ + + + + + + + + + + diff --git a/org.springframework.integration/src/test/java/org/springframework/integration/config/ChannelAdapterParserTests.java b/org.springframework.integration/src/test/java/org/springframework/integration/config/ChannelAdapterParserTests.java index be29f7a040..0017cc943b 100644 --- a/org.springframework.integration/src/test/java/org/springframework/integration/config/ChannelAdapterParserTests.java +++ b/org.springframework.integration/src/test/java/org/springframework/integration/config/ChannelAdapterParserTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2009 the original author or authors. + * Copyright 2002-2011 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. @@ -36,6 +36,7 @@ import org.springframework.integration.core.MessageChannel; import org.springframework.integration.endpoint.EventDrivenConsumer; import org.springframework.integration.endpoint.SourcePollingChannelAdapter; import org.springframework.integration.message.StringMessage; +import org.springframework.integration.util.TestUtils; /** * @author Mark Fisher @@ -180,4 +181,14 @@ public class ChannelAdapterParserTests { channelResolver.resolveChannelName("methodInvokingSource"); } + @Test + public void methodInvokingSourceWithSendTimeout() throws Exception{ + String beanName = "methodInvokingSourceWithTimeout"; + SourcePollingChannelAdapter adapter = + (SourcePollingChannelAdapter) this.applicationContext.getBean(beanName); + assertNotNull(adapter); + long sendTimeout = TestUtils.getPropertyValue(adapter, "channelTemplate.sendTimeout", Long.class); + assertEquals(999, sendTimeout); + } + }