001: /*
002: * $Header: /cvsroot/mvnforum/mvnforum/src/com/mvnforum/common/ReloadTomcatTimerTaskExt.java,v 1.4 2007/10/09 11:09:16 lexuanttkhtn Exp $
003: * $Author: lexuanttkhtn $
004: * $Revision: 1.4 $
005: * $Date: 2007/10/09 11:09:16 $
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: Phuong, Pham Dinh Duy
039: */
040: package com.mvnforum.common;
041:
042: import java.io.File;
043:
044: import org.apache.commons.logging.Log;
045: import org.apache.commons.logging.LogFactory;
046:
047: import net.myvietnam.mvncore.service.EnvironmentService;
048: import net.myvietnam.mvncore.service.MvnCoreServiceFactory;
049: import net.myvietnam.mvncore.util.*;
050:
051: public class ReloadTomcatTimerTaskExt extends TimerTaskAbstract
052: implements TimerTaskExt {
053:
054: // static variable
055: private static Log log = LogFactory
056: .getLog(ReloadTomcatTimerTaskExt.class);
057:
058: // static variable
059: private static ReloadTomcatTimerTaskExt instance = null;
060:
061: // instance variables
062: private EnvironmentService environmentService;
063:
064: // private constructor will prevent any instatiation
065: private ReloadTomcatTimerTaskExt() {
066: }
067:
068: public long getDelay() {
069: return DateUtil.MINUTE * 3;
070: }
071:
072: public long getPeriod() {
073: return DateUtil.MINUTE * 1;
074: }
075:
076: /**
077: * This static method is used to get the Singleton instance of WatchTask
078: * @return the singleton instance of WatchTask
079: */
080: public static synchronized ReloadTomcatTimerTaskExt getInstance() {
081: if (instance == null) {
082: instance = new ReloadTomcatTimerTaskExt();
083: }
084: return instance;
085: }
086:
087: public synchronized void schedule() {
088: if (scheduled == false) {
089: scheduled = true;
090: TimerUtil.getInstance().schedule(this , getDelay(),
091: getPeriod());
092: }
093: }
094:
095: public void run() {
096: if (environmentService == null) {
097: environmentService = MvnCoreServiceFactory
098: .getMvnCoreService().getEnvironmentService();
099: }
100:
101: if (environmentService.isShouldRun()) {
102: return;
103: }
104: try {
105: log
106: .debug("Begin reloading Tomcat in ReloadTomcatTimerTaskExt");
107: String classesPath = FileUtil.getServletClassesPath();
108: String libPath = classesPath + ".." + File.separatorChar
109: + "lib" + File.separatorChar + "mvnforum.jar";
110: FileUtil.touch(libPath);
111: } catch (Exception ex) {
112: log
113: .error(
114: "Error running reloading Tomcat in ReloadTomcatTimerTaskExt",
115: ex);
116: }
117: }
118:
119: }
|