Save This Page
Home » glassfish-v2ur2-b04-src » javax » servlet » [javadoc | source]
    1   
    2   
    3   /*
    4    * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
    5    * 
    6    * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
    7    * 
    8    * Portions Copyright Apache Software Foundation.
    9    * 
   10    * The contents of this file are subject to the terms of either the GNU
   11    * General Public License Version 2 only ("GPL") or the Common Development
   12    * and Distribution License("CDDL") (collectively, the "License").  You
   13    * may not use this file except in compliance with the License. You can obtain
   14    * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
   15    * or glassfish/bootstrap/legal/LICENSE.txt.  See the License for the specific
   16    * language governing permissions and limitations under the License.
   17    * 
   18    * When distributing the software, include this License Header Notice in each
   19    * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
   20    * Sun designates this particular file as subject to the "Classpath" exception
   21    * as provided by Sun in the GPL Version 2 section of the License file that
   22    * accompanied this code.  If applicable, add the following below the License
   23    * Header, with the fields enclosed by brackets [] replaced by your own
   24    * identifying information: "Portions Copyrighted [year]
   25    * [name of copyright owner]"
   26    * 
   27    * Contributor(s):
   28    * 
   29    * If you wish your version of this file to be governed by only the CDDL or
   30    * only the GPL Version 2, indicate your decision by adding "[Contributor]
   31    * elects to include this software in this distribution under the [CDDL or GPL
   32    * Version 2] license."  If you don't indicate a single choice of license, a
   33    * recipient has the option to distribute your version of this file under
   34    * either the CDDL, the GPL Version 2 or to extend the choice of license to
   35    * its licensees as provided above.  However, if you add GPL Version 2 code
   36    * and therefore, elected the GPL Version 2 license, then the option applies
   37    * only if the new code is made subject to such option by the copyright
   38    * holder.
   39    */
   40   
   41   package javax.servlet;
   42   
   43   
   44   /**
   45    * Defines an exception that a servlet or filter throws to indicate
   46    * that it is permanently or temporarily unavailable. 
   47    *
   48    * <p>When a servlet or filter is permanently unavailable, something is wrong
   49    * with it, and it cannot handle
   50    * requests until some action is taken. For example, a servlet
   51    * might be configured incorrectly, or a filter's state may be corrupted.
   52    * The component should log both the error and the corrective action
   53    * that is needed.
   54    *
   55    * <p>A servlet or filter is temporarily unavailable if it cannot handle
   56    * requests momentarily due to some system-wide problem. For example,
   57    * a third-tier server might not be accessible, or there may be 
   58    * insufficient memory or disk storage to handle requests. A system
   59    * administrator may need to take corrective action.
   60    *
   61    * <p>Servlet containers can safely treat both types of unavailable
   62    * exceptions in the same way. However, treating temporary unavailability
   63    * effectively makes the servlet container more robust. Specifically,
   64    * the servlet container might block requests to the servlet or filter for a period
   65    * of time suggested by the exception, rather than rejecting them until
   66    * the servlet container restarts.
   67    *
   68    *
   69    * @author 	Various
   70    *
   71    */
   72   
   73   public class UnavailableException
   74   extends ServletException {
   75   
   76       private Servlet     servlet;           // what's unavailable
   77       private boolean     permanent;         // needs admin action?
   78       private int         seconds;           // unavailability estimate
   79   
   80       /**
   81        * 
   82        * @deprecated	As of Java Servlet API 2.2, use {@link
   83        * 			#UnavailableException(String)} instead.
   84        *
   85        * @param servlet 	the <code>Servlet</code> instance that is
   86        *                  unavailable
   87        *
   88        * @param msg 	a <code>String</code> specifying the
   89        *                  descriptive message
   90        *
   91        */
   92   
   93       public UnavailableException(Servlet servlet, String msg) {
   94   	super(msg);
   95   	this.servlet = servlet;
   96   	permanent = true;
   97       }
   98    
   99       /**
  100        * @deprecated	As of Java Servlet API 2.2, use {@link
  101        *			#UnavailableException(String, int)} instead.
  102        *
  103        * @param seconds	an integer specifying the number of seconds
  104        * 			the servlet expects to be unavailable; if
  105        *			zero or negative, indicates that the servlet
  106        *			can't make an estimate
  107        *
  108        * @param servlet	the <code>Servlet</code> that is unavailable
  109        * 
  110        * @param msg	a <code>String</code> specifying the descriptive 
  111        *			message, which can be written to a log file or 
  112        *			displayed for the user.
  113        *
  114        */
  115       
  116       public UnavailableException(int seconds, Servlet servlet, String msg) {
  117   	super(msg);
  118   	this.servlet = servlet;
  119   	if (seconds <= 0)
  120   	    this.seconds = -1;
  121   	else
  122   	    this.seconds = seconds;
  123   	permanent = false;
  124       }
  125   
  126       /**
  127        * 
  128        * Constructs a new exception with a descriptive
  129        * message indicating that the servlet is permanently
  130        * unavailable.
  131        *
  132        * @param msg 	a <code>String</code> specifying the
  133        *                  descriptive message
  134        *
  135        */
  136   
  137       public UnavailableException(String msg) {
  138   	super(msg);
  139   
  140   	permanent = true;
  141       }
  142   
  143       /**
  144        * Constructs a new exception with a descriptive message
  145        * indicating that the servlet is temporarily unavailable
  146        * and giving an estimate of how long it will be unavailable.
  147        * 
  148        * <p>In some cases, the servlet cannot make an estimate. For
  149        * example, the servlet might know that a server it needs is
  150        * not running, but not be able to report how long it will take
  151        * to be restored to functionality. This can be indicated with
  152        * a negative or zero value for the <code>seconds</code> argument.
  153        *
  154        * @param msg	a <code>String</code> specifying the
  155        *                  descriptive message, which can be written
  156        *                  to a log file or displayed for the user.
  157        *
  158        * @param seconds	an integer specifying the number of seconds
  159        * 			the servlet expects to be unavailable; if
  160        *			zero or negative, indicates that the servlet
  161        *			can't make an estimate
  162        *
  163        */
  164       
  165       public UnavailableException(String msg, int seconds) {
  166   	super(msg);
  167   
  168   	if (seconds <= 0)
  169   	    this.seconds = -1;
  170   	else
  171   	    this.seconds = seconds;
  172   
  173   	permanent = false;
  174       }
  175   
  176       /**
  177        *
  178        * Returns a <code>boolean</code> indicating
  179        * whether the servlet is permanently unavailable.
  180        * If so, something is wrong with the servlet, and the
  181        * system administrator must take some corrective action.
  182        *
  183        * @return		<code>true</code> if the servlet is
  184        *			permanently unavailable; <code>false</code>
  185        *			if the servlet is available or temporarily
  186        *			unavailable
  187        *
  188        */
  189        
  190       public boolean isPermanent() {
  191   	return permanent;
  192       }
  193     
  194       /**
  195        * @deprecated	As of Java Servlet API 2.2, with no replacement.
  196        *
  197        * Returns the servlet that is reporting its unavailability.
  198        * 
  199        * @return		the <code>Servlet</code> object that is 
  200        *			throwing the <code>UnavailableException</code>
  201        *
  202        */
  203        
  204       public Servlet getServlet() {
  205   	return servlet;
  206       }
  207   
  208       /**
  209        * Returns the number of seconds the servlet expects to 
  210        * be temporarily unavailable.  
  211        *
  212        * <p>If this method returns a negative number, the servlet
  213        * is permanently unavailable or cannot provide an estimate of
  214        * how long it will be unavailable. No effort is
  215        * made to correct for the time elapsed since the exception was
  216        * first reported.
  217        *
  218        * @return		an integer specifying the number of seconds
  219        *			the servlet will be temporarily unavailable,
  220        *			or a negative number if the servlet is permanently
  221        *			unavailable or cannot make an estimate
  222        *
  223        */
  224        
  225       public int getUnavailableSeconds() {
  226   	return permanent ? -1 : seconds;
  227       }
  228   }

Save This Page
Home » glassfish-v2ur2-b04-src » javax » servlet » [javadoc | source]