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