blob: 3ea2d57f68f25e9770c9fc8b77988dac65e25b6a [file] [log] [blame]
Michael E. Rodriguezd8af66f2005-12-08 20:55:55 +00001/*
2 * Copyright 1999,2005 The Apache Software Foundation.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package javax.servlet;
18
19
20/**
21 * Defines an exception that a servlet throws to indicate
22 * that it is permanently or temporarily unavailable.
23 *
24 * <p>When a servlet is permanently unavailable, something is wrong
25 * with the servlet, and it cannot handle
26 * requests until some action is taken. For example, the servlet
27 * might be configured incorrectly, or its state may be corrupted.
28 * A servlet should log both the error and the corrective action
29 * that is needed.
30 *
31 * <p>A servlet is temporarily unavailable if it cannot handle
32 * requests momentarily due to some system-wide problem. For example,
33 * a third-tier server might not be accessible, or there may be
34 * insufficient memory or disk storage to handle requests. A system
35 * administrator may need to take corrective action.
36 *
37 * <p>Servlet containers can safely treat both types of unavailable
38 * exceptions in the same way. However, treating temporary unavailability
39 * effectively makes the servlet container more robust. Specifically,
40 * the servlet container might block requests to the servlet for a period
41 * of time suggested by the exception, rather than rejecting them until
42 * the servlet container restarts.
43 *
44 *
45 * @author Various
46 * @version $Version$
47 *
48 */
49
50public class UnavailableException
51extends ServletException {
52
53 private Servlet servlet; // what's unavailable
54 private boolean permanent; // needs admin action?
55 private int seconds; // unavailability estimate
56
57 /**
58 *
59 * @param servlet the <code>Servlet</code> instance that is
60 * unavailable
61 *
62 * @param msg a <code>String</code> specifying the
63 * descriptive message
64 *
65 */
66
67 public UnavailableException(Servlet servlet, String msg) {
68 super(msg);
69 this.servlet = servlet;
70 permanent = true;
71 }
72
73 /**
74 *
75 * @param seconds an integer specifying the number of seconds
76 * the servlet expects to be unavailable; if
77 * zero or negative, indicates that the servlet
78 * can't make an estimate
79 *
80 * @param servlet the <code>Servlet</code> that is unavailable
81 *
82 * @param msg a <code>String</code> specifying the descriptive
83 * message, which can be written to a log file or
84 * displayed for the user.
85 *
86 */
87
88 public UnavailableException(int seconds, Servlet servlet, String msg) {
89 super(msg);
90 this.servlet = servlet;
91 if (seconds <= 0)
92 this.seconds = -1;
93 else
94 this.seconds = seconds;
95 permanent = false;
96 }
97
98 /**
99 *
100 * Returns a <code>boolean</code> indicating
101 * whether the servlet is permanently unavailable.
102 * If so, something is wrong with the servlet, and the
103 * system administrator must take some corrective action.
104 *
105 * @return <code>true</code> if the servlet is
106 * permanently unavailable; <code>false</code>
107 * if the servlet is available or temporarily
108 * unavailable
109 *
110 */
111
112 public boolean isPermanent() {
113 return permanent;
114 }
115
116 /**
117 *
118 * Returns the servlet that is reporting its unavailability.
119 *
120 * @return the <code>Servlet</code> object that is
121 * throwing the <code>UnavailableException</code>
122 *
123 */
124
125 public Servlet getServlet() {
126 return servlet;
127 }
128
129 /**
130 * Returns the number of seconds the servlet expects to
131 * be temporarily unavailable.
132 *
133 * <p>If this method returns a negative number, the servlet
134 * is permanently unavailable or cannot provide an estimate of
135 * how long it will be unavailable. No effort is
136 * made to correct for the time elapsed since the exception was
137 * first reported.
138 *
139 * @return an integer specifying the number of seconds
140 * the servlet will be temporarily unavailable,
141 * or a negative number if the servlet is permanently
142 * unavailable or cannot make an estimate
143 *
144 */
145
146 public int getUnavailableSeconds() {
147 return permanent ? -1 : seconds;
148 }
149}