001: /*
002: * <copyright>
003: *
004: * Copyright 2002-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: package org.cougaar.core.examples.mobility.ldm;
027:
028: import java.io.Serializable;
029:
030: import org.cougaar.core.mobility.ldm.MoveAgent;
031:
032: /**
033: * Mutable status of step processing.
034: */
035: public final class StepStatus implements Serializable {
036:
037: /**
038: * State constants.
039: */
040: public static final int UNSEEN = 0;
041: public static final int PAUSED = 1;
042: public static final int RUNNING = 2;
043: public static final int SUCCESS = 3;
044: public static final int FAILURE = 4;
045: public static final int TIMEOUT = 5;
046:
047: /**
048: * Dummy results for use instead of null, to indicate
049: * that there are no current results.
050: */
051: public static final StepStatus NONE = new StepStatus(UNSEEN, -1,
052: -1, null);
053:
054: // ticket id?
055:
056: private final int state;
057: private final long startTime;
058: private final long endTime;
059: private final MoveAgent.Status moveStatus;
060:
061: public StepStatus(int state, long startTime, long endTime,
062: MoveAgent.Status moveStatus) {
063: this .state = state;
064: this .startTime = startTime;
065: this .endTime = endTime;
066: this .moveStatus = moveStatus;
067: }
068:
069: /**
070: * Get the state code (RUNNING, TIMEOUT, etc).
071: */
072: public int getState() {
073: return state;
074: }
075:
076: /**
077: * Get a String representation of the state code.
078: */
079: public String getStateAsString() {
080: switch (state) {
081: case UNSEEN:
082: return "UNSEEN";
083: case PAUSED:
084: return "PAUSED";
085: case RUNNING:
086: return "RUNNING";
087: case SUCCESS:
088: return "SUCCESS";
089: case FAILURE:
090: return "FAILURE";
091: case TIMEOUT:
092: return "TIMEOUT";
093: default:
094: return "UNKNOWN(" + state + ")";
095: }
096: }
097:
098: /**
099: * If the state is {RUNNING, SUCCESS, FAILURE, or TIMEOUT},
100: * get the time in milliseconds when the run started,
101: * otherwise -1 is returned.
102: */
103: public long getStartTime() {
104: return startTime;
105: }
106:
107: /**
108: * If the state is {SUCCESS, FAILURE, or TIMEOUT}, get the
109: * time in milliseconds when the run started, otherwise -1
110: * is returned.
111: */
112: public long getEndTime() {
113: return endTime;
114: }
115:
116: /**
117: * If the state is {SUCCESS or FAILURE}, get the
118: * move status if available.
119: */
120: public MoveAgent.Status getMoveStatus() {
121: return moveStatus;
122: }
123:
124: public boolean equals(Object o) {
125: if (o == this ) {
126: return true;
127: } else if (!(o instanceof StepStatus)) {
128: return false;
129: } else {
130: StepStatus ss = (StepStatus) o;
131: return (state == ss.state)
132: && (startTime == ss.startTime)
133: && (endTime == ss.endTime)
134: && ((moveStatus != null) ? (moveStatus
135: .equals(ss.moveStatus))
136: : (ss.moveStatus == null));
137: }
138: }
139:
140: public int hashCode() {
141: return ((int) startTime);
142: }
143:
144: public String toString() {
145: return "status {" + "\n state: " + getStateAsString()
146: + "\n start: " + startTime + "\n end: "
147: + endTime + "\n move status: " + moveStatus + "\n}";
148: }
149: }
|