camel-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Andrea Cosentino (JIRA)" <j...@apache.org>
Subject [jira] [Comment Edited] (CAMEL-9249) timer - Allow to specify a delay of -1 or something to indicate loop asap forever
Date Sat, 24 Oct 2015 12:17:27 GMT

    [ https://issues.apache.org/jira/browse/CAMEL-9249?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14972563#comment-14972563
] 

Andrea Cosentino edited comment on CAMEL-9249 at 10/24/15 12:16 PM:
--------------------------------------------------------------------

What I think we can do is something like this.

{code}
	@Override
	public void onCamelContextStarted(CamelContext context,
			boolean alreadyStarted) throws Exception {
		if (task != null && !configured && endpoint.getDelay() >= 0) {
			Timer timer = endpoint.getTimer(this);
			configureTask(task, timer);
		} else {
			final AtomicLong counter = new AtomicLong();
			long count = counter.incrementAndGet();
			while (count <= endpoint.getRepeatCount()) {
				sendTimerExchange(count);
				count = counter.incrementAndGet();
			}
		}
	}
{code}

In this case (delay < 0) you'll simply create Exchanges (with all the timer headers) and
process it, without registering a task.

This approach require a repeatCount parameter specified.

If we don't specified a repeatCount we can simply check isRunAllowed() 

{code}
    @Override
    public void onCamelContextStarted(CamelContext context, boolean alreadyStarted) throws
Exception {
        if (task != null && !configured && endpoint.getDelay() >= 0) {
            Timer timer = endpoint.getTimer(this);
            configureTask(task, timer);
        } else {
        	if (endpoint.getRepeatCount() > 0) {
        	final AtomicLong counter = new AtomicLong();
        	long count = counter.incrementAndGet();
            while (count <= endpoint.getRepeatCount()) {
            	System.err.println(count);
                    sendTimerExchange(count);
                    count = counter.incrementAndGet();
            }
        	} else {
            	final AtomicLong counter = new AtomicLong();
            	long count = counter.incrementAndGet();
                while (isRunAllowed()) {
                    sendTimerExchange(count);
                    count = counter.incrementAndGet();
                }        		
        	}
        }
    }
{code}

But in this case the loop will go forever.

Maybe we can check the presence of RepeatCount if a negative delay is specified.

What do you think about?


was (Author: ancosen):
What I think we can do is something like this.

{code}
	@Override
	public void onCamelContextStarted(CamelContext context,
			boolean alreadyStarted) throws Exception {
		if (task != null && !configured && endpoint.getDelay() >= 0) {
			Timer timer = endpoint.getTimer(this);
			configureTask(task, timer);
		} else {
			final AtomicLong counter = new AtomicLong();
			long count = counter.incrementAndGet();
			while (count <= endpoint.getRepeatCount()) {
				sendTimerExchange(count);
				count = counter.incrementAndGet();
			}
		}
	}
{code}

In this case (delay < 0) you'll simply create Exchanges (with all the timer headers) and
process it, without registering a task.

This approach require a repeatCount parameter specified.

If we don't specified a repeatCount we can simply check isRunAllowed() 

{code}
    @Override
    public void onCamelContextStarted(CamelContext context, boolean alreadyStarted) throws
Exception {
        if (task != null && !configured && endpoint.getDelay() >= 0) {
            Timer timer = endpoint.getTimer(this);
            configureTask(task, timer);
        } else {
        	if (endpoint.getRepeatCount() > 0) {
        	final AtomicLong counter = new AtomicLong();
        	long count = counter.incrementAndGet();
            while (count <= endpoint.getRepeatCount()) {
            	System.err.println(count);
                    sendTimerExchange(count);
                    count = counter.incrementAndGet();
            }
        	} else {
            	final AtomicLong counter = new AtomicLong();
            	long count = counter.incrementAndGet();
                while (isRunAllowed()) {
                    sendTimerExchange(count);
                    count = counter.incrementAndGet();
                }        		
        	}
        }
    }
{code}

But in this case the loop will go forever..

> timer - Allow to specify a delay of -1 or something to indicate loop asap forever
> ---------------------------------------------------------------------------------
>
>                 Key: CAMEL-9249
>                 URL: https://issues.apache.org/jira/browse/CAMEL-9249
>             Project: Camel
>          Issue Type: Improvement
>          Components: camel-core
>            Reporter: Claus Ibsen
>             Fix For: 2.17.0
>
>
> If you want to let a route trigger as fast as possible, then by settinh
> from timer:fast?delay=-1
>    to http blah
> then with the timer we can detect its a delay < 0 and then instead of using a timer,
then do a processor that's in a while loop and then keep routing
> {code}
> while (isRunAllowed) {
>    create exchange
>    process exchange
> }
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Mime
View raw message