Announcement Announcement Module
Collapse
No announcement yet.
Possible to delay starting the message store reaper? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Possible to delay starting the message store reaper?

    Hi,

    In the application I'm working on the objects are fetched from a database. The queries use cursors. Once the query plan is ready the data arrives in a constant stream. However, at the beginning, the application pauses for a few minutes while the database is configuring the query plans etc...

    I'm using an aggregator to aggregate an object I will call 'A'. A is aggregated with objects 'B' and 'C' which are both optional. So the reaper should expire A after some timeout, even if B and/or C have not arrived. A, B, C and fetched via separate cursors. Once A is known B and C are fetched subsequently.

    Because of the queries mentioned, at the start of the application B and C, if they exist, will arrive a few minutes after A does. However, after that B and C will arrive within a few seconds after A since the database is now providing a constant stream of objects.

    I would like to use a reaper to expire A objects but the timeout varies from minutes at the start, and then seconds later on. I thought if I could delay starting the reaper until the data flow has started up then it would work.

    Any thoughts non how to start up the reaper based on some application event? I did notice the control bus section in the manual but I'm not sure if that applies.

    Or perhaps there is another approach that would work?

    Thanks,
    Matt

  • #2
    Here's an idea. I will attempt to use the control bus to pause and unpause the reaper. This way I don't have to try to futz with the scheduler. Please let me know if this looks reasonable. Thanks.

    Code:
    public class ControllableMessageGroupStoreReaper extends MessageGroupStoreReaper {
    
        Logger logger = LoggerFactory.getLogger(ControllableMessageGroupStoreReaper.class);
    
        // paused by default
        private volatile boolean paused = true;
    
        public synchronized boolean isPaused() {
            return paused;
        }
    
        public synchronized void setPaused(boolean paused) {
            this.paused = paused;
        }
    
        @Override
        public void run() {
    
            if( isPaused()) {
                logger.debug("Paused. Not calling the target reaper object.");
            } else {
                logger.debug("Not Paused. Calling the target reaper object.");
            }
    
            if( ! isPaused()) {
                super.run();
            }
        }
    }

    Comment


    • #3
      Hello!

      Do you configure it like this?
      HTML Code:
      <task:scheduled-tasks>
      	<task:scheduled ref="reaper" method="run" fixed-rate="2000" />
      </task:scheduled-tasks>
      As you can see <task:scheduled> has another attribure trigger.
      So you can simply inject here a PeriodicTrigger bean with its initialDelay property.

      However I see MessageGroupStoreReaper implements SmartLifecycle but it doesn't check own state in run() to determine should it expire MessageGroups or not.
      Please, raise an issue and we will take care of this simple bug: https://jira.springsource.org/browse/INT

      Cheers,
      Artem

      Comment


      • #4
        Thanks for this. However, I don't really know what the initial delay will be. It can vary depending on the size of the data set. It isn't predictable.

        That's why I opted to be able to pause the reaper itself so that I can turn the effects of the reaper on and off.

        I'll raise an issue as you've suggested.

        Thanks,
        Matt

        Comment


        • #5
          ControllableMessageGroupStoreReaper extends MessageGroupStoreReaper
          Hey!
          you provide good idea: here you can implement what I've asked for JIRA:
          1. On reaper bean autoStartup = fasle
          2.
          Code:
              @Override
              public void run() {
                  if(isRunning()) {
                      super.run();
                  }
              }
          Any SmartLifecycle bean is accessible from Control Bus:
          HTML Code:
          <control-bus input-channel="controlBusChannel"/>
          <service-activator input-channel="reaperReadyChannel" output-channel="controlBusChannel"
          expression="'@reaper.start()'"/>
          reaperReadyChannel can be triggerd via <event:inbound-channel-adapter/>

          Comment


          • #6
            Looks like that would work for me. Great!

            Comment


            • #7
              You are welcome!
              The JIRA: https://jira.springsource.org/browse/INT-2878

              Comment

              Working...
              X