1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    *
5    *
6    *
7    * The contents of this file are subject to the terms of the Liferay Enterprise
8    * Subscription License ("License"). You may not use this file except in
9    * compliance with the License. You can obtain a copy of the License by
10   * contacting Liferay, Inc. See the License for the specific language governing
11   * permissions and limitations under the License, including but not limited to
12   * distribution rights of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  package com.liferay.portal.util;
24  
25  import com.liferay.portal.kernel.util.StringPool;
26  
27  import java.util.Date;
28  
29  /**
30   * <a href="ShutdownUtil.java.html"><b><i>View Source</i></b></a>
31   *
32   * @author Brian Wing Shun Chan
33   */
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 }