My requirement is that I would like to stop the poller after a fixed interval of time say 9 (hrs.). For now I am trying to stop the poller after 1 min. Following is my code:
<int-task:scheduler id="scheduler" pool-size="10"/>
<int-task:scheduled-tasks scheduler="scheduler">
<int-task:scheduled ref="incomingFiles.adapter" method="stop" fixed-delay="#{10 * 1000}"/>
</int-task:scheduled-tasks>
But now what I observe is that when I start my program then on startup I immediately get the message in the console as:
> INFO: Starting beans in phase 0 May 28, 2014 10:27:55 AM
> org.springframework.integration.endpoint.AbstractEndpoint start INFO:
> started incomingFiles.adapter May 28, 2014 10:27:55 AM
> org.springframework.integration.endpoint.EventDrivenConsumer
> logComponentSubscriptionEvent INFO: Adding {service-activator} as a
> subscriber to the 'incomingFiles' channel May 28, 2014 10:27:55 AM
> org.springframework.integration.channel.AbstractSubscribableChannel
> adjustCounterIfNecessary INFO: Channel
> 'org.springframework.context.support.ClassPathXmlApplicationContext@f4d5bc9.incomingFiles'
> has 1 subscriber(s). May 28, 2014 10:27:55 AM
> org.springframework.integration.endpoint.AbstractEndpoint start INFO:
> started
> org.springframework.integration.config.ConsumerEndpointFactoryBean#0
> May 28, 2014 10:27:55 AM
> org.springframework.integration.endpoint.EventDrivenConsumer
> logComponentSubscriptionEvent INFO: Adding {router} as a subscriber to
> the 'contextStartedEventChannelChannel' channel May 28, 2014 10:27:55
> AM org.springframework.integration.channel.AbstractSubscribableChannel
> adjustCounterIfNecessary INFO: Channel
> 'org.springframework.context.support.ClassPathXmlApplicationContext@f4d5bc9.contextStartedEventChannelChannel'
> has 1 subscriber(s). May 28, 2014 10:27:55 AM
> org.springframework.integration.endpoint.AbstractEndpoint start INFO:
> started
> org.springframework.integration.config.ConsumerEndpointFactoryBean#1
> May 28, 2014 10:27:55 AM
> org.springframework.integration.endpoint.EventDrivenConsumer
> logComponentSubscriptionEvent INFO: Adding
> {outbound-channel-adapter:trueChannel.adapter} as a subscriber to the
> 'trueChannel' channel May 28, 2014 10:27:55 AM
> org.springframework.integration.channel.AbstractSubscribableChannel
> adjustCounterIfNecessary INFO: Channel
> 'org.springframework.context.support.ClassPathXmlApplicationContext@f4d5bc9.trueChannel'
> has 1 subscriber(s). May 28, 2014 10:27:55 AM
> org.springframework.integration.endpoint.AbstractEndpoint start INFO:
> started trueChannel.adapter May 28, 2014 10:27:55 AM
> org.springframework.integration.endpoint.EventDrivenConsumer
> logComponentSubscriptionEvent INFO: Adding
> {outbound-channel-adapter:falseChannel.adapter} as a subscriber to the
> 'falseChannel' channel May 28, 2014 10:27:55 AM
> org.springframework.integration.channel.AbstractSubscribableChannel
> adjustCounterIfNecessary INFO: Channel
> 'org.springframework.context.support.ClassPathXmlApplicationContext@f4d5bc9.falseChannel'
> has 1 subscriber(s). May 28, 2014 10:27:55 AM
> org.springframework.integration.endpoint.AbstractEndpoint start INFO:
> started falseChannel.adapter May 28, 2014 10:27:55 AM
> org.springframework.integration.endpoint.EventDrivenConsumer
> logComponentSubscriptionEvent INFO: Adding
> {logging-channel-adapter:_org.springframework.integration.errorLogger}
> as a subscriber to the 'errorChannel' channel May 28, 2014 10:27:55 AM
> org.springframework.integration.channel.AbstractSubscribableChannel
> adjustCounterIfNecessary INFO: Channel
> 'org.springframework.context.support.ClassPathXmlApplicationContext@f4d5bc9.errorChannel'
> has 1 subscriber(s). May 28, 2014 10:27:55 AM
> org.springframework.integration.endpoint.AbstractEndpoint start INFO:
> started _org.springframework.integration.errorLogger May 28, 2014
> 10:27:55 AM
> org.springframework.integration.file.FileReadingMessageSource receive
> INFO: Created message: [[Payload File
> content=C:\TEMP\incomingFile\ETD.CONFIRM.60326.140519.T0613170][Headers={id=b003893a-e013-57c8-0c96-55db627ec643, timestamp=1401287275402}]] May 28, 2014 10:27:55 AM
> org.springframework.integration.endpoint.AbstractEndpoint stop INFO:
> stopped incomingFiles.adapter
Somewhere in the start of the starttup logs we get:
May 28, 2014 10:27:55 AM org.springframework.integration.endpoint.AbstractE ndpoint start INFO: started incomingFiles.adapter
Somewhere in the end of the startup logs we get:
May 28, 2014 10:27:55 AM org.springframework.integration.endpoint.AbstractE ndpoint stop INFO: stopped incomingFiles.adapter
Why the incomingFiles.adapter has been stopped immediately while our fixed-delay="#{10 * 1000}" is 10 sec. Time is exactly same and there is absolutely no delay. So ideally the poller should stop after 10 sec. and not immediately. Also there are 4 files in the directory and its picking up only one.
Please do suggest what's wrong.
Well, I see. The
<int-task:scheduled ref="incomingFiles.adapter" method="stop"
fixed-delay="#{10 * 1000}"/>
produces PeriodicTrigger
which result (nextExecutionTime
) depends on triggerContext.lastScheduledExecutionTime()
and if it is null
(your case) it invokes underlying method immidiatelly.
Let's try this!
<task:scheduled ref="incomingFiles.adapter" method="stop"
fixed-delay="#{10 * 1000}" initial-delay="#{10 * 1000}"/>
I mean the same value for the initial-delay
to postpone the first stop task for the desired time.