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: package org.cougaar.glm.execution.eg;
027:
028: import org.cougaar.planning.ldm.plan.AspectType;
029: import org.cougaar.core.util.UID;
030: import java.io.IOException;
031: import org.cougaar.glm.ldm.plan.AlpineAspectType;
032: import org.cougaar.glm.execution.common.*;
033:
034: public class TimedTaskEventReport extends Timed {
035: public TaskEventReport theTaskEventReport;
036: public TaskEventReport theOriginalTaskEventReport;
037: public String theSource;
038: public EventGroup theEventGroup = null;
039:
040: private TaskEventReportManager theTaskEventReportManager;
041:
042: public static Object getKey(String aSource,
043: TaskEventReport aTaskEventReport) {
044: return aTaskEventReport.theTaskEventId;
045: }
046:
047: public Object getKey() {
048: return getKey(theSource, theTaskEventReport);
049: }
050:
051: protected int compareToTieBreaker(Timed o) {
052: if (o == this )
053: return 0;
054: TimedTaskEventReport that = (TimedTaskEventReport) o;
055: int diff;
056: if (this .theEventGroup != that.theEventGroup) {
057: if (this .theEventGroup == null)
058: return 1;
059: if (that.theEventGroup == null)
060: return -1;
061: diff = this .theEventGroup.theGroupId
062: .compareTo(that.theEventGroup.theGroupId);
063: if (diff != 0)
064: return diff;
065: }
066: diff = theTaskEventReport.theTaskEventId
067: .compareTo(that.theTaskEventReport.theTaskEventId);
068: if (diff != 0)
069: return diff;
070: throw new IllegalArgumentException(
071: "Different tter having equal keys");
072: // return super.compareToTieBreaker(o);
073: }
074:
075: public static String checkAspectTypeString(String pattern) {
076: for (int aspectType = 0; aspectType <= AlpineAspectType.LAST_ALPINE_ASPECT; aspectType++) {
077: String aspectString = AlpineAspectType
078: .aspectTypeToString(aspectType);
079: if (pattern.equals(aspectString)) {
080: return aspectString;
081: }
082: }
083: try {
084: return "" + Integer.parseInt(pattern);
085: } catch (RuntimeException re) {
086: return null;
087: }
088: }
089:
090: public TimedTaskEventReport(String aSource,
091: TaskEventReport aTaskEventReport,
092: TaskEventReportManager aTaskEventReportManager) {
093: theTaskEventReportManager = aTaskEventReportManager;
094: theSource = aSource.intern();
095: theTaskEventReport = aTaskEventReport;
096: setEnabled(false);
097: }
098:
099: public String getAspectTypeString() {
100: return AlpineAspectType
101: .aspectTypeToString(theTaskEventReport.theTaskEventId.theAspectType);
102: }
103:
104: /**
105: **/
106: public boolean expired(long time) {
107: try {
108: theTaskEventReportManager.sendTaskEventReport(theSource,
109: theTaskEventReport);
110: } catch (IOException ioe) {
111: ioe.printStackTrace();
112: }
113: return true; // Expired
114: }
115:
116: public long getTime() {
117: return theTaskEventReport.theReceivedDate;
118: }
119:
120: public String getCluster() {
121: return theSource;
122: }
123:
124: public TaskEventReport getModifiableTaskEventReport() {
125: if (theOriginalTaskEventReport == null) {
126: theOriginalTaskEventReport = new TaskEventReport(
127: theTaskEventReport);
128: }
129: return theTaskEventReport;
130: }
131: }
|