[Swift-commit] r4527 - in trunk/src/org/griphyn/vdl/mapping: . file

hategan at ci.uchicago.edu hategan at ci.uchicago.edu
Wed May 25 14:55:12 CDT 2011


Author: hategan
Date: 2011-05-25 14:55:12 -0500 (Wed, 25 May 2011)
New Revision: 4527

Modified:
   trunk/src/org/griphyn/vdl/mapping/AbstractMapper.java
   trunk/src/org/griphyn/vdl/mapping/Mapper.java
   trunk/src/org/griphyn/vdl/mapping/file/ExternalMapper.java
Log:
generics and logging messages to trace external mapper parameters and output

Modified: trunk/src/org/griphyn/vdl/mapping/AbstractMapper.java
===================================================================
--- trunk/src/org/griphyn/vdl/mapping/AbstractMapper.java	2011-05-25 18:20:22 UTC (rev 4526)
+++ trunk/src/org/griphyn/vdl/mapping/AbstractMapper.java	2011-05-25 19:55:12 UTC (rev 4527)
@@ -15,11 +15,11 @@
 
 	public static final Logger logger = Logger.getLogger(AbstractMapper.class);
 	public static final MappingParam PARAM_INPUT = new MappingParam("input", Boolean.FALSE);
-	protected Map params;
+	protected Map<String, Object> params;
 
 	public synchronized void setParam(String name, Object value) {
 		if (params == null) {
-			params = new HashMap();
+			params = new HashMap<String, Object>();
 		}
 		params.put(name, value);
 	}
@@ -33,7 +33,7 @@
 		}
 	}
 
-	public void setParams(Map params) {
+	public void setParams(Map<String, Object> params) {
 		this.params = params;
 	}
 

Modified: trunk/src/org/griphyn/vdl/mapping/Mapper.java
===================================================================
--- trunk/src/org/griphyn/vdl/mapping/Mapper.java	2011-05-25 18:20:22 UTC (rev 4526)
+++ trunk/src/org/griphyn/vdl/mapping/Mapper.java	2011-05-25 19:55:12 UTC (rev 4527)
@@ -20,7 +20,7 @@
         entry is a Path object. The data files mapped to each Path object
         do not necessarily have to exist.
      */
-    Collection existing();
+    Collection<Path> existing();
 
     /**
      * Returns true if data mapped by this mapper cannot
@@ -38,7 +38,7 @@
      */
     boolean isStatic();
 
-    void setParams(Map params);
+    void setParams(Map<String, Object> params);
 
     void setParam(String name, Object value);
 

Modified: trunk/src/org/griphyn/vdl/mapping/file/ExternalMapper.java
===================================================================
--- trunk/src/org/griphyn/vdl/mapping/file/ExternalMapper.java	2011-05-25 18:20:22 UTC (rev 4526)
+++ trunk/src/org/griphyn/vdl/mapping/file/ExternalMapper.java	2011-05-25 19:55:12 UTC (rev 4527)
@@ -9,7 +9,6 @@
 import java.util.Collection;
 import java.util.HashMap;
 import java.util.HashSet;
-import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -24,15 +23,16 @@
 public class ExternalMapper extends AbstractMapper {
 	public static final Logger logger = Logger.getLogger(ExternalMapper.class);
 
-	private Map map, rmap = new HashMap();
+	private Map<Path, AbsFile> map;
+	private Map<String, Path> rmap;
 
 	public static final MappingParam PARAM_EXEC = new MappingParam("exec");
 	public static final MappingParam PARAM_BASEDIR = new MappingParam("#basedir", null);
 
-	private static Set ignored;
+	private static Set<String> ignored;
 
 	static {
-		ignored = new HashSet();
+		ignored = new HashSet<String>();
 		ignored.add("exec");
 		ignored.add("input");
 		ignored.add("dbgname");
@@ -44,21 +44,18 @@
 
 	private static final String[] STRING_ARRAY = new String[0];
 
-	public void setParams(Map params) {
+	public void setParams(Map<String, Object> params) {
 		super.setParams(params);
-		map = new HashMap();
-		rmap = new HashMap();
+		map = new HashMap<Path, AbsFile>();
+		rmap = new HashMap<String, Path>();
 		String exec = PARAM_EXEC.getStringValue(this);
 		String bdir = PARAM_BASEDIR.getStringValue(this);
 		if (bdir != null && !exec.startsWith("/")) {
 			exec = bdir + File.separator + exec;
 		}
-		List cmd = new ArrayList();
+		List<String> cmd = new ArrayList<String>();
 		cmd.add(exec);
-		Iterator i = params.entrySet().iterator();
-		while (i.hasNext()) {
-			Map.Entry e = (Map.Entry) i.next();
-			String name = e.getKey().toString();
+		for (String name : params.keySet()) {
 			if (!ignored.contains(name)) {
 				MappingParam tp = new MappingParam(name);
 				cmd.add('-' + name);
@@ -66,8 +63,14 @@
 			}
 		}
 		try {
-			Process p = Runtime.getRuntime().exec((String[]) cmd.toArray(STRING_ARRAY));
-			List lines = fetchOutput(p.getInputStream());
+		    if (logger.isDebugEnabled()) {
+		        logger.debug("invoking external mapper for " + getParam("dbgname") + ": " + cmd);
+		    }
+			Process p = Runtime.getRuntime().exec(cmd.toArray(STRING_ARRAY));
+			List<String> lines = fetchOutput(p.getInputStream());
+			if (logger.isDebugEnabled()) {
+			    logger.debug("external mapper for " + getParam("dbgname") + " output: " + lines);
+			}
 			int ec = p.waitFor();
 			if (ec != 0) {
 				throw new RuntimeException("External executable failed. Exit code: " + ec + "\n\t"
@@ -83,19 +86,18 @@
 		}
 	}
 
-	private String join(List l) {
+	private String join(List<?> l) {
 		StringBuffer sb = new StringBuffer();
-		Iterator i = l.iterator();
-		while (i.hasNext()) {
-			sb.append(i.next());
+		for (Object o : l) {
+			sb.append(o);
 			sb.append('\n');
 			sb.append('\t');
 		}
 		return sb.toString();
 	}
 
-	private List fetchOutput(InputStream is) throws IOException {
-		ArrayList lines = new ArrayList();
+	private List<String> fetchOutput(InputStream is) throws IOException {
+		ArrayList<String> lines = new ArrayList<String>();
 		BufferedReader br = new BufferedReader(new InputStreamReader(is));
 		String line = br.readLine();
 		while (line != null) {
@@ -105,10 +107,8 @@
 		return lines;
 	}
 
-	private void processLines(List lines) {
-		Iterator i = lines.iterator();
-		while (i.hasNext()) {
-			String line = (String) i.next();
+	private void processLines(List<String> lines) {
+		for (String line : lines) {
 			int s = line.indexOf(' ');
 			int t = line.indexOf('\t');
 			int m = Math.min(s == -1 ? t : s, t == -1 ? s : t);
@@ -123,7 +123,7 @@
 		}
 	}
 
-	public Collection existing() {
+	public Collection<Path> existing() {
 		return map.keySet();
 	}
 
@@ -131,11 +131,11 @@
 		if (name == null || name.equals("")) {
 			return null;
 		}
-		return (Path) rmap.get(name);
+		return rmap.get(name);
 	}
 
 	public PhysicalFormat map(Path path) {
-		return (AbsFile) map.get(path);
+		return map.get(path);
 	}
 
 	public boolean isStatic() {




More information about the Swift-commit mailing list