Results 1 to 7 of 7

Thread: Possible to delay starting the message store reaper?

  1. #1

    Default 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. #2

    Default

    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();
            }
        }
    }

  3. #3
    Join Date
    Jan 2009
    Location
    Ukraine, Kharkov
    Posts
    732

    Default

    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

  4. #4

    Default

    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

  5. #5
    Join Date
    Jan 2009
    Location
    Ukraine, Kharkov
    Posts
    732

    Default

    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/>

  6. #6

    Default

    Looks like that would work for me. Great!

  7. #7
    Join Date
    Jan 2009
    Location
    Ukraine, Kharkov
    Posts
    732

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •