001 /*
002 * Copyright 2004 The Apache Software Foundation
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017 package javax.servlet;
018
019 /**
020 * Defines an exception that a servlet or filter throws to indicate
021 * that it is permanently or temporarily unavailable.
022 *
023 * <p>When a servlet or filter is permanently unavailable, something is wrong
024 * with it, and it cannot handle
025 * requests until some action is taken. For example, a servlet
026 * might be configured incorrectly, or a filter's state may be corrupted.
027 * The component should log both the error and the corrective action
028 * that is needed.
029 *
030 * <p>A servlet or filter is temporarily unavailable if it cannot handle
031 * requests momentarily due to some system-wide problem. For example,
032 * a third-tier server might not be accessible, or there may be
033 * insufficient memory or disk storage to handle requests. A system
034 * administrator may need to take corrective action.
035 *
036 * <p>Servlet containers can safely treat both types of unavailable
037 * exceptions in the same way. However, treating temporary unavailability
038 * effectively makes the servlet container more robust. Specifically,
039 * the servlet container might block requests to the servlet or filter for a period
040 * of time suggested by the exception, rather than rejecting them until
041 * the servlet container restarts.
042 *
043 *
044 * @author Various
045 * @version $Version$
046 *
047 */
048
049 public class UnavailableException extends ServletException {
050
051 private Servlet servlet; // what's unavailable
052 private boolean permanent; // needs admin action?
053 private int seconds; // unavailability estimate
054
055 /**
056 *
057 * @deprecated As of Java Servlet API 2.2, use {@link
058 * #UnavailableException(String)} instead.
059 *
060 * @param servlet the <code>Servlet</code> instance that is
061 * unavailable
062 *
063 * @param msg a <code>String</code> specifying the
064 * descriptive message
065 *
066 */
067
068 public UnavailableException(Servlet servlet, String msg) {
069 super (msg);
070 this .servlet = servlet;
071 permanent = true;
072 }
073
074 /**
075 * @deprecated As of Java Servlet API 2.2, use {@link
076 * #UnavailableException(String, int)} instead.
077 *
078 * @param seconds an integer specifying the number of seconds
079 * the servlet expects to be unavailable; if
080 * zero or negative, indicates that the servlet
081 * can't make an estimate
082 *
083 * @param servlet the <code>Servlet</code> that is unavailable
084 *
085 * @param msg a <code>String</code> specifying the descriptive
086 * message, which can be written to a log file or
087 * displayed for the user.
088 *
089 */
090
091 public UnavailableException(int seconds, Servlet servlet, String msg) {
092 super (msg);
093 this .servlet = servlet;
094 if (seconds <= 0)
095 this .seconds = -1;
096 else
097 this .seconds = seconds;
098 permanent = false;
099 }
100
101 /**
102 *
103 * Constructs a new exception with a descriptive
104 * message indicating that the servlet is permanently
105 * unavailable.
106 *
107 * @param msg a <code>String</code> specifying the
108 * descriptive message
109 *
110 */
111
112 public UnavailableException(String msg) {
113 super (msg);
114
115 permanent = true;
116 }
117
118 /**
119 * Constructs a new exception with a descriptive message
120 * indicating that the servlet is temporarily unavailable
121 * and giving an estimate of how long it will be unavailable.
122 *
123 * <p>In some cases, the servlet cannot make an estimate. For
124 * example, the servlet might know that a server it needs is
125 * not running, but not be able to report how long it will take
126 * to be restored to functionality. This can be indicated with
127 * a negative or zero value for the <code>seconds</code> argument.
128 *
129 * @param msg a <code>String</code> specifying the
130 * descriptive message, which can be written
131 * to a log file or displayed for the user.
132 *
133 * @param seconds an integer specifying the number of seconds
134 * the servlet expects to be unavailable; if
135 * zero or negative, indicates that the servlet
136 * can't make an estimate
137 *
138 */
139
140 public UnavailableException(String msg, int seconds) {
141 super (msg);
142
143 if (seconds <= 0)
144 this .seconds = -1;
145 else
146 this .seconds = seconds;
147
148 permanent = false;
149 }
150
151 /**
152 *
153 * Returns a <code>boolean</code> indicating
154 * whether the servlet is permanently unavailable.
155 * If so, something is wrong with the servlet, and the
156 * system administrator must take some corrective action.
157 *
158 * @return <code>true</code> if the servlet is
159 * permanently unavailable; <code>false</code>
160 * if the servlet is available or temporarily
161 * unavailable
162 *
163 */
164
165 public boolean isPermanent() {
166 return permanent;
167 }
168
169 /**
170 * @deprecated As of Java Servlet API 2.2, with no replacement.
171 *
172 * Returns the servlet that is reporting its unavailability.
173 *
174 * @return the <code>Servlet</code> object that is
175 * throwing the <code>UnavailableException</code>
176 *
177 */
178
179 public Servlet getServlet() {
180 return servlet;
181 }
182
183 /**
184 * Returns the number of seconds the servlet expects to
185 * be temporarily unavailable.
186 *
187 * <p>If this method returns a negative number, the servlet
188 * is permanently unavailable or cannot provide an estimate of
189 * how long it will be unavailable. No effort is
190 * made to correct for the time elapsed since the exception was
191 * first reported.
192 *
193 * @return an integer specifying the number of seconds
194 * the servlet will be temporarily unavailable,
195 * or a negative number if the servlet is permanently
196 * unavailable or cannot make an estimate
197 *
198 */
199
200 public int getUnavailableSeconds() {
201 return permanent ? -1 : seconds;
202 }
203 }
|