1 package com.sslexplorer.tasks.shutdown; 2 3 import java.text.SimpleDateFormat ; 4 import java.util.Date ; 5 import java.util.TimerTask ; 6 7 import org.apache.commons.logging.Log; 8 import org.apache.commons.logging.LogFactory; 9 10 import com.sslexplorer.boot.ContextHolder; 11 12 public class ShutdownTimerTask extends TimerTask { 13 14 final static Log log = LogFactory.getLog(ShutdownTimerTask.class); 15 16 public static String NAME = "shutdown.task"; 17 18 boolean restart = false; 19 long defaultDelay = 10000; 20 long delay = 0; 21 22 public ShutdownTimerTask(boolean restart, int delayInMins) { 23 super(); 24 this.restart = restart; 25 this.delay = (delayInMins*60*1000) ; 26 } 27 28 public void run() { 29 if (log.isInfoEnabled()) 30 log.info("About to perform shutdown task."); 31 ContextHolder.getContext().shutdown(restart); 32 } 33 34 public long getDelay() { 35 if (delay < defaultDelay) 37 return defaultDelay; 38 else 39 return delay; 40 } 41 42 public void setDelay(long shutdownTime) { 43 this.delay = shutdownTime; 44 } 45 46 public Date getShutDownTime(){ 47 return new Date (System.currentTimeMillis() +this.getDelay()); 48 } 49 50 public String getShutDownTimeString(){ 51 return getShutDownTimeString("HH:mm"); 52 } 53 54 public String getShutDownTimeString(String pattern){ 55 SimpleDateFormat sdf = new SimpleDateFormat (pattern); 56 return sdf.format(getShutDownTime()); 57 } 58 59 } 60 | Popular Tags |