[Swift-commit] r5847 - in trunk/src/org/griphyn/vdl: karajan karajan/lib karajan/lib/cache mapping
hategan at ci.uchicago.edu
hategan at ci.uchicago.edu
Tue Jul 17 13:42:51 CDT 2012
Author: hategan
Date: 2012-07-17 13:42:51 -0500 (Tue, 17 Jul 2012)
New Revision: 5847
Modified:
trunk/src/org/griphyn/vdl/karajan/ArrayIndexFutureList.java
trunk/src/org/griphyn/vdl/karajan/FutureTracker.java
trunk/src/org/griphyn/vdl/karajan/Monitor.java
trunk/src/org/griphyn/vdl/karajan/lib/CreateArray.java
trunk/src/org/griphyn/vdl/karajan/lib/VDLFunction.java
trunk/src/org/griphyn/vdl/karajan/lib/cache/File.java
trunk/src/org/griphyn/vdl/karajan/lib/cache/LRUFileCache.java
trunk/src/org/griphyn/vdl/mapping/AbstractDataNode.java
trunk/src/org/griphyn/vdl/mapping/ArrayDataNode.java
trunk/src/org/griphyn/vdl/mapping/RootArrayDataNode.java
trunk/src/org/griphyn/vdl/mapping/RootDataNode.java
Log:
misc merges from 0.93
Modified: trunk/src/org/griphyn/vdl/karajan/ArrayIndexFutureList.java
===================================================================
--- trunk/src/org/griphyn/vdl/karajan/ArrayIndexFutureList.java 2012-07-17 18:27:38 UTC (rev 5846)
+++ trunk/src/org/griphyn/vdl/karajan/ArrayIndexFutureList.java 2012-07-17 18:42:51 UTC (rev 5847)
@@ -39,11 +39,12 @@
import org.griphyn.vdl.mapping.ArrayDataNode;
import org.griphyn.vdl.mapping.DSHandle;
-public class ArrayIndexFutureList implements FutureList, FutureWrapper {
+public class ArrayIndexFutureList implements FutureList, FutureWrapper {
private ArrayList<Object> keys;
private Map<?, ?> values;
private List<ListenerStackPair> listeners;
private ArrayDataNode node;
+ private boolean purged;
public ArrayIndexFutureList(ArrayDataNode node, Map<?, ?> values) {
this.node = node;
@@ -69,11 +70,15 @@
}
public int available() {
- return keys.size();
+ synchronized(node) {
+ return keys.size();
+ }
}
public void addKey(Object key) {
- keys.add(key);
+ synchronized(node) {
+ keys.add(key);
+ }
notifyListeners();
}
@@ -86,10 +91,7 @@
}
public void close() {
- synchronized(node) {
- purge();
- }
- notifyListeners();
+ throw new UnsupportedOperationException("Not used here");
}
private void purge() {
@@ -97,11 +99,18 @@
allkeys.removeAll(keys);
// remaining keys must be added
keys.addAll(allkeys);
+ purged = true;
}
public boolean isClosed() {
synchronized(node) {
- return node.isClosed();
+ boolean closed = node.isClosed();
+ if (closed && !purged) {
+ // this is done here because no explicit close() is
+ // ever called on this object
+ purge();
+ }
+ return closed;
}
}
@@ -142,6 +151,7 @@
for (final ListenerStackPair lsp : l) {
WaitingThreadsMonitor.removeThread(lsp.stack);
EventBus.post(new Runnable() {
+ @Override
public void run() {
lsp.listener.futureModified(ArrayIndexFutureList.this, lsp.stack);
}
Modified: trunk/src/org/griphyn/vdl/karajan/FutureTracker.java
===================================================================
--- trunk/src/org/griphyn/vdl/karajan/FutureTracker.java 2012-07-17 18:27:38 UTC (rev 5846)
+++ trunk/src/org/griphyn/vdl/karajan/FutureTracker.java 2012-07-17 18:42:51 UTC (rev 5847)
@@ -54,4 +54,8 @@
public Map<DSHandle, Future> getMap() {
return futures;
}
+
+ public synchronized Map<DSHandle, Future> getMapSafe() {
+ return new HashMap<DSHandle, Future>(futures);
+ }
}
Modified: trunk/src/org/griphyn/vdl/karajan/Monitor.java
===================================================================
--- trunk/src/org/griphyn/vdl/karajan/Monitor.java 2012-07-17 18:27:38 UTC (rev 5846)
+++ trunk/src/org/griphyn/vdl/karajan/Monitor.java 2012-07-17 18:42:51 UTC (rev 5847)
@@ -224,7 +224,7 @@
public static void dumpVariables(PrintStream ps) {
ps.println("\nRegistered futures:");
- Map<DSHandle, Future> map = FutureTracker.get().getMap();
+ Map<DSHandle, Future> map = FutureTracker.get().getMapSafe();
Map<DSHandle, Future> copy;
synchronized (map) {
copy = new HashMap<DSHandle, Future>(map);
Modified: trunk/src/org/griphyn/vdl/karajan/lib/CreateArray.java
===================================================================
--- trunk/src/org/griphyn/vdl/karajan/lib/CreateArray.java 2012-07-17 18:27:38 UTC (rev 5846)
+++ trunk/src/org/griphyn/vdl/karajan/lib/CreateArray.java 2012-07-17 18:42:51 UTC (rev 5847)
@@ -17,17 +17,20 @@
package org.griphyn.vdl.karajan.lib;
-import java.util.Iterator;
+import java.util.Collections;
+import java.util.HashMap;
import java.util.List;
+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.FutureFault;
import org.griphyn.vdl.mapping.DSHandle;
import org.griphyn.vdl.mapping.Path;
import org.griphyn.vdl.mapping.RootArrayDataNode;
+import org.griphyn.vdl.type.Field;
import org.griphyn.vdl.type.Type;
public class CreateArray extends VDLFunction {
@@ -40,7 +43,8 @@
setArguments(CreateArray.class, new Arg[] { PA_VALUE });
}
- public Object function(VariableStack stack) throws ExecutionException {
+ @SuppressWarnings("unchecked")
+ public Object function(VariableStack stack) throws ExecutionException {
Object value = PA_VALUE.getValue(stack);
try {
@@ -49,56 +53,105 @@
"An array variable can only be initialized with a list of values");
}
- Type type = null;
+ Type type = checkTypes((List<?>) value);
+
+ DSHandle handle = new RootArrayDataNode(type.arrayType());
+ if (hasMappableFields(type)) {
+ setMapper(handle);
+ }
- Iterator i = ((List) value).iterator();
- while (i.hasNext()) {
- Object o = i.next();
- if (o instanceof DSHandle) {
- DSHandle d = (DSHandle)o;
- Type thisType = d.getType();
- if(type == null) {
- // this first element
- type = thisType;
- } else {
- // other elements, when we have a type to expect
- if(!(type.equals(thisType))) {
- throw new RuntimeException(
- "Expecting all array elements to have SwiftScript type "+type+" but found an element with type "+thisType);
- }
- }
- }
- else {
- throw new RuntimeException("An array variable can only be initialized by a list of DSHandle values.");
- }
-
+ if (logger.isInfoEnabled()) {
+ logger.info("CREATEARRAY START array=" + handle.getIdentifier());
}
- DSHandle handle = new RootArrayDataNode(type.arrayType());
-
- logger.info("CREATEARRAY START array="+handle.getIdentifier());
-
int index = 0;
- i = ((List) value).iterator();
- while (i.hasNext()) {
+ for (Object o : (List<?>) value) {
// TODO check type consistency of elements with
// the type of the array
- DSHandle n = (DSHandle) i.next();
+ DSHandle n = (DSHandle) o;
// we know this DSHandle cast will work because we checked
// it in the previous scan of the array contents
Path p = Path.EMPTY_PATH.addLast(index, true);
+
+ DSHandle dst = handle.getField(p);
- handle.getField(p).set(n);
- logger.info("CREATEARRAY MEMBER array="+handle.getIdentifier()+" index="+index+" member="+n.getIdentifier());
+ SetFieldValue.deepCopy(dst, n, stack, 1);
+
+ if (logger.isInfoEnabled()) {
+ logger.info("CREATEARRAY MEMBER array=" + handle.getIdentifier()
+ + " index=" + index + " member=" + n.getIdentifier());
+ }
index++;
}
+
handle.closeShallow();
- logger.info("CREATEARRAY COMPLETED array="+handle.getIdentifier());
+
+ if (logger.isInfoEnabled()) {
+ logger.info("CREATEARRAY COMPLETED array=" + handle.getIdentifier());
+ }
return handle;
}
+ catch (FutureFault e) {
+ throw e;
+ }
catch (Exception e) {
throw new ExecutionException(e);
}
}
+
+ private void setMapper(DSHandle handle) {
+ // slap a concurrent mapper on this
+ Map<String, Object> params = new HashMap<String, Object>();
+ params.put("descriptor", "concurrent_mapper");
+ params.put("dbgname", "arrayexpr");
+ handle.init(params);
+ }
+
+ private boolean hasMappableFields(Type type) {
+ if (type.isPrimitive()) {
+ return false;
+ }
+ else if (!type.isComposite()) {
+ return true;
+ }
+ else if (type.isArray()) {
+ return hasMappableFields(type.itemType());
+ }
+ else {
+ // struct
+ for (Field f : type.getFields()) {
+ if (hasMappableFields(f.getType())) {
+ return true;
+ }
+ }
+ return false;
+ }
+ }
+
+ private Type checkTypes(List<?> value) {
+ Type type = null;
+
+ for (Object o : value) {
+ if (o instanceof DSHandle) {
+ DSHandle d = (DSHandle)o;
+ Type thisType = d.getType();
+ if(type == null) {
+ // this first element
+ type = thisType;
+ } else {
+ // other elements, when we have a type to expect
+ if(!(type.equals(thisType))) {
+ throw new RuntimeException(
+ "Expecting all array elements to have SwiftScript type " +
+ type + " but found an element with type "+thisType);
+ }
+ }
+ }
+ else {
+ throw new RuntimeException("An array variable can only be initialized by a list of DSHandle values.");
+ }
+ }
+ return type;
+ }
}
Modified: trunk/src/org/griphyn/vdl/karajan/lib/VDLFunction.java
===================================================================
--- trunk/src/org/griphyn/vdl/karajan/lib/VDLFunction.java 2012-07-17 18:27:38 UTC (rev 5846)
+++ trunk/src/org/griphyn/vdl/karajan/lib/VDLFunction.java 2012-07-17 18:42:51 UTC (rev 5847)
@@ -214,9 +214,15 @@
private static String[] leavesFileNames(DSHandle var) throws ExecutionException, HandleOpenException {
Mapper mapper;
+
synchronized (var.getRoot()) {
mapper = var.getMapper();
}
+
+ if (mapper == null) {
+ throw new ExecutionException(var.getType() + " is not a mapped type");
+ }
+
List<String> l = new ArrayList<String>();
try {
Collection<Path> fp = var.getFringePaths();
Modified: trunk/src/org/griphyn/vdl/karajan/lib/cache/File.java
===================================================================
--- trunk/src/org/griphyn/vdl/karajan/lib/cache/File.java 2012-07-17 18:27:38 UTC (rev 5846)
+++ trunk/src/org/griphyn/vdl/karajan/lib/cache/File.java 2012-07-17 18:42:51 UTC (rev 5847)
@@ -175,7 +175,7 @@
EventBus.post(new Runnable() {
public void run() {
etp.listener.futureModified(File.this, etp.stack);
- }
+ }
});
}
}
Property changes on: trunk/src/org/griphyn/vdl/karajan/lib/cache/LRUFileCache.java
___________________________________________________________________
Deleted: svn:mergeinfo
- /branches/release-0.93/src/org/griphyn/vdl/karajan/lib/cache/LRUFileCache.java:4761-5123
Modified: trunk/src/org/griphyn/vdl/mapping/AbstractDataNode.java
===================================================================
--- trunk/src/org/griphyn/vdl/mapping/AbstractDataNode.java 2012-07-17 18:27:38 UTC (rev 5846)
+++ trunk/src/org/griphyn/vdl/mapping/AbstractDataNode.java 2012-07-17 18:42:51 UTC (rev 5847)
@@ -522,7 +522,7 @@
}
}
- protected Mapper getActualMapper() {
+ public Mapper getActualMapper() {
return null;
}
Modified: trunk/src/org/griphyn/vdl/mapping/ArrayDataNode.java
===================================================================
--- trunk/src/org/griphyn/vdl/mapping/ArrayDataNode.java 2012-07-17 18:27:38 UTC (rev 5846)
+++ trunk/src/org/griphyn/vdl/mapping/ArrayDataNode.java 2012-07-17 18:42:51 UTC (rev 5847)
@@ -91,10 +91,14 @@
}
}
- private void addKey(Comparable<?> key) {
- if (wrapper != null) {
- ((ArrayIndexFutureList) wrapper).addKey(key);
+ private void addKey(String name) {
+ ArrayIndexFutureList w;
+ synchronized(this) {
+ w = (ArrayIndexFutureList) wrapper;
}
+ if (w != null) {
+ w.addKey(name);
+ }
}
@Override
Modified: trunk/src/org/griphyn/vdl/mapping/RootArrayDataNode.java
===================================================================
--- trunk/src/org/griphyn/vdl/mapping/RootArrayDataNode.java 2012-07-17 18:27:38 UTC (rev 5846)
+++ trunk/src/org/griphyn/vdl/mapping/RootArrayDataNode.java 2012-07-17 18:42:51 UTC (rev 5847)
@@ -47,7 +47,7 @@
this.params = params;
if (this.params == null) {
initialized();
- }
+ }
else {
innerInit();
}
@@ -126,7 +126,7 @@
}
}
- protected Mapper getActualMapper() {
+ public Mapper getActualMapper() {
return mapper;
}
Modified: trunk/src/org/griphyn/vdl/mapping/RootDataNode.java
===================================================================
--- trunk/src/org/griphyn/vdl/mapping/RootDataNode.java 2012-07-17 18:27:38 UTC (rev 5846)
+++ trunk/src/org/griphyn/vdl/mapping/RootDataNode.java 2012-07-17 18:42:51 UTC (rev 5847)
@@ -216,15 +216,15 @@
if (initialized) {
return mapper;
}
- if (waitingMapperParam == null) {
- return null;
- }
- else {
- throw new FutureNotYetAvailable(waitingMapperParam.getFutureWrapper());
- }
+ if (waitingMapperParam == null) {
+ return null;
+ }
+ else {
+ throw new FutureNotYetAvailable(waitingMapperParam.getFutureWrapper());
+ }
}
- protected Mapper getActualMapper() {
+ public Mapper getActualMapper() {
return mapper;
}
More information about the Swift-commit
mailing list