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
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 }