package project.listener;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import org.apache.logging.log4j.LogManager;
import org.seasar.extension.timer.TimeoutManager;

import javassist.ClassClassPath;
import javassist.ClassPool;
import online.listener.ContextListener;

/**
 * WebContextListener
 *
 * @author Tadashi Nakayama
 */
public class WebContextListener implements ServletContextListener {

	/** ContextListener */
	private final ContextListener cl = new ContextListener();

	/**
	 * @see javax.servlet.ServletContextListener
	 * #contextDestroyed(javax.servlet.ServletContextEvent)
	 */
	@Override
	public void contextDestroyed(final ServletContextEvent sce) {
		this.cl.contextDestroyed(sce);

		if (!TimeoutManager.getInstance().stop(3000)) {
			LogManager.getLogger().info("TimeoutManager is still alive.");
		}
	}

	/**
	 * @see javax.servlet.ServletContextListener
	 * #contextInitialized(javax.servlet.ServletContextEvent)
	 */
	@Override
	public void contextInitialized(final ServletContextEvent arg0) {
		this.cl.contextInitialized(arg0);

		final ClassPool pool = ClassPool.getDefault();
		pool.appendClassPath(new ClassClassPath(this.getClass()));
	}
}
