KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > portlet > UnavailableException


1 /**
2   * Copyright 2003 IBM Corporation and Sun Microsystems, Inc.
3   * All rights reserved.
4   * Use is subject to license terms.
5   */

6
7 package javax.portlet;
8
9 /**
10  * The portlet should throw the <CODE>UnavailableException</CODE> when
11  * the portlet is either temporarily or permanently unavailable to handle requests.
12  *
13  **/

14
15 public class UnavailableException extends PortletException
16 {
17
18     private boolean permanent; // needs admin action?
19
private int seconds; // unavailability estimate
20

21
22     /**
23      *
24      * Constructs a new exception with a descriptive
25      * message indicating that the portlet is permanently
26      * unavailable.
27      *
28      * @param text a <code>String</code> specifying the
29      * descriptive message
30      *
31      */

32
33     public UnavailableException(String JavaDoc text) {
34     super(text);
35
36     permanent = true;
37     }
38
39     /**
40      * Constructs a new exception with a descriptive message
41      * indicating that the portlet is temporarily unavailable
42      * and giving an estimate of how long it will be unavailable.
43      *
44      * <p>In some cases, the portlet cannot make an estimate. For
45      * example, the portlet might know that a server it needs is
46      * not running, but it might not be able to report how long it will take
47      * to be restored to functionality. This can be indicated with
48      * a negative or zero value for the <code>seconds</code> argument.
49      *
50      * @param text a <code>String</code> specifying the
51      * descriptive message. This message can be written
52      * to a log file or displayed for the user.
53      *
54      * @param seconds an integer specifying the number of seconds
55      * for which the portlet expects to be unavailable; if
56      * this is zero or negative, it indicates that the portlet
57      * cannot make an estimate.
58      *
59      */

60     
61     public UnavailableException(String JavaDoc text, int seconds) {
62     super(text);
63
64     if (seconds <= 0)
65         this.seconds = -1;
66     else
67         this.seconds = seconds;
68
69     permanent = false;
70     }
71
72     /**
73      *
74      * Returns a <code>boolean</code> indicating
75      * whether the portlet is permanently unavailable.
76      * If so, something is wrong with the portlet, and the
77      * system administrator must take some corrective action.
78      *
79      * @return <code>true</code> if the portlet is
80      * permanently unavailable; <code>false</code>
81      * if the portlet is temporarily
82      * unavailable.
83      *
84      */

85      
86     public boolean isPermanent() {
87     return permanent;
88     }
89   
90
91     /**
92      * Returns the time in seconds for which the portlet can be expected to
93      * be unavailable.
94      * <p>
95      * If the portlet is called again while it is still unavailable, it
96      * indicates the same time estimate. No effort is
97      * made to correct for the time elapsed since the exception was
98      * first reported.
99      * <p>
100      * If this method returns zero or a negative number, the portlet
101      * is permanently unavailable or cannot provide an estimate of
102      * how long it will be unavailable.
103      *
104      * @return an integer specifying the number of seconds
105      * the portlet will be temporarily unavailable,
106      * or zero or a negative number if the portlet is permanently
107      * unavailable or cannot make an estimate.
108      *
109      */

110      
111     public int getUnavailableSeconds() {
112     return permanent ? -1 : seconds;
113     }
114
115
116 }
117
Popular Tags