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

noreply at svn.ci.uchicago.edu noreply at svn.ci.uchicago.edu
Fri Dec 19 10:33:32 CST 2008


Author: benc
Date: 2008-12-19 10:33:30 -0600 (Fri, 19 Dec 2008)
New Revision: 2378

Modified:
   trunk/src/org/griphyn/vdl/karajan/lib/New.java
   trunk/src/org/griphyn/vdl/karajan/lib/swiftscript/FileName.java
   trunk/src/org/griphyn/vdl/mapping/AbstractDataNode.java
   trunk/src/org/griphyn/vdl/mapping/RootArrayDataNode.java
   trunk/src/org/griphyn/vdl/mapping/RootDataNode.java
Log:
mapper initialization can now be deferred, instead of happening at dataset creation time; this means mappers can take future values as parameters

Modified: trunk/src/org/griphyn/vdl/karajan/lib/New.java
===================================================================
--- trunk/src/org/griphyn/vdl/karajan/lib/New.java	2008-12-16 23:31:36 UTC (rev 2377)
+++ trunk/src/org/griphyn/vdl/karajan/lib/New.java	2008-12-19 16:33:30 UTC (rev 2378)
@@ -123,9 +123,7 @@
 			}
 			else if (type != null) {
 				handle = new RootDataNode(type);
-				if (mapping != null) {
-					handle.init(mapping);
-				}
+				handle.init(mapping);
 				if (value != null) {
 					handle.setValue(internalValue(type, value));
 					closeShallow(stack, handle);

Modified: trunk/src/org/griphyn/vdl/karajan/lib/swiftscript/FileName.java
===================================================================
--- trunk/src/org/griphyn/vdl/karajan/lib/swiftscript/FileName.java	2008-12-16 23:31:36 UTC (rev 2377)
+++ trunk/src/org/griphyn/vdl/karajan/lib/swiftscript/FileName.java	2008-12-19 16:33:30 UTC (rev 2378)
@@ -3,6 +3,8 @@
 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.VDL2FutureException;
 import org.griphyn.vdl.karajan.lib.VDLFunction;
 import org.griphyn.vdl.mapping.RootDataNode;
 import org.griphyn.vdl.type.Types;
@@ -13,7 +15,11 @@
 	}
 
 	public Object function(VariableStack stack) throws ExecutionException {
-		String s = argList(filename(stack), true);
-		return RootDataNode.newNode(Types.STRING, s);
+		try {
+			String s = argList(filename(stack), true);
+			return RootDataNode.newNode(Types.STRING, s);
+		} catch(VDL2FutureException ve) {
+			throw new FutureNotYetAvailable(addFutureListener(stack, ve.getHandle()));
+		}
 	}
 }

Modified: trunk/src/org/griphyn/vdl/mapping/AbstractDataNode.java
===================================================================
--- trunk/src/org/griphyn/vdl/mapping/AbstractDataNode.java	2008-12-16 23:31:36 UTC (rev 2377)
+++ trunk/src/org/griphyn/vdl/mapping/AbstractDataNode.java	2008-12-19 16:33:30 UTC (rev 2378)
@@ -18,6 +18,8 @@
 import org.griphyn.vdl.type.Type;
 import org.griphyn.vdl.type.Types;
 
