home *** CD-ROM | disk | FTP | other *** search
/ Java Developer's Companion / Java Developer's Companion.iso / binaries / Windows / jsdk / src / javax / servlet / UnavailableException.java < prev   
Encoding:
Java Source  |  1997-07-18  |  4.7 KB  |  137 lines

  1. /*
  2.  * @(#)UnavailableException.java    1.4 97/05/22
  3.  * 
  4.  * Copyright (c) 1997 Sun Microsystems, Inc. All Rights Reserved.
  5.  * 
  6.  * This software is the confidential and proprietary information of Sun
  7.  * Microsystems, Inc. ("Confidential Information").  You shall not
  8.  * disclose such Confidential Information and shall use it only in
  9.  * accordance with the terms of the license agreement you entered into
  10.  * with Sun.
  11.  * 
  12.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
  13.  * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  14.  * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  15.  * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
  16.  * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
  17.  * THIS SOFTWARE OR ITS DERIVATIVES.
  18.  * 
  19.  * CopyrightVersion 1.0
  20.  */
  21.  
  22. package javax.servlet;
  23.  
  24.  
  25. /**
  26.  * This exception indicates that a servlet is unavailable.  Servlets
  27.  * may report this exception at any time, and the network service
  28.  * running the servlet should behave appropriately.  There are two
  29.  * types of unavailability, and sophisticated services will to deal
  30.  * with these differently: <UL>
  31.  * 
  32.  * <LI> <em>Permanent</em> unavailability.  The servlet will not be
  33.  * able to handle client requests until some administrative action is
  34.  * taken to correct a servlet problem.  For example, the servlet might
  35.  * be misconfigured, or the state of the servlet may be corrupted.
  36.  * Well written servlets will log both the error and the corrective
  37.  * action which an administrator must perform to let the servlet
  38.  * become available.
  39.  *
  40.  * <LI> <em>Temporary</em> unavailability.  The servlet can not handle
  41.  * requests at this moment due to a system-wide problem.  For example,
  42.  * a third tier server might not be accessible, or there may be
  43.  * insufficient memory or disk storage to handle requests.  The
  44.  * problem may be self correcting, such as those due to excessive
  45.  * load, or corrective action may need to be taken by an
  46.  * administrator.
  47.  *
  48.  * </UL>
  49.  *
  50.  * <P> Network services may safely treat both types of exceptions as
  51.  * "permanent", but good treatment of temporary unavailability leads
  52.  * to more robust network services.  Specifically, requests to the
  53.  * servlet might be blocked (or otherwise deferred) for a
  54.  * servlet-suggested amount of time, rather than being rejected until
  55.  * the service itself restarts.
  56.  *
  57.  * @version    1.4
  58.  * @author David Brownell
  59.  */
  60. public 
  61. class UnavailableException extends ServletException {
  62.     private Servlet    servlet;        // what's unavailable
  63.     private boolean    permanent;        // needs admin action?
  64.     private int        seconds;        // unavailability estimate
  65.  
  66.  
  67.     /**
  68.      * 
  69.      * Constructs a new exception with the specified descriptive
  70.      * message, indicating that the servlet is permanently
  71.      * unavailable.
  72.      *
  73.      * @param servlet the servlet which is unavailable
  74.      * @param msg the descriptive message
  75.      */
  76.     public UnavailableException (Servlet servlet, String msg) {
  77.     super (msg);
  78.     this.servlet = servlet;
  79.     permanent = true;
  80.     }
  81.  
  82.  
  83.     /**
  84.      * Constructs a new exception with the specified descriptive message,
  85.      * indicating that the servlet is temporarily unavailable and giving
  86.      * an estimate of how long it will be unavailable.  In some cases, no
  87.      * estimate can be made; this is indicated by a non-positive time.
  88.      * For example, the servlet might know a server it needs is "down",
  89.      * but not be able to report how long it will take to restore it to
  90.      * an adequate level of functionality.
  91.      *
  92.      * @param seconds number of seconds that the servlet is anticipated
  93.      *    to be unavailable.  If negative or zero, no estimate is available.
  94.      * @param servlet the servlet which is unavailable
  95.      * @param msg the descriptive message
  96.      */
  97.     public UnavailableException (int seconds, Servlet servlet, String msg) {
  98.     super (msg);
  99.     this.servlet = servlet;
  100.     if (seconds <= 0)
  101.         seconds = -1;
  102.     else
  103.         this.seconds = seconds;
  104.     permanent = false;
  105.     }
  106.  
  107.  
  108.     /**
  109.      * Returns true if the servlet is "permanently" unavailable,
  110.      * indicating that the service administrator must take some
  111.      * corrective action to make the servlet be usable.
  112.      */
  113.     public boolean isPermanent () {
  114.     return permanent;
  115.     }
  116.  
  117.  
  118.     /**
  119.      * Returns the servlet that is reporting its unavailability.
  120.      */
  121.     public Servlet getServlet () {
  122.     return servlet;
  123.     }
  124.  
  125.  
  126.     /**
  127.      * Returns the amount of time the servlet expects to be temporarily
  128.      * unavailable.  If the servlet is permanently unavailable, or no
  129.      * estimate was provided, returns a negative number.  No effort is
  130.      * made to correct for the time elapsed since the exception was
  131.      * first reported.
  132.      */
  133.     public int getUnavailableSeconds () {
  134.     return permanent ? -1 : seconds;
  135.     }
  136. }
  137.