001: /*
002: * $Header: /cvsroot/mvnforum/mvnforum/src/com/mvnforum/MVNForumContextListener.java,v 1.19 2008/01/21 11:31:34 minhnn Exp $
003: * $Author: minhnn $
004: * $Revision: 1.19 $
005: * $Date: 2008/01/21 11:31:34 $
006: *
007: * ====================================================================
008: *
009: * Copyright (C) 2002-2007 by MyVietnam.net
010: *
011: * All copyright notices regarding mvnForum MUST remain
012: * intact in the scripts and in the outputted HTML.
013: * The "powered by" text/logo with a link back to
014: * http://www.mvnForum.com and http://www.MyVietnam.net in
015: * the footer of the pages MUST remain visible when the pages
016: * are viewed on the internet or intranet.
017: *
018: * This program is free software; you can redistribute it and/or modify
019: * it under the terms of the GNU General Public License as published by
020: * the Free Software Foundation; either version 2 of the License, or
021: * any later version.
022: *
023: * This program is distributed in the hope that it will be useful,
024: * but WITHOUT ANY WARRANTY; without even the implied warranty of
025: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
026: * GNU General Public License for more details.
027: *
028: * You should have received a copy of the GNU General Public License
029: * along with this program; if not, write to the Free Software
030: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
031: *
032: * Support can be obtained from support forums at:
033: * http://www.mvnForum.com/mvnforum/index
034: *
035: * Correspondence and Marketing Questions can be sent to:
036: * info at MyVietnam net
037: *
038: * @author: Minh Nguyen
039: * @author: Mai Nguyen
040: */
041: package com.mvnforum;
042:
043: import java.sql.Timestamp;
044:
045: import javax.servlet.*;
046:
047: import net.myvietnam.mvncore.service.MvnCoreServiceFactory;
048: import net.myvietnam.mvncore.util.DateUtil;
049: import net.myvietnam.mvncore.util.FileUtil;
050:
051: import org.apache.commons.logging.Log;
052: import org.apache.commons.logging.LogFactory;
053:
054: import com.mvnforum.service.MvnForumServiceFactory;
055:
056: public class MVNForumContextListener implements ServletContextListener {
057:
058: private static Log log = LogFactory
059: .getLog(MVNForumContextListener.class);
060:
061: private static MVNForumContextListener instance;
062:
063: private Timestamp startTimestamp;
064:
065: public MVNForumContextListener() {
066: instance = this ;
067: }
068:
069: /**
070: * Notification that the web application is ready to process requests.
071: *
072: * @param event ServletContextEvent
073: */
074: public void contextInitialized(ServletContextEvent event) {
075:
076: log.debug("contextInitialized");
077:
078: // We MUST initialize FileUtil's ServletClassesPath first before call any ServiceFactory
079: // because ServiceFactory need the correct servlet path first before it can be initialized
080: String realPath = event.getServletContext().getRealPath(
081: "/WEB-INF/classes");// Add '/' before WEB-INF to fix the Oracle 10G bug
082: FileUtil.setServletClassesPath(realPath);
083:
084: MvnCoreServiceFactory.getMvnCoreService()
085: .getMvnCoreLifeCycleService().contextInitialized(event);
086: MvnForumServiceFactory.getMvnForumService()
087: .getMvnForumLifeCycleService()
088: .contextInitialized(event);
089:
090: startTimestamp = DateUtil.getCurrentGMTTimestamp();
091: }
092:
093: /**
094: * Notification that the servlet context is about to be shut down.
095: *
096: * @param event ServletContextEvent
097: */
098: public void contextDestroyed(ServletContextEvent event) {
099:
100: MvnForumServiceFactory.getMvnForumService()
101: .getMvnForumLifeCycleService().contextDestroyed(event);
102: MvnCoreServiceFactory.getMvnCoreService()
103: .getMvnCoreLifeCycleService().contextDestroyed(event);
104:
105: instance = null;
106:
107: try {
108: //we will sleep 2 seconds, so the background thread of TimerUtil and WhirlyCache could be destroyed
109: log.debug("About to sleep 2 seconds.");
110: Thread.sleep(2000);
111: } catch (InterruptedException e) {
112: //ignore
113: }
114:
115: log.debug("contextDestroyed");
116:
117: }
118:
119: // below are add on method
120:
121: public static MVNForumContextListener getInstance() {
122: return instance;
123: }
124:
125: public Timestamp getStartTimestamp() {
126: return startTimestamp;
127: }
128:
129: }
|