1
14
15 package com.liferay.portal.util;
16
17 import com.liferay.portal.kernel.util.StringPool;
18
19 import java.util.Date;
20
21
26 public class ShutdownUtil {
27
28 public static void cancel() {
29 _instance._cancel();
30 }
31
32 public static long getInProcess() {
33 return _instance._getInProcess();
34 }
35
36 public static String getMessage() {
37 return _instance._getMessage();
38 }
39
40 public static boolean isInProcess() {
41 return _instance._isInProcess();
42 }
43
44 public static boolean isShutdown() {
45 return _instance._isShutdown();
46 }
47
48 public static void shutdown(long milliseconds) {
49 shutdown(milliseconds, StringPool.BLANK);
50 }
51
52 public static void shutdown(long milliseconds, String message) {
53 _instance._shutdown(milliseconds, message);
54 }
55
56 private ShutdownUtil() {
57 }
58
59 private void _cancel() {
60 _date = null;
61 _message = null;
62 }
63
64 private long _getInProcess() {
65 long milliseconds = 0;
66
67 if (_date != null) {
68 milliseconds = _date.getTime() - System.currentTimeMillis();
69 }
70
71 return milliseconds;
72 }
73
74 private String _getMessage() {
75 return _message;
76 }
77
78 private boolean _isInProcess() {
79 if (_date == null) {
80 return false;
81 }
82 else {
83 if (_date.after(new Date())) {
84 return true;
85 }
86 else {
87 return false;
88 }
89 }
90 }
91
92 private boolean _isShutdown() {
93 if (_date == null) {
94 return false;
95 }
96 else {
97 if (_date.before(new Date())) {
98 return true;
99 }
100 else {
101 return false;
102 }
103 }
104 }
105
106 private void _shutdown(long milliseconds, String message) {
107 _date = new Date(System.currentTimeMillis() + milliseconds);
108 _message = message;
109 }
110
111 private static ShutdownUtil _instance = new ShutdownUtil();
112
113 private Date _date;
114 private String _message;
115
116 }