001: /**
002: * Copyright 2003 IBM Corporation and Sun Microsystems, Inc.
003: * All rights reserved.
004: * Use is subject to license terms.
005: */package javax.portlet;
006:
007: /**
008: * The portlet should throw the <CODE>UnavailableException</CODE> when
009: * the portlet is either temporarily or permanently unavailable to handle requests.
010: *
011: **/
012:
013: public class UnavailableException extends PortletException {
014:
015: private boolean permanent; // needs admin action?
016: private int seconds; // unavailability estimate
017:
018: /**
019: *
020: * Constructs a new exception with a descriptive
021: * message indicating that the portlet is permanently
022: * unavailable.
023: *
024: * @param text a <code>String</code> specifying the
025: * descriptive message
026: *
027: */
028:
029: public UnavailableException(String text) {
030: super (text);
031:
032: permanent = true;
033: }
034:
035: /**
036: * Constructs a new exception with a descriptive message
037: * indicating that the portlet is temporarily unavailable
038: * and giving an estimate of how long it will be unavailable.
039: *
040: * <p>In some cases, the portlet cannot make an estimate. For
041: * example, the portlet might know that a server it needs is
042: * not running, but it might not be able to report how long it will take
043: * to be restored to functionality. This can be indicated with
044: * a negative or zero value for the <code>seconds</code> argument.
045: *
046: * @param text a <code>String</code> specifying the
047: * descriptive message. This message can be written
048: * to a log file or displayed for the user.
049: *
050: * @param seconds an integer specifying the number of seconds
051: * for which the portlet expects to be unavailable; if
052: * this is zero or negative, it indicates that the portlet
053: * cannot make an estimate.
054: *
055: */
056:
057: public UnavailableException(String text, int seconds) {
058: super (text);
059:
060: if (seconds <= 0)
061: this .seconds = -1;
062: else
063: this .seconds = seconds;
064:
065: permanent = false;
066: }
067:
068: /**
069: *
070: * Returns a <code>boolean</code> indicating
071: * whether the portlet is permanently unavailable.
072: * If so, something is wrong with the portlet, and the
073: * system administrator must take some corrective action.
074: *
075: * @return <code>true</code> if the portlet is
076: * permanently unavailable; <code>false</code>
077: * if the portlet is temporarily
078: * unavailable.
079: *
080: */
081:
082: public boolean isPermanent() {
083: return permanent;
084: }
085:
086: /**
087: * Returns the time in seconds for which the portlet can be expected to
088: * be unavailable.
089: * <p>
090: * If the portlet is called again while it is still unavailable, it
091: * indicates the same time estimate. No effort is
092: * made to correct for the time elapsed since the exception was
093: * first reported.
094: * <p>
095: * If this method returns zero or a negative number, the portlet
096: * is permanently unavailable or cannot provide an estimate of
097: * how long it will be unavailable.
098: *
099: * @return an integer specifying the number of seconds
100: * the portlet will be temporarily unavailable,
101: * or zero or a negative number if the portlet is permanently
102: * unavailable or cannot make an estimate.
103: *
104: */
105:
106: public int getUnavailableSeconds() {
107: return permanent ? -1 : seconds;
108: }
109:
110: }
|