You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Claus Ibsen <cl...@gmail.com> on 2011/04/02 10:02:36 UTC

Re: Scheduling routes with RoutePolicy

Just had a 2nd look.

The RoutePolicy has an onInit method which is invoked always. So we
got the hook to initialize the route policy, even if the route is not
started up-front.

See CustomScheduledRoutePolicyTest from camel-core unit tests.

So if there is a flaw in CronScheduledRoutePolicy then we should be
able to fix that, as it should initialize itself in onInit.
Maybe you can create an unit test which demonstrates the issue, we can
use to look into it?


On Tue, Mar 29, 2011 at 2:03 PM, Claus Ibsen <cl...@gmail.com> wrote:
> Ah you may have hit a corner issue.
>
> You can indicate a route is stopped using .noAutoStartup in the DSL.
> But we need to initialize the CronScheduledRoutePolicy regardless
> what. It should have a start method you can invoke manually thought.
>
> But check its source code to be sure. And maybe you need to associate
> a route id to it, so it has the id to use for starting the route. Or
> the code need to be enhanced for this scenario.
>
>
>
> On Tue, Mar 29, 2011 at 1:21 PM, mikaelfj <mi...@gmail.com> wrote:
>> Hi,
>>
>> I'm in the process of using CronScheduledRoutePolicy to schedule a route to
>> start and stop - i.e. to only be polling the from endpoint in a certain
>> time-interval - e.g. the below should ensure it only polls the from endpoint
>> one hour each day between 16-17:
>>
>> CronScheduledRoutePolicy policy = new CronScheduledRoutePolicy();
>> policy.setRouteStartTime("0 0 16 ? * *");
>> policy.setRouteStopTime("0 0 17 ? * *");
>> from(...)
>> .routeId(routeId)
>> .routePolicy(policy)
>> .process(...)
>>
>> As far as I can tell from my test, the setting of the routePolicy does not
>> automatically ensure that the route is stopped when I e.g. start the route,
>> say, at 11.
>> So I assume that the routePolicy just ensures that it will trigger at start
>> at 16 and a stop at 17 - but I need to ensure manually that if started at 11
>> it is initially in the stopped state - is that correctly understood?
>>
>> We are building our routes inside an implementation of the
>> RouteBuilder.configure method e.g. like:
>>
>> public void configure() throws Exception {
>>  CronScheduledRoutePolicy policy = new CronScheduledRoutePolicy();
>>  policy.setRouteStartTime("0 0 16 ? * *");
>>  policy.setRouteStopTime("0 0 17 ? * *");
>>  from(...)
>>  .routeId(routeId)
>>  .routePolicy(policy)
>>  .process(...)
>> }
>>
>> This is different from e.g. the unit tests that shows how to start the
>> context and then stop a route.
>> So, how do I, in the implementation of the RouteBuilder.configure method
>> ensure that the route is initially stopped if the route is about to be
>> startet at 11?
>>
>> Regards
>> Mikael
>>
>> --
>> View this message in context: http://camel.465427.n5.nabble.com/Scheduling-routes-with-RoutePolicy-tp4269200p4269200.html
>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>
>
>
>
> --
> Claus Ibsen
> -----------------
> FuseSource
> Email: cibsen@fusesource.com
> Web: http://fusesource.com
> Twitter: davsclaus
> Blog: http://davsclaus.blogspot.com/
> Author of Camel in Action: http://www.manning.com/ibsen/
>



-- 
Claus Ibsen
-----------------
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
CamelOne 2011: http://fusesource.com/camelone2011/
Twitter: davsclaus
Blog: http://davsclaus.blogspot.com/
Author of Camel in Action: http://www.manning.com/ibsen/

Re: Scheduling routes with RoutePolicy

Posted by public_phil <pu...@me.com>.
Hi Mikael,

  I had the exact same problem with Camel 2.6.  This was my configuration:


