Schedule Overview

It is just reference Services.

Almost this Code is copied from Apache' Avalon-Cornerstone.
Cornerstone is a good Component. but It can only run on Avalon Framework. so I just modified them to remove the coupling with Avalon Framework

Usage Example

services.xml

<?xml version="1.0" encoding="UTF-8"?>

<services>
	<service id="ThreadManager" class="sunheart.third.thread.impl.ResourceLimitingThreadManager" />
	<!-- it require 'ThreadManager' sercie' -->
	<service id="TimeScheduler" class="sunheart.third.scheduler.impl.MultiTimeScheduler" />
</services>          
          

scheduler information is stored in seperated file 'scheduler.xml'. of course you can change it to another repository. (you need to subclass 'sunheart.third.scheduler.impl.DefaultTimeScheduler')

scheduler.xml

<?xml version="1.0" encoding="UTF-8"?>
<scheduler>
	<!-- ip check. if value is blank, skip -->
	<onlythisip></onlythisip>

	<!-- same with ip -->
	<onlythisHost></onlythisHost>

	<!-- triggers -->
	<trigger name="periodic1700" type="periodic">
		\<!-- a base time -->
		<start hour="17" minute="0" />
		<!-- period, minute -->
		<period>1</period>
	</trigger>

	<trigger name="cron0511" type="cron">
		<minute>14</minute>
		<hour>11</hour>
		<day week="1">-1</day>
		<month>-1</month>
		<year>-1</year>
	</trigger>

	<target class="example.ATarget">
		<ref_trigger>periodic1700</ref_trigger>
		<ref_trigger>cron0511</ref_trigger>
	</target>
</scheduler>
          

Java code

package example;

import java.util.Date;

import sunheart.service.scheduler.Target;

/**
 *  
 */
public class ATarget implements Target {

    public void targetTriggered(String triggerName) {
        System.out.println(triggerName + ":ATarget target is fired "
                + new Date());
    }

}