| ShutdownUtil.java |
1 /**
2 * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 * SOFTWARE.
21 */
22
23 package com.liferay.portal.util;
24
25 import com.liferay.portal.kernel.util.StringPool;
26
27 import java.util.Date;
28
29 /**
30 * <a href="ShutdownUtil.java.html"><b><i>View Source</i></b></a>
31 *
32 * @author Brian Wing Shun Chan
33 *
34 */
35 public class ShutdownUtil {
36
37 public static void cancel() {
38 _instance._cancel();
39 }
40
41 public static long getInProcess() {
42 return _instance._getInProcess();
43 }
44
45 public static String getMessage() {
46 return _instance._getMessage();
47 }
48
49 public static boolean isInProcess() {
50 return _instance._isInProcess();
51 }
52
53 public static boolean isShutdown() {
54 return _instance._isShutdown();
55 }
56
57 public static void shutdown(long milliseconds) {
58 shutdown(milliseconds, StringPool.BLANK);
59 }
60
61 public static void shutdown(long milliseconds, String message) {
62 _instance._shutdown(milliseconds, message);
63 }
64
65 private ShutdownUtil() {
66 }
67
68 private void _cancel() {
69 _date = null;
70 _message = null;
71 }
72
73 private long _getInProcess() {
74 long milliseconds = 0;
75
76 if (_date != null) {
77 milliseconds = _date.getTime() - System.currentTimeMillis();
78 }
79
80 return milliseconds;
81 }
82
83 private String _getMessage() {
84 return _message;
85 }
86
87 private boolean _isInProcess() {
88 if (_date == null) {
89 return false;
90 }
91 else {
92 if (_date.after(new Date())) {
93 return true;
94 }
95 else {
96 return false;
97 }
98 }
99 }
100
101 private boolean _isShutdown() {
102 if (_date == null) {
103 return false;
104 }
105 else {
106 if (_date.before(new Date())) {
107 return true;
108 }
109 else {
110 return false;
111 }
112 }
113 }
114
115 private void _shutdown(long milliseconds, String message) {
116 _date = new Date(System.currentTimeMillis() + milliseconds);
117 _message = message;
118 }
119
120 private static ShutdownUtil _instance = new ShutdownUtil();
121
122 private Date _date;
123 private String _message;
124
125 }