public void configure() throws Exception {		
  Calendar c = Calendar.getInstance();
  c.add(Calendar.MINUTE, 1);
  SimpleScheduledRoutePolicy simple = new SimpleScheduledRoutePolicy();
  simple.setRouteStartDate(c.getTime());
		
  c.add(Calendar.MINUTE, 2);
  simple.setRouteStopDate(c.getTime());
		
 
from("file://c:/routeTest").routeId("test").routePolicy(simple).to("file://c:/routeOutput").noAutoStartup();
}


With 2.6, the route would never be started.  Once I upgraded to 2.7,
however, the route starts after 1 minute and then terminates after 2
minutes.


--
View this message in context: http://camel.465427.n5.nabble.com/Scheduling-routes-with-RoutePolicy-tp4269200p4284818.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Scheduling routes with RoutePolicy

Posted by public_phil <pu...@me.com>.
Hi Mikael,

  I had the exact same problem with Camel 2.6.  This was my configuration:


public void configure() throws Exception {		
  Calendar c = Calendar.getInstance();
  c.add(Calendar.MINUTE, 1);
  SimpleScheduledRoutePolicy simple = new SimpleScheduledRoutePolicy();
  simple.setRouteStartDate(c.getTime());
		
  c.add(Calendar.MINUTE, 2);
  simple.setRouteStopDate(c.getTime());
		
 
from("file://c:/routeTest").routeId("test").routePolicy(simple).to("file://c:/routeOutput").noAutoStartup();
}


With 2.6, the route would never be started.  Once I upgraded to 2.7,
however, the route starts after 1 minute and then terminates after 2
minutes.


--
View this message in context: http://camel.465427.n5.nabble.com/Scheduling-routes-with-RoutePolicy-tp4269200p4284809.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Scheduling routes with RoutePolicy

Posted by mikaelfj <mi...@gmail.com>.
Hi,

Took a look at the source for 2.7 and I can see that this particular method
has been changed as a result of CAMEL-3575 - which is exactly the problem
that we experience.

I'll make the same change to 2.6 to see if that fixes the problem.

/Mikael

--
View this message in context: http://camel.465427.n5.nabble.com/Scheduling-routes-with-RoutePolicy-tp4269200p4283755.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Scheduling routes with RoutePolicy

Posted by mikaelfj <mi...@gmail.com>.
Hi,

I've been trying it out using the noAutoStartUp() - which seems to make it
work, i.e. let the route begin in a stopped state and then having a
cron-schedule to start it at a given point in time.

However, I need to have it to start and then stop a few hours later, but
this does not work.

If I set both a routeStartTime and a routeStopTime on the policy, then two
scheduled events are being handled, but they are both firing the STOP
action.

I've been through the code, and I think that the problem is in this method
of the ScheduledRoutePolicy:

protected void loadCallbackDataIntoSchedulerContext(Action action, Route
route) throws SchedulerException {
        getScheduler().getContext().put(SCHEDULED_ACTION, action);
        getScheduler().getContext().put(SCHEDULED_ROUTE, route);
    }    

This method is called during each invocation of the
ScheduledRoutepolicy.scheduleRoute(Action action) method - which in my test
gets called twice - first for the Start action and secondly for the Stop
action.

So after the second invocation of loadCallbackDataIntoSchedulerContext the
SCHEDULED_ACTION on the context is the Stop action - even though I wanted to
define both a Start and Stop action.

I.e. it is possible to register in the routepolicy multiple actions, but the
registration in the scheduler context only allows for one single action.

Is this deliberate or is it a flaw in the implementation.

>From comments on other issues in the forum I can see that it should be
possible to register multiple policies on a route from Camel 2.7 - however,
we are currently stuck on JDK1.5 so Camel 2.7 is not an option for us.

Regards
Mikael

--
View this message in context: http://camel.465427.n5.nabble.com/Scheduling-routes-with-RoutePolicy-tp4269200p4281413.html
Sent from the Camel - Users mailing list archive at Nabble.com.