|
From: <ha...@us...> - 2008-02-12 17:09:17
|
Revision: 1884
http://cogkit.svn.sourceforge.net/cogkit/?rev=1884&view=rev
Author: hategan
Date: 2008-02-12 09:09:13 -0800 (Tue, 12 Feb 2008)
Log Message:
-----------
ensure proper ordering of events, and that all events are reported (even if by guessing)
Modified Paths:
--------------
trunk/current/src/cog/modules/abstraction-common/src/org/globus/cog/abstraction/impl/common/task/TaskImpl.java
Added Paths:
-----------
trunk/current/src/cog/modules/abstraction-common/src/org/globus/cog/abstraction/impl/common/task/StatusOrder.java
Added: trunk/current/src/cog/modules/abstraction-common/src/org/globus/cog/abstraction/impl/common/task/StatusOrder.java
===================================================================
--- trunk/current/src/cog/modules/abstraction-common/src/org/globus/cog/abstraction/impl/common/task/StatusOrder.java (rev 0)
+++ trunk/current/src/cog/modules/abstraction-common/src/org/globus/cog/abstraction/impl/common/task/StatusOrder.java 2008-02-12 17:09:13 UTC (rev 1884)
@@ -0,0 +1,53 @@
+//----------------------------------------------------------------------
+//This code is developed as part of the Java CoG Kit project
+//The terms of the license can be found at http://www.cogkit.org/license
+//This message may not be removed or altered.
+//----------------------------------------------------------------------
+
+/*
+ * Created on Feb 11, 2008
+ */
+package org.globus.cog.abstraction.impl.common.task;
+
+import org.globus.cog.abstraction.interfaces.Status;
+
+public class StatusOrder {
+
+ /**
+ * Returns the predecessor of a status code or -1 if the code
+ * does not have one
+ */
+ public static int pred(int code) {
+ switch (code) {
+ case Status.CANCELED:
+ case Status.FAILED:
+ case Status.COMPLETED:
+ return Status.ACTIVE;
+ case Status.SUBMITTING:
+ return Status.UNSUBMITTED;
+ case Status.SUBMITTED:
+ return Status.SUBMITTING;
+ case Status.ACTIVE:
+ return Status.SUBMITTED;
+ case Status.RESUMED:
+ return Status.SUSPENDED;
+ default:
+ return -1;
+ }
+ }
+
+ /**
+ * Returns true code1 is greater than code2 in the status
+ * order. The two need not be comparable (in which case false
+ * will be returned).
+ */
+ public static boolean greaterThan(int code1, int code2) {
+ int prev = pred(code1);
+ if (prev == -1) {
+ return false;
+ }
+ else {
+ return prev == code2 || greaterThan(prev, code2);
+ }
+ }
+}
Modified: trunk/current/src/cog/modules/abstraction-common/src/org/globus/cog/abstraction/impl/common/task/TaskImpl.java
===================================================================
--- trunk/current/src/cog/modules/abstraction-common/src/org/globus/cog/abstraction/impl/common/task/TaskImpl.java 2008-02-12 17:04:05 UTC (rev 1883)
+++ trunk/current/src/cog/modules/abstraction-common/src/org/globus/cog/abstraction/impl/common/task/TaskImpl.java 2008-02-12 17:09:13 UTC (rev 1884)
@@ -8,11 +8,10 @@
import java.io.File;
import java.util.ArrayList;
-import java.util.Calendar;
import java.util.Collection;
-import java.util.Enumeration;
-import java.util.Hashtable;
+import java.util.HashMap;
import java.util.Iterator;
+import java.util.Map;
import org.apache.log4j.Logger;
import org.globus.cog.abstraction.impl.common.IdentityImpl;
@@ -46,17 +45,16 @@
private CopyOnWriteHashSet statusListeners, outputListeners;
- private Hashtable attributes = null;
- private Calendar submittedTime = null;
- private Calendar completedTime = null;
- private ArrayList serviceList = null;
+ private Map attributes;
+
+ private ArrayList serviceList;
private int requiredServices = 0;
private boolean anythingWaiting;
public TaskImpl() {
this.id = new IdentityImpl();
- this.attributes = new Hashtable();
+ this.attributes = new HashMap();
this.serviceList = new ArrayList();
this.status = new StatusImpl();
statusListeners = new CopyOnWriteHashSet();
@@ -196,19 +194,39 @@
}
public void setStatus(Status status) {
- if (logger.isDebugEnabled()) {
- logger.debug(this + " setting status to " + status);
+ int next = status.getStatusCode();
+ int pred = StatusOrder.pred(next);
+ boolean missing = false;
+ boolean discard = false;
+ synchronized (this) {
+ int crt = this.status.getStatusCode();
+ if (StatusOrder.greaterThan(crt, next) || crt == next) {
+ // discard late arrivals
+ discard = true;
+ }
+ else if (pred != crt && pred != -1) {
+ missing = true;
+ }
}
- this.status = status;
-
- if (this.status.getStatusCode() == Status.SUBMITTED) {
- this.submittedTime = this.status.getTime();
+ if (missing) {
+ setStatus(pred);
}
- else if (this.status.getStatusCode() == Status.COMPLETED) {
- this.completedTime = this.status.getTime();
+ if (!discard) {
+ // not much choice left
+ if (logger.isDebugEnabled()) {
+ logger.debug(this + " setting status to " + status);
+ }
+ synchronized(this) {
+ this.status = status;
+ }
+ notifyListeners(status);
}
+ // Now prove that this works correctly with concurrent updates.
+ // I will pay $20 for the first one.
+ }
- StatusEvent event = new StatusEvent(this, this.status);
+ protected void notifyListeners(Status status) {
+ StatusEvent event = new StatusEvent(this, status);
Iterator i = statusListeners.iterator();
try {
while (i.hasNext()) {
@@ -245,8 +263,8 @@
return this.attributes.get(name.toLowerCase());
}
- public Enumeration getAllAttributes() {
- return this.attributes.keys();
+ public Collection getAttributeNames() {
+ return this.attributes.keySet();
}
public void addStatusListener(StatusListener listener) {
@@ -272,14 +290,19 @@
public String toString() {
return "Task(type=" + typeString(type) + ", identity=" + id + ")";
}
-
+
public static String typeString(int type) {
switch (type) {
- case JOB_SUBMISSION: return "JOB_SUBMISSION";
- case FILE_TRANSFER: return "FILE_TRANSFER";
- case FILE_OPERATION: return "FILE_OPERATION";
- case INFORMATION_QUERY: return "INFORMATION_QUERY";
- default: return "UNKNOWN";
+ case JOB_SUBMISSION:
+ return "JOB_SUBMISSION";
+ case FILE_TRANSFER:
+ return "FILE_TRANSFER";
+ case FILE_OPERATION:
+ return "FILE_OPERATION";
+ case INFORMATION_QUERY:
+ return "INFORMATION_QUERY";
+ default:
+ return "UNKNOWN";
}
}
@@ -307,14 +330,6 @@
return (this.status.getStatusCode() == Status.CANCELED);
}
- public Calendar getSubmittedTime() {
- return this.submittedTime;
- }
-
- public Calendar getCompletedTime() {
- return this.completedTime;
- }
-
public boolean equals(Object object) {
return this.id.equals(((ExecutableObject) object).getIdentity());
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|