[Swift-commit] r2090 - in trunk: libexec src/org/griphyn/vdl/karajan/lib

noreply at svn.ci.uchicago.edu noreply at svn.ci.uchicago.edu
Mon Jul 7 11:18:00 CDT 2008


Author: benc
Date: 2008-07-07 11:17:57 -0500 (Mon, 07 Jul 2008)
New Revision: 2090

Added:
   trunk/src/org/griphyn/vdl/karajan/lib/WaitFieldValue.java
Modified:
   trunk/libexec/vdl-lib.xml
   trunk/libexec/vdl.k
Log:
WaitFieldValue helper

Modified: trunk/libexec/vdl-lib.xml
===================================================================
--- trunk/libexec/vdl-lib.xml	2008-07-07 12:39:21 UTC (rev 2089)
+++ trunk/libexec/vdl-lib.xml	2008-07-07 16:17:57 UTC (rev 2090)
@@ -45,6 +45,7 @@
 	<export name="getFieldSubscript"><elementDef classname="org.griphyn.vdl.karajan.lib.GetFieldSubscript"/></export>
 	<export name="setFieldValue"><elementDef classname="org.griphyn.vdl.karajan.lib.SetFieldValue"/></export>
 	<export name="getFieldValue"><elementDef classname="org.griphyn.vdl.karajan.lib.GetFieldValue"/></export>
+	<export name="waitFieldValue"><elementDef classname="org.griphyn.vdl.karajan.lib.WaitFieldValue"/></export>
 	<export name="isFileBound"><elementDef classname="org.griphyn.vdl.karajan.lib.IsFileBound"/></export>
 	<export name="fileSet"><elementDef classname="org.griphyn.vdl.karajan.lib.FileSet"/></export>
 	<export name="fringePaths"><elementDef classname="org.griphyn.vdl.karajan.lib.FringePaths"/></export>

Modified: trunk/libexec/vdl.k
===================================================================
--- trunk/libexec/vdl.k	2008-07-07 12:39:21 UTC (rev 2089)
+++ trunk/libexec/vdl.k	2008-07-07 16:17:57 UTC (rev 2090)
@@ -59,7 +59,7 @@
 						fp := vdl:fringePaths(var)
 						try (
 							for(path, fp
-								discard(vdl:getFieldValue(path=path, var))
+								vdl:waitFieldValue(path=path, var)
 							)
 							catch(".*errors in data dependencies.*"
 								log(LOG:DEBUG, exception)
@@ -80,7 +80,7 @@
 				)
 				else(
 					//we still wait until the primitive value is there
-					discard(vdl:getFieldValue(var))
+					vdl:waitFieldValue(var)
 				)
 			)
 		)

Added: trunk/src/org/griphyn/vdl/karajan/lib/WaitFieldValue.java
===================================================================
--- trunk/src/org/griphyn/vdl/karajan/lib/WaitFieldValue.java	                        (rev 0)
+++ trunk/src/org/griphyn/vdl/karajan/lib/WaitFieldValue.java	2008-07-07 16:17:57 UTC (rev 2090)
@@ -0,0 +1,57 @@
+package org.griphyn.vdl.karajan.lib;
+
+import java.util.Map;
+
+import org.apache.log4j.Logger;
+import org.globus.cog.karajan.arguments.Arg;
+import org.globus.cog.karajan.stack.VariableStack;
+import org.globus.cog.karajan.workflow.ExecutionException;
+import org.globus.cog.karajan.workflow.futures.FutureNotYetAvailable;
+import org.griphyn.vdl.karajan.PairIterator;
+import org.griphyn.vdl.mapping.DSHandle;
+import org.griphyn.vdl.mapping.HandleOpenException;
+import org.griphyn.vdl.mapping.InvalidPathException;
+import org.griphyn.vdl.mapping.Path;
+
+public class WaitFieldValue extends VDLFunction {
+	public static final Logger logger = Logger.getLogger(WaitFieldValue.class);
+
+	static {
+		setArguments(WaitFieldValue.class, new Arg[] { PA_VAR, OA_PATH });
+	}
+
+	/**
+	 * Takes a supplied variable and path, and returns the unique value at that
+	 * path. Path can contain wildcards, in which case an array is returned.
+	 */
+	public Object function(VariableStack stack) throws ExecutionException {
+		Object var1 = PA_VAR.getValue(stack);
+		if (!(var1 instanceof DSHandle)) {
+			throw new RuntimeException("Can only wait for DSHandles - was supplied "+var1.getClass());
+		}
+		DSHandle var = (DSHandle) var1;
+		try {
+			Path path = parsePath(OA_PATH.getValue(stack), stack);
+			var = var.getField(path);
+			synchronized (var) {
+				if (!var.isClosed()) {
+					logger.debug("Waiting for " + var);
+					throw new FutureNotYetAvailable(addFutureListener(stack, var));
+				}
+				else {
+					Object v = var.getValue();
+					logger.debug("Do not need to wait for " + var+" as it is closed and has value "+v + (v!=null ? " with class "+v.getClass() : "" ));
+					if(v !=null && v instanceof RuntimeException) {
+						throw (RuntimeException)v;
+					} else {
+						return null;
+					}
+				}
+			}
+		}
+		catch (InvalidPathException e) {
+			throw new ExecutionException(e);
+		}
+	}
+
+}




More information about the Swift-commit mailing list