001: /*
002: * <copyright>
003: *
004: * Copyright 1997-2004 BBNT Solutions, LLC
005: * under sponsorship of the Defense Advanced Research Projects
006: * Agency (DARPA).
007: *
008: * You can redistribute this software and/or modify it under the
009: * terms of the Cougaar Open Source License as published on the
010: * Cougaar Open Source Website (www.cougaar.org).
011: *
012: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
013: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
014: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
015: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
016: * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
017: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
018: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
019: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
020: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
021: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
022: * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
023: *
024: * </copyright>
025: */
026:
027: package org.cougaar.tools.server;
028:
029: /**
030: * An event that occured in the Node and sent to the client via
031: * OutputListener.
032: * <p>
033: * Soon to be <b>deprecated</b> -- see NodeEventTranslator. Not
034: * deprecated yet to keep the number of developer warnings minimal.
035: */
036: public final class NodeEvent implements java.io.Serializable, Cloneable {
037:
038: //
039: // Event types:
040: //
041:
042: /** Standard output */
043: public static final int STANDARD_OUT = 0;
044:
045: /** Standard error */
046: public static final int STANDARD_ERR = 1;
047:
048: /** A "heartbeat" for the Node to see if the client is still alive */
049: public static final int HEARTBEAT = 2;
050:
051: /** The Node has been created */
052: public static final int PROCESS_CREATED = 3;
053:
054: /**
055: * A rough indicator how busy the host is.
056: * <p>
057: * The message will be a String representation of a <tt>double</tt> that
058: * is greater than zero. A small number (0.0 .. 0.5) suggests that the
059: * host is idle, and larger numbers indicate that the Node/Host is busy.
060: * <p>
061: * This will remain a vague indicator until JNI/JVM measures are
062: * more accurate!
063: */
064: public static final int IDLE_UPDATE = 4;
065:
066: /** The Node has been destroyed */
067: public static final int PROCESS_DESTROYED = 5;
068:
069: public static final int MAX_TYPE = PROCESS_DESTROYED;
070:
071: public static final String[] PREFIX = { "STANDARD_OUT",
072: "STANDARD_ERR", "HEARTBEAT", "PROCESS_CREATED",
073: "IDLE_UPDATE", "PROCESS_DESTROYED", };
074:
075: private final int type;
076: private final String msg;
077:
078: public NodeEvent(int type) {
079: this .type = type;
080: this .msg = "";
081: if ((type < 0) || (type > MAX_TYPE)) {
082: throw new IllegalArgumentException("Illegal type: " + type);
083: }
084: }
085:
086: public NodeEvent(int type, String msg) {
087: this .type = type;
088: this .msg = ((msg != null) ? msg : "");
089: if ((type < 0) || (type > MAX_TYPE)) {
090: throw new IllegalArgumentException("Illegal type: " + type);
091: }
092: }
093:
094: public int getType() {
095: return type;
096: }
097:
098: public String getMessage() {
099: return msg;
100: }
101:
102: //
103: // might add other info, e.g. timestamp
104: //
105:
106: public Object clone() {
107: try {
108: return super .clone();
109: } catch (CloneNotSupportedException e) {
110: // never
111: throw new InternalError();
112: }
113: }
114:
115: public String toString() {
116: String pf = PREFIX[type];
117: return ((!(msg.equals(""))) ? (pf + ": \"" + msg + "\"") : (pf));
118: }
119:
120: private static final long serialVersionUID = 8909182368192098122L;
121: }
|