[Swift-commit] r3836 - in trunk/src/org/griphyn/vdl: karajan/lib mapping

noreply at svn.ci.uchicago.edu noreply at svn.ci.uchicago.edu
Sun Jan 2 16:31:01 CST 2011


Author: hategan
Date: 2011-01-02 16:31:00 -0600 (Sun, 02 Jan 2011)
New Revision: 3836

Modified:
   trunk/src/org/griphyn/vdl/karajan/lib/CloseDataset.java
   trunk/src/org/griphyn/vdl/karajan/lib/SetFieldValue.java
   trunk/src/org/griphyn/vdl/karajan/lib/VDLFunction.java
   trunk/src/org/griphyn/vdl/mapping/AbstractDataNode.java
   trunk/src/org/griphyn/vdl/mapping/ArrayDataNode.java
   trunk/src/org/griphyn/vdl/mapping/Path.java
Log:
merged changes from 1.0 branch

Modified: trunk/src/org/griphyn/vdl/karajan/lib/CloseDataset.java
===================================================================
--- trunk/src/org/griphyn/vdl/karajan/lib/CloseDataset.java	2010-12-31 23:39:12 UTC (rev 3835)
+++ trunk/src/org/griphyn/vdl/karajan/lib/CloseDataset.java	2011-01-02 22:31:00 UTC (rev 3836)
@@ -6,6 +6,7 @@
 import org.apache.log4j.Logger;
 import org.globus.cog.karajan.arguments.Arg;
 import org.globus.cog.karajan.stack.VariableStack;
+import org.globus.cog.karajan.util.TypeUtil;
 import org.globus.cog.karajan.workflow.ExecutionException;
 import org.griphyn.vdl.mapping.DSHandle;
 import org.griphyn.vdl.mapping.InvalidPathException;
