home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgLangD.iso / VCAFE.3.0A / Main.bin / UnavailableException.java < prev    next >
Text File  |  1998-04-21  |  5KB  |  136 lines

  1. /*
  2.  * @(#)UnavailableException.java    1.5 97/07/15
  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.5
  58.  */
  59. public 
  60. class UnavailableException extends ServletException {
  61.     private Servlet    servlet;        // what's unavailable
  62.     private boolean    permanent;        // needs admin action?
  63.     private int        seconds;        // unavailability estimate
  64.  
  65.  
  66.     /**
  67.      * 
  68.      * Constructs a new exception with the specified descriptive
  69.      * message, indicating that the servlet is permanently
  70.      * unavailable.
  71.      *
  72.      * @param servlet the servlet which is unavailable
  73.      * @param msg the descriptive message
  74.      */
  75.     public UnavailableException (Servlet servlet, String msg) {
  76.     super (msg);
  77.     this.servlet = servlet;
  78.     permanent = true;
  79.     }
  80.  
  81.  
  82.     /**
  83.      * Constructs a new exception with the specified descriptive message,
  84.      * indicating that the servlet is temporarily unavailable and giving
  85.      * an estimate of how long it will be unavailable.  In some cases, no
  86.      * estimate can be made; this is indicated by a non-positive time.
  87.      * For example, the servlet might know a server it needs is "down",
  88.      * but not be able to report how long it will take to restore it to
  89.      * an adequate level of functionality.
  90.      *
  91.      * @param seconds number of seconds that the servlet is anticipated
  92.      *    to be unavailable.  If negative or zero, no estimate is available.
  93.      * @param servlet the servlet which is unavailable
  94.      * @param msg the descriptive message
  95.      */
  96.     public UnavailableException (int seconds, Servlet servlet, String msg) {
  97.     super (msg);
  98.     this.servlet = servlet;
  99.     if (seconds <= 0)
  100.         seconds = -1;
  101.     else
  102.         this.seconds = seconds;
  103.     permanent = false;
  104.     }
  105.  
  106.  
  107.     /**
  108.      * Returns true if the servlet is "permanently" unavailable,
  109.      * indicating that the service administrator must take some
  110.      * corrective action to make the servlet be usable.
  111.      */
  112.     public boolean isPermanent () {
  113.     return permanent;
  114.     }
  115.  
  116.  
  117.     /**
  118.      * Returns the servlet that is reporting its unavailability.
  119.      */
  120.     public Servlet getServlet () {
  121.     return servlet;
  122.     }
  123.  
  124.  
  125.     /**
  126.      * Returns the amount of time the servlet expects to be temporarily
  127.      * unavailable.  If the servlet is permanently unavailable, or no
  128.      * estimate was provided, returns a negative number.  No effort is
  129.      * made to correct for the time elapsed since the exception was
  130.      * first reported.
  131.      */
  132.     public int getUnavailableSeconds () {
  133.     return permanent ? -1 : seconds;
  134.     }
  135. }
  136.