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: public abstract class Timed implements Comparable {
029: private static int nextTieBreaker = 0;
030: private int tieBreaker = nextTieBreaker++;
031: private boolean enabled = false;
032: private Object annotation = null; // Annotation supplied by plugin
033:
034: protected Timed() {
035: }
036:
037: public abstract Object getKey();
038:
039: /**
040: * Return true if this item has expired and should be removed from
041: * the screen.
042: **/
043: public abstract boolean expired(long time);
044:
045: public boolean isEnabled() {
046: return enabled;
047: }
048:
049: public void setEnabled(boolean newEnabled) {
050: enabled = newEnabled;
051: }
052:
053: public abstract long getTime();
054:
055: public abstract String getCluster();
056:
057: public void setAnnotation(Object o) {
058: annotation = o;
059: }
060:
061: public Object getAnnotation() {
062: return annotation;
063: }
064:
065: public int compareTo(Object o) {
066: Timed other = (Timed) o;
067: long diff = this .getTime() - other.getTime();
068: if (diff < 0L)
069: return -1;
070: if (diff > 0L)
071: return 1;
072: return compareToTieBreaker(other);
073: }
074:
075: //Override this to use a different tie breaker
076: protected int compareToTieBreaker(Timed other) {
077: return (other.tieBreaker - this .tieBreaker);
078: }
079:
080: private String getShortClassName() {
081: String result = getClass().getName();
082: return result.substring(result.lastIndexOf('.') + 1);
083: }
084:
085: public String toString() {
086: return getShortClassName() + "@" + new EGDate(getTime());
087: }
088:
089: public static class Dummy extends Timed {
090: private long theTime = -1;
091:
092: public Dummy(long aTime) {
093: theTime = aTime;
094: }
095:
096: public Object getKey() {
097: return null;
098: }
099:
100: public long getTime() {
101: return theTime;
102: }
103:
104: public String getCluster() {
105: return "";
106: }
107:
108: public boolean expired(long aTime) {
109: theTime = aTime;
110: return true;
111: }
112: }
113: }
|