/**
 * JobSchedulerActivator.java
 * Created on Jun 9, 2008
 * (C) Copyright TANDBERG Television Ltd.
 */
package com.tandbergtv.watchpoint.pmm.job.scheduling;

import org.apache.log4j.Logger;

import com.tandbergtv.workflow.core.service.Service;
import com.tandbergtv.workflow.core.service.ServiceRegistry;

/**
 * This class is responsible for starting and stopping the job scheduling service
 * 
 * @author spuranik
 */
public class JobSchedulerActivator {

	private static final Logger logger = Logger.getLogger(JobSchedulerActivator.class);
	
	/**
	 * this method starts the job scheduling engine
	 */
	public void start() {
		IJobScheduleManager quartzScheduleMgr = QuartzScheduleManager
				.getInstance();

		ServiceRegistry.getDefault().register(
				quartzScheduleMgr.getServiceName(), quartzScheduleMgr);
		quartzScheduleMgr.start();

		logger.debug("Starting job scheduling service.");
	}

	/**
	 * this method stops the job scheduling service
	 */
	public void stop() {
		logger.debug("Stopping job scheduling service.");
		ServiceRegistry registry = ServiceRegistry.getDefault();
		Service service = registry.lookup(IJobScheduleManager.class);

		if (service != null) {
			service.stop();
			registry.unregister(service);
		}
	}
}