@@ -13,12 +14,13 @@
 
 public class CloseDataset extends VDLFunction {
 	public static final Logger logger = Logger.getLogger(CloseDataset.class);
+	
+	public static final Arg OA_CHILDREN_ONLY = new Arg.Optional("childrenOnly", Boolean.FALSE); 
 
 	static {
-		setArguments(CloseDataset.class, new Arg[] { PA_VAR, OA_PATH });
+		setArguments(CloseDataset.class, new Arg[] { PA_VAR, OA_PATH, OA_CHILDREN_ONLY });
 	}
 
-	// TODO path is not used!
 	public Object function(VariableStack stack) throws ExecutionException {
 		Path path = parsePath(OA_PATH.getValue(stack), stack);
 		DSHandle var = (DSHandle) PA_VAR.getValue(stack);
@@ -27,7 +29,13 @@
 				logger.debug("Closing " + var);
 			}
 			var = var.getField(path);
-			closeChildren(stack, var);
+			
+			if (TypeUtil.toBoolean(OA_CHILDREN_ONLY.getValue(stack))) {
+			    closeChildren(stack, var);
+			}
+			else {
+			    closeDeep(stack, var);
+			}
 		}
 		catch (InvalidPathException e) {
 			throw new ExecutionException(e);

Modified: trunk/src/org/griphyn/vdl/karajan/lib/SetFieldValue.java
===================================================================
--- trunk/src/org/griphyn/vdl/karajan/lib/SetFieldValue.java	2010-12-31 23:39:12 UTC (rev 3835)
+++ trunk/src/org/griphyn/vdl/karajan/lib/SetFieldValue.java	2011-01-02 22:31:00 UTC (rev 3836)
@@ -42,6 +42,9 @@
 				if (!value.isClosed()) {
 					throw new FutureNotYetAvailable(addFutureListener(stack, value));
 				}
+				if (var.getParent() != null && var.getParent().getType().isArray()) {
+				    markAsAvailable(stack, leaf.getParent(), leaf.getPathFromRoot().getLast());
+				}
 			}
 			synchronized (var.getRoot()) {
 				deepCopy(leaf, value, stack);

Modified: trunk/src/org/griphyn/vdl/karajan/lib/VDLFunction.java
===================================================================
--- trunk/src/org/griphyn/vdl/karajan/lib/VDLFunction.java	2010-12-31 23:39:12 UTC (rev 3835)
+++ trunk/src/org/griphyn/vdl/karajan/lib/VDLFunction.java	2011-01-02 22:31:00 UTC (rev 3836)
@@ -297,9 +297,10 @@
 			return relativize(String.valueOf(var.getValue()));
 		}
 		else {
-			PhysicalFormat f;
-			Path pathFromRoot = var.getPathFromRoot();
-			f = mapper.map(pathFromRoot);
+			if (var.getMapper() == null) {
+				throw new ExecutionException("Cannot invoke filename() on data without a mapper: " + var);
+			}
+			PhysicalFormat f = var.getMapper().map(var.getPathFromRoot());
 			if (f instanceof GeneralizedFileFormat) {
 				String filename = ((GeneralizedFileFormat) f).getURIAsString();
 				if (filename == null) {
@@ -451,8 +452,31 @@
 			markToRoot(stack, handle);
 		}
 	}
+	
+	protected void closeDeep(VariableStack stack, DSHandle handle) 
+	    throws ExecutionException, InvalidPathException {
+	    synchronized(handle.getRoot()) {
+	        closeDeep(stack, handle, getFutureWrapperMap(stack));
+	    }
+	}
 
-	private void markToRoot(VariableStack stack, DSHandle handle) throws ExecutionException {
+	private void closeDeep(VariableStack stack, DSHandle handle,
+            WrapperMap hash) throws InvalidPathException, ExecutionException {
+	    handle.closeShallow();
+	    hash.close(handle);
+	    try {
+            // Mark all leaves
+            Iterator it = handle.getFields(Path.CHILDREN).iterator();
+            while (it.hasNext()) {
+                closeDeep(stack, (DSHandle) it.next(), hash);
+            }
+        }
+        catch (HandleOpenException e) {
+            throw new ExecutionException("Handle open in closeChildren",e);
+        }
+    }
+
+    private void markToRoot(VariableStack stack, DSHandle handle) throws ExecutionException {
 		// Also mark all arrays from root
 		Path fullPath = handle.getPathFromRoot();
 		DSHandle root = handle.getRoot();

Modified: trunk/src/org/griphyn/vdl/mapping/AbstractDataNode.java
===================================================================
--- trunk/src/org/griphyn/vdl/mapping/AbstractDataNode.java	2010-12-31 23:39:12 UTC (rev 3835)
+++ trunk/src/org/griphyn/vdl/mapping/AbstractDataNode.java	2011-01-02 22:31:00 UTC (rev 3836)
@@ -550,6 +550,26 @@
         }
         return pathFromRoot;
     }
+	
+	/**
+     * Recursively closes arrays through a tree of arrays and complex types.
+     */
+    public void closeArraySizes() {
+        if (!this.closed && this.getType().isArray()) {
+            closeShallow();
+        }
+        synchronized (handles) {
+            Iterator i = handles.entrySet().iterator();
+            while (i.hasNext()) {
+                Map.Entry e = (Map.Entry) i.next();
+                AbstractDataNode child = (AbstractDataNode) e.getValue();
+                if (child.getType().isArray() ||
+                                  child.getType().getFields().size() > 0) {
+                    child.closeArraySizes();
+                }
+            }
+        }
+    }
 
     public Mapper getMapper() {
         return ((AbstractDataNode) getRoot()).getMapper();

Modified: trunk/src/org/griphyn/vdl/mapping/ArrayDataNode.java
===================================================================
--- trunk/src/org/griphyn/vdl/mapping/ArrayDataNode.java	2010-12-31 23:39:12 UTC (rev 3835)
+++ trunk/src/org/griphyn/vdl/mapping/ArrayDataNode.java	2011-01-02 22:31:00 UTC (rev 3836)
@@ -42,6 +42,24 @@
 			}
 		}
 	}
+	
+	/** Recursively closes arrays through a tree of arrays and complex
+        types. */
+    public void closeDeep() {
+        assert(this.getType().isArray());
+        if (!this.isClosed()) {
+            closeShallow();
+        }
+        Map handles = getHandles();
+        synchronized (handles) {
+            Iterator i = handles.entrySet().iterator();
+            while (i.hasNext()) {
+                Map.Entry e = (Map.Entry) i.next();
+                AbstractDataNode child = (AbstractDataNode) e.getValue();
+                child.closeDeep();
+            }
+        }
+    }
 
 	
 	public boolean isArray() {

Modified: trunk/src/org/griphyn/vdl/mapping/Path.java
===================================================================
--- trunk/src/org/griphyn/vdl/mapping/Path.java	2010-12-31 23:39:12 UTC (rev 3835)
+++ trunk/src/org/griphyn/vdl/mapping/Path.java	2011-01-02 22:31:00 UTC (rev 3836)
@@ -179,7 +179,7 @@
 	}
 	
 	public String getLast() {
-	    return ((Entry) elements.get(elements.size() - 1)).name;
+		return ((Entry) elements.get(elements.size() - 1)).name;
 	}
 
 	public boolean isEmpty() {




More information about the Swift-commit mailing list