XmlBlaster Logo

REQUIREMENT

contrib.scheduler

XmlBlaster Logo


Type NEW
Priority HIGH
Status CLOSED
Topic You can receive messages published by the filewatcher and store them at a certain location on the filesystem.
Des
cription

If you have requirements to execute some operations or to allow some operations only during some hours of the day, or some days of a month or a week, then this plugin can do it. It is a scheduler using quartz as the underlying library. The syntax to define the execution of jobs is defined/configured in a cron- and crontab alike manner.

A typical usage example would be to timely control the dispatch of messages, for example to allow messages for some clients to be dispatched only during non-rush hours (for example during the night or over the weekend). This is for instance accomplished by the org.xmlBlaster.contrib.scheduler.jobs.ReplScheduler

In the org.xmlBlaster.contrib.scheduler.jobs directory you find the provided implemented jobs. These classes all implement the Job interface defined by quartz.
If you don't find your requirement is covered by one of the provided jobs it is easy to write an own implementation: just extend the Job class, provide a public default constructor and implement the only relevant method of the interface: void execute(JobExecutionContext context). On how to retrieve the necessary data from the environment have a look at one of the provided implementations, for example at the class org.xmlBlaster.contrib.scheduler.jobs.ReplScheduler.

To use this plugin you need to activate it in the xmlBlasterPlugins.xml file and configure it appropriately. In the configuration of this plugin you can define attributes. All attributes starting with the prefix scheduler. will be considered jobs to be scheduled. So for example scheduler.action1 would result in a job having the assigned name action1. Note that the name of these jobs must be unique inside the plugin.

 02    *   *   *    *  org.xmlBlaster.contrib.scheduler.jobs.ReplScheduler stopDispatcher
 |     |                       
 *     *   *   *    *  command to be executed                              further attributes:
 -     -   -   -    -                                                      could be more than 0 and
 |     |   |   |    |                                                      are depending on the job
 |     |   |   |    +----- day of week (0 - 6) (Sunday=0)                  implementation          
 |     |   |   +------- month (1 - 12)
 |     |   +--------- day of month (1 - 31)                                                        
 |     +----------- hour (0 - 23)
 +------------- min (0 - 59)                                                                             
For the day of the week one can also use MON (or monday), TUE, WED, THU, FRI, SAT, SUN, this way it is easier to read the configuration.
The same as for the week days is true for the month: these can also be expressed as names or as JAN, FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP, OCT, NOV, DEC.
The above example would mean the ReplScheduler will stop the dispatcher for all involved replications at minute 02 every hour.

For further details on the usage please look at the examples and configuration section.

Example
any

Scheduler Jobs for Replication

By means of the scheduler you can control the dispatcher of the replication clients, i.e. you can determine when to set the callback dispatcher to active or inactive. In the cron-like command line you specify in the 6th attribute the class name of the job (ReplScheduler) and thereafter all the attributes which org.xmlBlaster.contrib.scheduler.jobs.ReplScheduler understands. These are:
arg type default value Comment
arg0 String null mandatory: The name of the operation to perform. one of startDispatcher or stopDispatcher must be specified
arg1 String null optional: The name of the replication prefix (i.e. the name of the source of the replication) for which the action specified in arg0 is supposed to be. If you choose this (for example masterGroupA and do not specify arg2, then the action is executed on all the clients (slaves) associated to the source masterGroupA.
arg2 String null optional: The name of the client session for which to execute the action. Note that the associated prefix must be correct.

 00    07  *   *    *  org.xmlBlaster.contrib.scheduler.jobs.ReplScheduler stopDispatcher
 00    18  *   *    *  org.xmlBlaster.contrib.scheduler.jobs.ReplScheduler startDispatcher
 02    07  *   *    6  org.xmlBlaster.contrib.scheduler.jobs.ReplScheduler startDispatcher
 02    07  *   *    5  org.xmlBlaster.contrib.scheduler.jobs.ReplScheduler startDispatcher

This would mean that every morning at 07:00 the dispatcher is stopped, it is started again every evening at 18:00. During the weekends we want the dispatcher to be active, so the third raw means that 2 minutes after 07:00 on saturday morning and in fourth raw the same on sunday morning, the dispatcher is set to active. This would mean the dispatcher remains closed during working hour.

You could also express the same of above as:

 00    07  *   *    *        org.xmlBlaster.contrib.scheduler.jobs.ReplScheduler stopDispatcher
 00    18  *   *    *        org.xmlBlaster.contrib.scheduler.jobs.ReplScheduler startDispatcher
 02    07  *   *    saturday org.xmlBlaster.contrib.scheduler.jobs.ReplScheduler startDispatcher
 02    07  *   *    sunday   org.xmlBlaster.contrib.scheduler.jobs.ReplScheduler startDispatcher
or
 00    07  *   *    *   org.xmlBlaster.contrib.scheduler.jobs.ReplScheduler stopDispatcher
 00    18  *   *    *   org.xmlBlaster.contrib.scheduler.jobs.ReplScheduler startDispatcher
 02    07  *   *    SAT org.xmlBlaster.contrib.scheduler.jobs.ReplScheduler startDispatcher
 02    07  *   *    SUN org.xmlBlaster.contrib.scheduler.jobs.ReplScheduler startDispatcher
which are easier to understand than the numeric representation of above.

Configure

 <xmlBlaster>
   ...
   <plugin id='SchedulerPlugin' className='org.xmlBlaster.contrib.scheduler.SchedulerPlugin'>
      <attribute id="scheduler.closeWork">00 07 * * * org.xmlBlaster.contrib.scheduler.jobs.ReplScheduler stopDispatcher</attribute>
      <attribute id="scheduler.openNight">00 18 * * * org.xmlBlaster.contrib.scheduler.jobs.ReplScheduler startDispatcher</attribute>
      <attribute id="scheduler.openSat">02 07 * * 6 org.xmlBlaster.contrib.scheduler.jobs.ReplScheduler startDispatcher</attribute>
      <attribute id="scheduler.openSun">02 07 * * 0 org.xmlBlaster.contrib.scheduler.jobs.ReplScheduler startDispatcher</attribute>
      <action do='LOAD' onStartupRunlevel='9' sequence='10' onFail='resource.configuration.pluginFailed'/>
      <action do='STOP' onShutdownRunlevel='8' sequence='1'/>
   </plugin>
   ...
 </xmlBlaster>
 

The example above can also be seen on the jmx page:
In the jmx console you have as JobNames the list of all registered scheduler, as SchedulerList a list (with contents) of all the registered schedulers.
With addScheduler you can a new scheduler or modify an existing one. The first parameter is the name to associate to the job (that corresponds to the name after the prefix scheduler. in the attribute id in xmlBlasterPlugins.xml which in turn correspons to what indicated under JobNames, and as the second parameter the string containing the cron-like syntax for the job.
With removeScheduler you can remove a scheduler. It takes one argument which is the name of the job (the one displayed in the parameter JobNames

NOTE: Configuration parameters are specified on command line (-someValue 17) or in the xmlBlaster.properties file (someValue=17). See requirement "util.property" for details.
Columns named Impl tells you if the feature is implemented.
Columns named Hot tells you if the configuration is changeable in hot operation.

See REQ engine.runlevel

This page is generated from the requirement XML file xmlBlaster/doc/requirements/contrib.scheduler.xml

Back to overview