+import org.griphyn.vdl.karajan.VDL2FutureException;
+
 public abstract class AbstractDataNode implements DSHandle {
 
 	static final String DATASET_URI_PREFIX = "tag:benc at ci.uchicago.edu,2008:swift:dataset:";
@@ -348,7 +350,11 @@
 		notifyListeners();
 		logger.info("closed "+this.getIdentifier());
 // so because its closed, we can dump the contents
-		logContent();
+		try {
+			logContent();
+		} catch(Exception e) {
+			logger.warn("Exception whilst logging dataset content for "+this,e);
+		}
 // TODO record retrospective provenance information for this dataset here
 // we should do it at closing time because that's the point at which we
 // know the dataset has its values (all the way down the tree) assigned.
@@ -368,15 +374,23 @@
 			if(this.getType().isPrimitive()) {
 				logger.info("VALUE dataset="+this.getIdentifier()+" VALUE="+this.toString());
 			}
-			if(this.getMapper() != null) {
+
+			Mapper m;
+
+			try {
+				m = this.getMapper();
+			} catch(VDL2FutureException fe) {
+				m = null; // no mapping info if mapper isn't initialised yet
+			}
+			if(m != null) {
 // TODO proper type here
 // Not sure catching exception here is really the right thing to do here
 // anyway - should perhaps only be trying to map leafnodes? Mapping
 // non-leaf stuff is giving wierd paths anyway
 				try {
-					Object path=this.getMapper().map(this.getPathFromRoot());
+					Object path=m.map(this.getPathFromRoot());
 					logger.info("FILENAME dataset="+this.getIdentifier()+" filename="+
-						this.getMapper().map(this.getPathFromRoot()));
+						m.map(this.getPathFromRoot()));
 				} catch(Exception e) {
 					logger.info("dataset "+this.getIdentifier()+" exception while mapping path from root",e);
 				}
@@ -435,7 +449,8 @@
 
 	public synchronized void addListener(DSHandleListener listener) {
 		if (logger.isInfoEnabled()) {
-			logger.info("Adding handle listener \"" + listener + "\" to \"" + this + "\"");
+Exception e = new Exception("To get stack trace");
+			logger.info("Adding handle listener \"" + listener + "\" to \"" + this + "\"", e);
 		}
 		if (listeners == null) {
 			listeners = new LinkedList();

Modified: trunk/src/org/griphyn/vdl/mapping/RootArrayDataNode.java
===================================================================
--- trunk/src/org/griphyn/vdl/mapping/RootArrayDataNode.java	2008-12-16 23:31:36 UTC (rev 2377)
+++ trunk/src/org/griphyn/vdl/mapping/RootArrayDataNode.java	2008-12-19 16:33:30 UTC (rev 2378)
@@ -1,6 +1,7 @@
 package org.griphyn.vdl.mapping;
 
 import java.util.Map;
+import java.util.Iterator;
 
 import org.griphyn.vdl.karajan.VDL2FutureException;
 import org.griphyn.vdl.type.Field;
@@ -8,6 +9,7 @@
 
 public class RootArrayDataNode extends ArrayDataNode implements DSHandleListener {
 
+	private boolean initialized=false;
 	private Mapper mapper;
 	private Map params;
 
@@ -21,18 +23,40 @@
 
 	public void init(Map params) {
 		this.params = params;
+		if(this.params == null) {
+			initialized();
+		} else {
+			innerInit();
+		}
+	}
+
+	private void innerInit() {
+		Iterator i = params.entrySet().iterator();
+		while(i.hasNext()) {
+			Map.Entry entry = (Map.Entry) i.next();
+			Object k = entry.getKey();
+			Object v = entry.getValue();
+			if(v instanceof DSHandle && !( (DSHandle)v).isClosed()) {
+				DSHandle dh = (DSHandle)v;
+				dh.addListener(this);
+				return;
+			}
+		}
 		String desc = (String) params.get("descriptor");
 		if (desc == null) {
+			initialized();
 			return;
 		}
 		try {
 			mapper = MapperFactory.getMapper(desc, params);
 			checkInputs();
 			getField().setName(PARAM_PREFIX.getStringValue(mapper));
+			initialized();
 		}
 		catch (InvalidMapperException e) {
 			throw new RuntimeException(e);
 		}
+		notifyListeners();
 	}
 
 	private void checkInputs() {
@@ -46,10 +70,11 @@
 			setValue(new MappingDependentException(this, e));
 			closeShallow();
 		}
+		initialized();
 	}
 
 	public void handleClosed(DSHandle handle) {
-		checkInputs();
+		innerInit();
 	}
 
 	public String getParam(String name) {
@@ -68,11 +93,24 @@
 	}
 
 	public Mapper getMapper() {
-		return mapper;
+		if(initialized) {
+			return mapper;
+		} else {
+			throw new VDL2FutureException(this);
+		}
 	}
 
 	public boolean isArray() {
 		return true;
 	}
 
+        public void setValue(Object value) {
+                super.setValue(value);
+                initialized();
+        }
+
+        private void initialized() {
+                initialized=true;
+        }
+
 }

Modified: trunk/src/org/griphyn/vdl/mapping/RootDataNode.java
===================================================================
--- trunk/src/org/griphyn/vdl/mapping/RootDataNode.java	2008-12-16 23:31:36 UTC (rev 2377)
+++ trunk/src/org/griphyn/vdl/mapping/RootDataNode.java	2008-12-19 16:33:30 UTC (rev 2378)
@@ -12,6 +12,7 @@
 
 public class RootDataNode extends AbstractDataNode implements DSHandleListener {
 
+	private boolean initialized=false;
 	private Mapper mapper;
 	private Map params;
 
@@ -29,18 +30,43 @@
 
 	public void init(Map params) {
 		this.params = params;
+		if(this.params == null) { 
+			initialized();
+		} else {
+			innerInit();
+		}
+	}
 
+	/** must have this.params set to the appropriate parameters before
+	    being called. */
+	private void innerInit() {
+
+		Iterator i = params.entrySet().iterator();
+		while(i.hasNext()) {
+			Map.Entry entry = (Map.Entry) i.next();
+			Object k = entry.getKey();
+			Object v = entry.getValue();
+			if(v instanceof DSHandle && !( (DSHandle)v).isClosed()) {
+				DSHandle dh = (DSHandle)v;
+				dh.addListener(this);
+				return;
+			}
+		}
 		String desc = (String) params.get("descriptor");
-		if (desc == null)
+		if (desc == null) {
+			initialized();
 			return;
+		}
 		try {
 			mapper = MapperFactory.getMapper(desc, params);
 			checkInputs();
 			getField().setName(PARAM_PREFIX.getStringValue(mapper));
+			initialized();
 		}
 		catch (InvalidMapperException e) {
-			throw new RuntimeException(e);
+			throw new RuntimeException("InvalidMapperException caught in mapper initialization", e);
 		}
+		notifyListeners();
 	}
 
 	private void checkInputs() {
@@ -48,20 +74,23 @@
 			checkInputs(params, mapper, this);
 		}
 		catch (VDL2FutureException e) {
-			e.printStackTrace();
-			e.getHandle().addListener(this);
+			logger.warn("Unexpected VDL2FutureException checking inputs");
+			throw new RuntimeException("Got a VDL2FutureException but all parameters should have their values",e);
 		}
 		catch (DependentException e) {
 			setValue(new MappingDependentException(this, e));
 			closeShallow();
+			return;
 		}
+		initialized();
 	}
 
 	public void handleClosed(DSHandle handle) {
-		checkInputs();
+		innerInit();
 	}
 
-	public static void checkInputs(Map params, Mapper mapper, AbstractDataNode root) {
+
+	static protected void checkInputs(Map params, Mapper mapper, AbstractDataNode root) {
 		String input = (String) params.get("input");
 		if (input != null && Boolean.valueOf(input.trim()).booleanValue()) {
 			Iterator i = mapper.existing().iterator();
@@ -167,11 +196,26 @@
 		return null;
 	}
 
+
+
 	public Mapper getMapper() {
-		return mapper;
+		if(initialized) {
+			return mapper;
+		} else {
+			throw new VDL2FutureException(this);
+		}
 	}
 
 	public boolean isArray() {
 		return false;
 	}
+
+	public void setValue(Object value) {
+		super.setValue(value);
+		initialized();
+	}
+
+	private void initialized() {
+		initialized=true;
+	}
 }




More information about the Swift-commit mailing list