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: import java.util.ArrayList;
030: import java.util.List;
031:
032: /**
033: * An OutputBundle is a chunk of output from
034: * the remote process that is sent to the client.
035: *
036: * @see NodeEventTranslator for backwards-compatible NodeEvent
037: * support
038: */
039: public final class OutputBundle implements java.io.Serializable,
040: Cloneable, Comparable {
041:
042: private String name;
043: private long timestamp;
044: private boolean created;
045: private boolean destroyed;
046: private final List idleUpdates;
047: private final DualStreamBuffer dsb;
048:
049: // FIXME add List of flush-tokens
050:
051: public OutputBundle() {
052: this (10, 89);
053: }
054:
055: public OutputBundle(int initialIdleUpdatesSize,
056: int initialDualStreamBufferSize) {
057: if ((initialIdleUpdatesSize <= 0)
058: || (initialDualStreamBufferSize <= 0)) {
059: throw new IllegalArgumentException();
060: }
061: idleUpdates = new ArrayList(initialIdleUpdatesSize);
062: dsb = new DualStreamBuffer(initialDualStreamBufferSize);
063: }
064:
065: /**
066: * @return the name of the process that created this output.
067: */
068: public String getName() {
069: return name;
070: }
071:
072: public void setName(String name) {
073: this .name = name;
074: }
075:
076: /**
077: * @return the time (in milliseconds) when this OutputBundle
078: * was created -- note that this depends upon the
079: * creating machine's clock.
080: */
081: public long getTimeStamp() {
082: return timestamp;
083: }
084:
085: public void setTimeStamp(long timestamp) {
086: this .timestamp = timestamp;
087: }
088:
089: /**
090: * @return true if the process was created; the first (and
091: * only first) OutputBundle from the process should
092: * set this to true.
093: */
094: public boolean getCreated() {
095: return created;
096: }
097:
098: public void setCreated(boolean created) {
099: this .created = created;
100: }
101:
102: /**
103: * @return a List of "double:long" Strings, which may be
104: * empty
105: */
106: public List getIdleUpdates() {
107: return idleUpdates;
108: }
109:
110: /**
111: * @return the container of captured standard-out and
112: * standard-error
113: *
114: * @see DualStreamBuffer
115: */
116: public DualStreamBuffer getDualStreamBuffer() {
117: return dsb;
118: }
119:
120: /**
121: * @return true if the process was destroyed; the last (and
122: * only last) OutputBundle from the process should
123: * set this to true.
124: */
125: public boolean getDestroyed() {
126: return destroyed;
127: }
128:
129: public void setDestroyed(boolean destroyed) {
130: this .destroyed = destroyed;
131: }
132:
133: public Object clone() {
134: try {
135: return super .clone();
136: } catch (CloneNotSupportedException e) {
137: // never
138: throw new InternalError();
139: }
140: }
141:
142: /**
143: * @return timestamp-based ordering
144: */
145: public int compareTo(Object o) {
146: long diff = (this .timestamp - ((OutputBundle) o).timestamp);
147: return ((diff == 0) ? 0 : ((diff < 0) ? -1 : 1));
148: }
149:
150: public String toString() {
151: return "OutputBundle " + name + " at time " + timestamp;
152: }
153:
154: private static final long serialVersionUID = 161238047123987677L;
155: }
|