RIFE logo
This page last changed on Apr 30, 2007 by rife@klaus-meffert.de.

The Memory Scheduler

Adding a participant

The first thing you need to do is to add a participant to your repository (usually rep/participants.xml). Basically this will look like this:

<participant name="scheduler" param="rep/scheduler.xml">ParticipantMemoryScheduler</participant>

Defining your scheduler

Afterwards you have to actually write the scheduler.xml file you referenced above. Again I'll explain this by example:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE scheduler SYSTEM "/dtd/scheduler.dtd">

    <task classname="com.uwyn.rife.mail.executors.DatabaseMailQueueExecutor" frequency="*/5 * * * *">
        <option name="datasource"><config param="DATASOURCE"/></option>
        <option name="smtp_server"><config param="SMTP_SERVER"/></option>
    <task classname="com.uwyn.rife.search.executors.IndexQueueExecutor" frequency="*/5 * * * *"/>

This is the scheduler as used by the Bamboo project. So, what does it do?

As you can see, it basically defines a list of tasks. Each task definition consists of the following components:

  1. Executor class. This is the actual class, which will be instantiated and called.
  2. Frequency. This defines when and how often the task will be executed. The syntax is the same as with the popular CRON daemon. If you're not familiar with that syntax, please take a look at this explanation on Wikipedia.
  3. Options (if neccessary). As in the first task in the example above, you can also add various options that will be passed to your Executor.

Implementing an Executor

Now that you've decided how many tasks you have and when they should be executed, there's only one more thing left: You need to define what they are supposed to do. This is done by implementing so called Executors.

There are basically two examples of Executors you can refer to:

Let's start building our first Executor.

First we need to define a class that inherits from com.uwyn.rife.scheduler.Executor:

package com.example;
import com.uwyn.rife.scheduler.Executor;

public class MyTestExecutor extends Executor

Now we have to implement the following method, returing the name of the task:

public String getHandledTasktype() {
  return "MyTask";

Next thing is we add a method called executeTask() to our Executor which takes one argument of type com.uwyn.rife.scheduler.Task and returns a Boolean value.

public boolean executeTask(Task task)
    return true;

At this point, you should take a look at the Task class (JavaDoc). It's mostly used to get the values for the options we defined above. Here's an example of how that might look:

String datasource_name = null;
    datasource_name = task.getTaskoptionValue("datasource_name");
catch (SchedulerException e)
    datasource_name = null;

Another thing that you can use the Task object for is to get the frequency as defined in the scheduler.xml file and even more interesting, when the next execution will take place. Take a look:

String freq;
long nextExecution;
freq = task.getFrequency();
nextExecution = task.getPlanned();

That's it, now you're ready to go and write your own Executors.

Document generated by Confluence on Oct 19, 2010 14:57