1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   *
13   */
14  
15  package com.liferay.portal.util;
16  
17  import com.liferay.portal.kernel.util.StringPool;
18  
19  import java.util.Date;
20  
21  /**
22   * <a href="ShutdownUtil.java.html"><b><i>View Source</i></b></a>
23   *
24   * @author Brian Wing Shun Chan
25   */
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 }