/**
 * ContainerCacheActivator.java
 * Created on Jun 11, 2008
 * (C) Copyright TANDBERG Television Ltd.
 */
package com.tandbergtv.watchpoint.pmm.util;

import org.apache.log4j.Logger;

import com.tandbergtv.watchpoint.pmm.entities.IContainer;
import com.tandbergtv.workflow.core.service.Service;
import com.tandbergtv.workflow.core.service.ServiceRegistry;
import com.tandbergtv.workflow.core.service.cache.ICacheService;

/**
 * This class is responsible to start the Container Cache service.
 * 
 * @author spuranik
 *
 */
public class ContainerCacheActivator {

	private static final Logger logger = Logger.getLogger(ContainerCacheActivator.class);
	
	/**
	 * this method starts the job scheduling engine
	 */
	public void start() {
		try {
			ICacheService<IContainer> containerCache = ContainerCache.getInstance();

			ServiceRegistry.getDefault().register(containerCache.getServiceName(), containerCache);
			containerCache.start();

			logger.debug("Starting container cache service.");
		} catch (RuntimeException e) {
			logger.error("Error while starting container cache service: " + e.toString());
		}
	}

	/**
	 * this method stops the job scheduling service
	 */
	public void stop() {
		try {
			logger.debug("Stopping container cache service.");
			ServiceRegistry registry = ServiceRegistry.getDefault();
			Service service = registry.lookup("Container Cache");

			if (service != null) {
				service.stop();
				registry.unregister(service);
			}
		} catch (RuntimeException e) {
			logger.error("Error while stopping container cache service: " + e.toString());
		}
	}

}
