001: /**
002: * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
003: *
004: * Permission is hereby granted, free of charge, to any person obtaining a copy
005: * of this software and associated documentation files (the "Software"), to deal
006: * in the Software without restriction, including without limitation the rights
007: * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
008: * copies of the Software, and to permit persons to whom the Software is
009: * furnished to do so, subject to the following conditions:
010: *
011: * The above copyright notice and this permission notice shall be included in
012: * all copies or substantial portions of the Software.
013: *
014: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
015: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
016: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
017: * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
018: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
019: * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
020: * SOFTWARE.
021: */package com.liferay.portal.util;
022:
023: import com.liferay.portal.kernel.util.StringPool;
024:
025: import java.util.Date;
026:
027: /**
028: * <a href="ShutdownUtil.java.html"><b><i>View Source</i></b></a>
029: *
030: * @author Brian Wing Shun Chan
031: *
032: */
033: public class ShutdownUtil {
034:
035: public static void cancel() {
036: _instance._cancel();
037: }
038:
039: public static long getInProcess() {
040: return _instance._getInProcess();
041: }
042:
043: public static String getMessage() {
044: return _instance._getMessage();
045: }
046:
047: public static boolean isInProcess() {
048: return _instance._isInProcess();
049: }
050:
051: public static boolean isShutdown() {
052: return _instance._isShutdown();
053: }
054:
055: public static void shutdown(long milliseconds) {
056: shutdown(milliseconds, StringPool.BLANK);
057: }
058:
059: public static void shutdown(long milliseconds, String message) {
060: _instance._shutdown(milliseconds, message);
061: }
062:
063: private ShutdownUtil() {
064: }
065:
066: private void _cancel() {
067: _date = null;
068: _message = null;
069: }
070:
071: private long _getInProcess() {
072: long milliseconds = 0;
073:
074: if (_date != null) {
075: milliseconds = _date.getTime() - System.currentTimeMillis();
076: }
077:
078: return milliseconds;
079: }
080:
081: private String _getMessage() {
082: return _message;
083: }
084:
085: private boolean _isInProcess() {
086: if (_date == null) {
087: return false;
088: } else {
089: if (_date.after(new Date())) {
090: return true;
091: } else {
092: return false;
093: }
094: }
095: }
096:
097: private boolean _isShutdown() {
098: if (_date == null) {
099: return false;
100: } else {
101: if (_date.before(new Date())) {
102: return true;
103: } else {
104: return false;
105: }
106: }
107: }
108:
109: private void _shutdown(long milliseconds, String message) {
110: _date = new Date(System.currentTimeMillis() + milliseconds);
111: _message = message;
112: }
113:
114: private static ShutdownUtil _instance = new ShutdownUtil();
115:
116: private Date _date;
117: private String _message;
118:
119: }
|