LibraryToggle FramesPrintFeedback

Example 2.7 shows how to schedule a route to start up using the Java DSL. The policy is configured with the cron expression, */3 * * * * ?, which triggers a start event every 3 seconds.

In Java DSL, you attach the route policy to the route by calling the routePolicy() DSL command in the route.


[Note]Note

You can specify multiple policies on the route by calling routePolicy() with multiple arguments.

The cron expression syntax has its origins in the UNIX cron utility, which schedules jobs to run in the background on a UNIX system. A cron expression is effectively a syntax for wildcarding dates and times that enables you to specify either a single event or multiple events that recur periodically.

A cron expression consists of 6 or 7 fields in the following order:

Seconds Minutes Hours DayOfMonth Month DayOfWeek [Year]

The Year field is optional and usually omitted, unless you want to define an event that occurs once and once only. Each field consists of a mixture of literals and special characters. For example, the following cron expression specifies an event that fires once every day at midnight:

0 0 24 * * ?

The * character is a wildcard that matches every value of a field. Hence, the preceding expression matches every day of every month. The ? character is a dummy placeholder that means ignore this field. It always appears either in the DayOfMonth field or in the DayOfWeek field, because it is not logically consistent to specify both of these fields at the same time. For example, if you want to schedule an event that fires once a day, but only from Monday to Friday, use the following cron expression:

0 0 24 ? * MON-FRI

Where the hyphen character specifies a range, MON-FRI. You can also use the forward slash character, /, to specify increments. For example, to specify that an event fires every 5 minutes, use the following cron expression:

0 0/5 * * * ?

For a full explanation of the cron expression syntax, see the Wikipedia article on CRON expressions.

The following table lists the parameters for scheduling one or more route starts.

ParameterTypeDefaultDescription
routeStartStringStringNoneSpecifies a cron expression that triggers one or more route start events.

The following table lists the parameters for scheduling one or more route stops.

ParameterTypeDefaultDescription
routeStopTimeStringNoneSpecifies a cron expression that triggers one or more route stop events.
routeStopGracePeriodint10000Specifies how long to wait for the current exchange to finish processing (grace period) before forcibly stopping the route. Set to 0 for an infinite grace period.
routeStopTimeUnitlongTimeUnit.MILLISECONDSSpecifies the time unit of the grace period.

The following table lists the parameters for scheduling the suspension of a route one or more times.

ParameterTypeDefaultDescription
routeSuspendTimeStringNoneSpecifies a cron expression that triggers one or more route suspend events.

The following table lists the parameters for scheduling the resumption of a route one or more times.

ParameterTypeDefaultDescription
routeResumeTimeStringNoneSpecifies a cron expression that triggers one or more route resume events.
Comments powered by Disqus
loading table of contents...