2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
18 package javax.servlet;
21 * Defines an exception that a servlet or filter throws to indicate that it is
22 * permanently or temporarily unavailable.
24 * When a servlet or filter is permanently unavailable, something is wrong with
25 * it, and it cannot handle requests until some action is taken. For example, a
26 * servlet might be configured incorrectly, or a filter's state may be
27 * corrupted. The component should log both the error and the corrective action
30 * A servlet or filter is temporarily unavailable if it cannot handle requests
31 * momentarily due to some system-wide problem. For example, a third-tier server
32 * might not be accessible, or there may be insufficient memory or disk storage
33 * to handle requests. A system administrator may need to take corrective
36 * Servlet containers can safely treat both types of unavailable exceptions in
37 * the same way. However, treating temporary unavailability effectively makes
38 * the servlet container more robust. Specifically, the servlet container might
39 * block requests to the servlet or filter for a period of time suggested by the
40 * exception, rather than rejecting them until the servlet container restarts.
42 public class UnavailableException extends ServletException {
44 private static final long serialVersionUID = 1L;
46 private final Servlet servlet; // what's unavailable
47 private final boolean permanent; // needs admin action?
48 private final int seconds; // unavailability estimate
52 * the <code>Servlet</code> instance that is unavailable
54 * a <code>String</code> specifying the descriptive message
55 * @deprecated As of Java Servlet API 2.2, use
56 * {@link #UnavailableException(String)} instead.
58 @SuppressWarnings("dep-ann")
59 // Spec API does not use @Deprecated
60 public UnavailableException(Servlet servlet, String msg) {
62 this.servlet = servlet;
69 * an integer specifying the number of seconds the servlet
70 * expects to be unavailable; if zero or negative, indicates that
71 * the servlet can't make an estimate
73 * the <code>Servlet</code> that is unavailable
75 * a <code>String</code> specifying the descriptive message,
76 * which can be written to a log file or displayed for the user.
77 * @deprecated As of Java Servlet API 2.2, use
78 * {@link #UnavailableException(String, int)} instead.
80 @SuppressWarnings("dep-ann")
81 // Spec API does not use @Deprecated
82 public UnavailableException(int seconds, Servlet servlet, String msg) {
84 this.servlet = servlet;
88 this.seconds = seconds;
93 * Constructs a new exception with a descriptive message indicating that the
94 * servlet is permanently unavailable.
97 * a <code>String</code> specifying the descriptive message
99 public UnavailableException(String msg) {
107 * Constructs a new exception with a descriptive message indicating that the
108 * servlet is temporarily unavailable and giving an estimate of how long it
109 * will be unavailable.
111 * In some cases, the servlet cannot make an estimate. For example, the
112 * servlet might know that a server it needs is not running, but not be able
113 * to report how long it will take to be restored to functionality. This can
114 * be indicated with a negative or zero value for the <code>seconds</code>
118 * a <code>String</code> specifying the descriptive message,
119 * which can be written to a log file or displayed for the user.
121 * an integer specifying the number of seconds the servlet
122 * expects to be unavailable; if zero or negative, indicates that
123 * the servlet can't make an estimate
125 public UnavailableException(String msg, int seconds) {
131 this.seconds = seconds;
137 * Returns a <code>boolean</code> indicating whether the servlet is
138 * permanently unavailable. If so, something is wrong with the servlet, and
139 * the system administrator must take some corrective action.
141 * @return <code>true</code> if the servlet is permanently unavailable;
142 * <code>false</code> if the servlet is available or temporarily
145 public boolean isPermanent() {
150 * Returns the servlet that is reporting its unavailability.
152 * @return the <code>Servlet</code> object that is throwing the
153 * <code>UnavailableException</code>
154 * @deprecated As of Java Servlet API 2.2, with no replacement.
156 @SuppressWarnings("dep-ann")
157 // Spec API does not use @Deprecated
158 public Servlet getServlet() {
163 * Returns the number of seconds the servlet expects to be temporarily
166 * If this method returns a negative number, the servlet is permanently
167 * unavailable or cannot provide an estimate of how long it will be
168 * unavailable. No effort is made to correct for the time elapsed since the
169 * exception was first reported.
171 * @return an integer specifying the number of seconds the servlet will be
172 * temporarily unavailable, or a negative number if the servlet is
173 * permanently unavailable or cannot make an estimate
175 public int getUnavailableSeconds() {
176 return permanent ? -1 : seconds;