|
RIFE : Scheduler
This page last changed on Apr 30, 2007 by rife@klaus-meffert.de.
The Memory SchedulerAdding a participantThe 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 schedulerAfterwards 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"> <scheduler> <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> <task classname="com.uwyn.rife.search.executors.IndexQueueExecutor" frequency="*/5 * * * *"/> </scheduler> 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:
Implementing an ExecutorNow 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; try { datasource_name = task.getTaskoptionValue("datasource_name"); } catch (SchedulerException e) { Logger.getLogger("com.uwyn.rife.search.executors").severe(ExceptionUtils.getExceptionStackTrace(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 |