1 /** 2 This file is part of GoldenGate Project (named also GoldenGate or GG). 3 4 Copyright 2009, Frederic Bregier, and individual contributors by the @author 5 tags. See the COPYRIGHT.txt in the distribution for a full listing of 6 individual contributors. 7 8 All GoldenGate Project is free software: you can redistribute it and/or 9 modify it under the terms of the GNU General Public License as published 10 by the Free Software Foundation, either version 3 of the License, or 11 (at your option) any later version. 12 13 GoldenGate is distributed in the hope that it will be useful, 14 but WITHOUT ANY WARRANTY; without even the implied warranty of 15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 GNU General Public License for more details. 17 18 You should have received a copy of the GNU General Public License 19 along with GoldenGate . If not, see <http://www.gnu.org/licenses/>. 20 */ 21 package goldengate.ftp.core.utils; 22 23 import goldengate.common.logging.GgInternalLogger; 24 import goldengate.common.logging.GgInternalLoggerFactory; 25 import goldengate.ftp.core.config.FtpConfiguration; 26 27 import java.util.TimerTask; 28 29 /** 30 * Timer Task used mainly when the server is going to shutdown in order to be 31 * sure the program exit. 32 * 33 * @author Frederic Bregier 34 * 35 */ 36 public class FtpTimerTask extends TimerTask { 37 /** 38 * Internal Logger 39 */ 40 private static final GgInternalLogger logger = GgInternalLoggerFactory 41 .getLogger(FtpTimerTask.class); 42 43 /** 44 * EXIT type (System.exit(1)) 45 */ 46 public static final int TIMER_EXIT = 1; 47 /** 48 * Finalize Control connection 49 */ 50 public static final int TIMER_CONTROL = 2; 51 52 /** 53 * Type of execution in run() method 54 */ 55 private final int type; 56 /** 57 * Configuration 58 */ 59 public FtpConfiguration configuration = null; 60 61 /** 62 * Constructor from type 63 * 64 * @param type 65 */ 66 public FtpTimerTask(int type) { 67 super(); 68 this.type = type; 69 } 70 71 /* 72 * (non-Javadoc) 73 * 74 * @see java.util.TimerTask#run() 75 */ 76 @Override 77 public void run() { 78 switch (type) { 79 case TIMER_EXIT: 80 logger.error("System will force EXIT"); 81 System.exit(0); 82 break; 83 case TIMER_CONTROL: 84 logger.info("Exit Shutdown Command"); 85 FtpChannelUtils.terminateCommandChannels(configuration); 86 logger.info("Exit end of Command Shutdown"); 87 break; 88 default: 89 logger.info("Type unknown in TimerTask"); 90 } 91 } 92 }