Announcement Announcement Module
Collapse
No announcement yet.
Problems while trying to modify polling rate on runtime Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Problems while trying to modify polling rate on runtime

    Hi all,

    Having defined a channel adapter as:
    Code:
       
      <int:channel id="target">
    	<int:queue />
       </int:channel>
    
       <int-jdbc:inbound-channel-adapter id="adapter" channel="target" query="${int.poll.query}"  update="${int.update.query}" data-source="mock-datasource">
        	<int:poller fixed-rate="5000"/>
     </int-jdbc:inbound-channel-adapter>
    I wonder why I cannot modify the polling rate on runtime, as follows:
    Code:
    SourcePollingChannelAdapter adapter = applicationContext.getBean("adapter",SourcePollingChannelAdapter.class);
    adapter.setTrigger(new PeriodicTrigger(1000));
    When i debug this solution, I can see that the adapter has this new trigger attached to it, however the polling rate remains unchanged (every 5 secs). I tried also to stop() and start() the adapter, with similar luck.

    Anyone can point me out what I am doing wrong?
    Thanks

  • #2
    Any reason why you want to modify the polling rate?

    Comment


    • #3
      As a way to throttle inbound messages. I know that there are other ways to achieve this, however I wanted to know why you cannot modify this property on runtime.

      Comment


      • #4
        Under the covers we are simply creating a PeriodicTrigger instance (it is defined in the Spring Framework core), and it accepts the "interval" as a constructor argument. Therefore it cannot be changed at runtime. However, you can define your own implementation of the Trigger interface, even using the PeriodicTrigger as a starting point. Then, you could add a setter for the interval (or even embed your throttling logic within the trigger itself if possible). Then, the interval can be changed between polls. It will be used with each call to nextExecutionTime (to schedule the next poll), so that should have the desired effect. To use your poller, remove the 'fixed-rate' attribute from your poller element and add a 'trigger' attribute referencing your instance instead. In other words, you would provide a Trigger that has dynamic capabilities itself rather than changing the Trigger reference at runtime.

        Hope that helps.
        -Mark

        Comment


        • #5
          Going back to you original post, you CAN modify it if you implement your own Trigger and set it on the poller via 'trigger' attribute. You can than expose properties on the this custom Trigger implementation that allow you to change how the next execution time is calculated.
          Code:
          public interface Trigger {
          	Date nextExecutionTime(TriggerContext triggerContext);
          }
          Trigger is a very simple strategy (as yo can see from above) that defines only one method which is invoked by scheduler after each successful invocation of the task. What happens and how it happens in the Trigger.nextExecutionTime(..) is entirely up to the implementation.

          Comment


          • #6
            I have created a Jira to document this requirement in the reference manual:

            https://jira.springsource.org/browse/INT-2425

            Comment

            Working...
            X