package org.treesched.examples;

import org.apache.log4j.Logger;
import org.treesched.schedules.IntervalSchedule;
import org.treesched.schedules.TimeSchedule;



/**
 * This is a demonstration of a very simple scheduler that uses treesched.
 * The schedule is constructed within the code instead
 * of read from a configuration file.
 */

public class CodeExample {

    private static final Logger logger = Logger.getLogger(CodeExample.class);

    public static void main(String[] args) throws Exception {
				
		SimpleScheduler scheduler = new SimpleScheduler();

		IntervalSchedule interval = new IntervalSchedule();
		interval.setInterval("00:15");

		TimeSchedule time = new TimeSchedule();
		time.setFrom("10:15");
		time.setTo("21:30");
		time.setChildSchedule(interval);

		scheduler.setSchedule(time);
	
		Thread t = new Thread(scheduler);
		t.start();
		
		System.out.println("Enter anything to stop");
		
		try {			
			System.in.read();
		} catch (java.io.IOException e) {
			e.printStackTrace();
		}

		System.out.println("Stopping...");

		scheduler.stop();
		
		t.join();		

		System.out.println("Stopped.");
	}
}
