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