[Swift-commit] r6397 - branches/faster/src/org/griphyn/vdl/karajan

hategan at ci.uchicago.edu hategan at ci.uchicago.edu
Mon Mar 18 19:24:44 CDT 2013


Author: hategan
Date: 2013-03-18 19:24:44 -0500 (Mon, 18 Mar 2013)
New Revision: 6397

Removed:
   branches/faster/src/org/griphyn/vdl/karajan/FutureTracker.java
   branches/faster/src/org/griphyn/vdl/karajan/InHook.java
   branches/faster/src/org/griphyn/vdl/karajan/Monitor.java
Modified:
   branches/faster/src/org/griphyn/vdl/karajan/HangChecker.java
Log:
removed old monitor

Deleted: branches/faster/src/org/griphyn/vdl/karajan/FutureTracker.java
===================================================================
--- branches/faster/src/org/griphyn/vdl/karajan/FutureTracker.java	2013-03-18 22:10:26 UTC (rev 6396)
+++ branches/faster/src/org/griphyn/vdl/karajan/FutureTracker.java	2013-03-19 00:24:44 UTC (rev 6397)
@@ -1,57 +0,0 @@
-/*
- * Copyright 2012 University of Chicago
- * 
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * 
- * http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-
-package org.griphyn.vdl.karajan;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import k.rt.Future;
-
-import org.griphyn.vdl.mapping.DSHandle;
-
-public class FutureTracker {
-    public static final String VAR_NAME = "#swift:futureTracker";
-    
-    private static final FutureTracker ft = new FutureTracker();
-    
-    public static FutureTracker get() {
-        return ft;
-    }
-    
-    private Map<DSHandle, Future> futures;
-    
-    public FutureTracker() {
-        futures = new HashMap<DSHandle, Future>();
-    }
-
-    public synchronized void add(DSHandle h, Future f) {
-        futures.put(h, f);
-    }
-
-    public synchronized void remove(DSHandle h) {
-        futures.remove(h);
-    }
-
-    public Map<DSHandle, Future> getMap() {
-        return futures;
-    }
-    
-    public synchronized Map<DSHandle, Future> getMapSafe() {
-        return new HashMap<DSHandle, Future>(futures);
-    }
-}

Modified: branches/faster/src/org/griphyn/vdl/karajan/HangChecker.java
===================================================================
--- branches/faster/src/org/griphyn/vdl/karajan/HangChecker.java	2013-03-18 22:10:26 UTC (rev 6396)
+++ branches/faster/src/org/griphyn/vdl/karajan/HangChecker.java	2013-03-19 00:24:44 UTC (rev 6397)
@@ -18,6 +18,7 @@
 package org.griphyn.vdl.karajan;
 
 import java.io.ByteArrayOutputStream;
+import java.io.File;
 import java.io.PrintStream;
 import java.util.ArrayList;
 import java.util.Collections;
@@ -39,18 +40,21 @@
 
 import org.apache.log4j.Logger;
 import org.globus.cog.karajan.analyzer.VariableNotFoundException;
+import org.globus.cog.karajan.compiled.nodes.Node;
 import org.globus.cog.karajan.compiled.nodes.grid.SchedulerNode;
 import org.globus.cog.karajan.scheduler.WeightedHostScoreScheduler;
 import org.griphyn.vdl.mapping.DSHandle;
+import org.griphyn.vdl.mapping.MappingParam;
+import org.griphyn.vdl.mapping.Path;
 
 public class HangChecker extends TimerTask {
     public static final Logger logger = Logger.getLogger(HangChecker.class);
     
-    public static final int CHECK_INTERVAL = 10000;
+    public static final int CHECK_INTERVAL = 1000;
     public static final int MAX_CYCLES = 10;
     private Timer timer;
     private Context context;
-    private long lastSequenceNumber;
+    private long lastSequenceNumber, lastHandledSequenceNumber;
     
     public HangChecker(Context context) throws ExecutionException {
     	this.context = context;
@@ -68,16 +72,20 @@
                 lastSequenceNumber = crtSequenceNumber;
                 return;
             }
+            if (lastHandledSequenceNumber == crtSequenceNumber) {
+                // already printed info, so don't spam stdout
+                return;
+            }
             WeightedHostScoreScheduler s = (WeightedHostScoreScheduler) context.getAttribute(SchedulerNode.CONTEXT_ATTR_NAME);
             if (s != null) {
                 int running = s.getRunning();
                 boolean allOverloaded = s.allOverloaded();
                 if (running == 0 && !Scheduler.getScheduler().isAnythingRunning() && !allOverloaded) {
+                    lastHandledSequenceNumber = crtSequenceNumber;
                     logger.warn("No events in " + (CHECK_INTERVAL / 1000) + "s.");
                     ByteArrayOutputStream os = new ByteArrayOutputStream();
                     PrintStream ps = new PrintStream(os);
-                    Monitor.dumpVariables(ps);
-                    Monitor.dumpThreads(ps);
+                    dumpThreads(ps);
                     try {
                         Graph g = buildGraph();
                         if (!findCycles(ps, g)) {
@@ -97,6 +105,93 @@
         }
     }
     
+    public void dumpThreads() {
+        dumpThreads(System.out);
+    }
+
+    public static void dumpThreads(PrintStream pw) {
+        pw.println("\nWaiting threads:");
+        Map<LWThread, DSHandle> c = WaitingThreadsMonitor.getAllThreads();
+        for (Map.Entry<LWThread, DSHandle> e : c.entrySet()) {
+            dumpThread(pw, e.getKey(), e.getValue());
+            pw.println();
+        }
+        pw.println("----");
+    }
+
+    public static void dumpThread(PrintStream pw, LWThread thr, DSHandle handle) {
+        try {
+            pw.println("Thread: " + thr.getName() 
+                + (handle == null ? "" : ", waiting on " + varWithLine(handle)));
+
+            for (String t : getSwiftTrace(thr)) {
+                pw.println("\t" + t);
+            }
+        }
+        catch (VariableNotFoundException e1) {
+            pw.println("unknown thread");
+        }
+    }
+    
+    public static String varWithLine(DSHandle value) {
+        String line = value.getRoot().getParam(MappingParam.SWIFT_LINE);
+        Path path = value.getPathFromRoot();
+        return value.getRoot().getParam(MappingParam.SWIFT_DBGNAME) + 
+            (value == value.getRoot() ? "" : (path.isArrayIndex(0) ? path : "." + path)) + 
+            (line == null ? "" : " (declared on line " + line + ")");
+    }
+    
+    public static String getLastCall(LWThread thr) {
+        List<Object> trace = thr.getTrace();
+        if (trace != null) {
+            for (Object o : trace) {
+                if (o instanceof Node) {
+                    Node n = (Node) o;
+                    int line = n.getLine();
+                    return(n.getTextualName() + ", " + 
+                            fileName(n) + ", line " + line);
+                }
+            }
+        }
+        return "?";
+    }
+    
+    public static List<String> getSwiftTrace(LWThread thr) {
+        List<String> ret = new ArrayList<String>();
+        List<Object> trace = thr.getTrace();
+        if (trace != null) {
+            for (Object o : trace) {
+                if (o instanceof Node) {
+                    Node n = (Node) o;
+                    int line = n.getLine();
+                    ret.add(n.getTextualName() + ", " + 
+                            fileName(n) + ", line " + line);
+                
+                }
+            }
+        }
+        return ret;
+    }
+    
+    public static List<Object> getSwiftTraceElements(LWThread thr) {
+        List<Object> ret = new ArrayList<Object>();
+        List<Object> trace = thr.getTrace();
+        if (trace != null) {
+            for (Object o : trace) {
+                if (o instanceof Node) {
+                    Node n = (Node) o;
+                    ret.add(n.getLine());
+                }
+            }
+        }
+        return ret;
+    }
+
+    private static String fileName(Node n) {
+        return new File(n.getFileName()).getName().replace(".kml", ".swift");
+    }
+
+    
     private void findThreadsToBlame(PrintStream ps, Graph g) {
         Map<LWThread, DSHandle> wt = WaitingThreadsMonitor.getAllThreads();
         Set<LWThread> sl = g.nodeSet();
@@ -110,7 +205,7 @@
             ps.println();
             ps.println("The following threads are independently hung:");
             for (LWThread s : loners) {
-                Monitor.dumpThread(ps, s, wt.get(s));
+                dumpThread(ps, s, wt.get(s));
                 ps.println();
             }
             ps.println("----");
@@ -209,19 +304,19 @@
             for (Object o : c) {
                 if (o instanceof Stack) {
                     if (prev != null) {
-                        ps.println("\t" + Monitor.varWithLine((DSHandle) prev) + " is needed by: ");
+                        ps.println("\t" + varWithLine((DSHandle) prev) + " is needed by: ");
                     }
                     else {
                         ps.println("\tthe above must complete before the block below can complete:");
                     }
-                    for (String t : Monitor.getSwiftTrace((LWThread) o)) {
+                    for (String t : getSwiftTrace((LWThread) o)) {
                         ps.println("\t\t" + t);
                     }
                 }
                 else {
                     prev = o;
                     if (o != null) {
-                        ps.println("\twhich produces " + Monitor.varWithLine((DSHandle) o));
+                        ps.println("\twhich produces " + varWithLine((DSHandle) o));
                     }
                     ps.println();
                 }
@@ -280,8 +375,8 @@
         LWThread sa = (LWThread) a;
         LWThread sb = (LWThread) b;
         
-        List<Object> ta = Monitor.getSwiftTraceElements(sa);
-        List<Object> tb = Monitor.getSwiftTraceElements(sb);
+        List<Object> ta = getSwiftTraceElements(sa);
+        List<Object> tb = getSwiftTraceElements(sb);
         
         if (ta.size() != tb.size()) {
             return false;

Deleted: branches/faster/src/org/griphyn/vdl/karajan/InHook.java
===================================================================
--- branches/faster/src/org/griphyn/vdl/karajan/InHook.java	2013-03-18 22:10:26 UTC (rev 6396)
+++ branches/faster/src/org/griphyn/vdl/karajan/InHook.java	2013-03-19 00:24:44 UTC (rev 6397)
@@ -1,92 +0,0 @@
-/*
- * Copyright 2012 University of Chicago
- * 
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * 
- * http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-
-/*
- * Created on Jun 19, 2006
- */
-package org.griphyn.vdl.karajan;
-
-import java.io.BufferedInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-
-import org.apache.log4j.Logger;
-
-public class InHook extends InputStream implements Runnable {
-
-	public static final Logger logger = Logger.getLogger(InHook.class);
-
-	public synchronized static void install(Monitor m) {
-		if (!(System.in instanceof InHook)) {
-			System.setIn(new InHook(System.in, m));
-		}
-	}
-
-	private BufferedInputStream is;
-	private Monitor m;
-
-	private InHook(InputStream is, Monitor m) {
-		if (is instanceof BufferedInputStream) {
-			this.is = (BufferedInputStream) is;
-			this.m = m;
-			Thread t = new Thread(this, "Swift console debugger");
-			t.setDaemon(true);
-			t.start();
-		} else {
-			logger.error("Attempt to start console debugger with stdin not an instance of BufferedInputStream. InputStream class is "+is.getClass());
-		}
-	}
-
-	public int read() throws IOException {
-		return is.read();
-	}
-
-	public void run() {
-		logger.debug("Starting console debugger thread");
-		while (true) {
-			logger.debug("Console debugger outer loop");
-			try {
-				int c = is.read();
-				logger.debug("Command: "+c); // TODO display as char?
-				if (c == 'd') {
-					m.toggle();
-				}
-				else if (c == 'v') {
-					m.dumpVariables();
-				}
-				else if (c == 't') {
-					m.dumpThreads();
-				} else if (c == 10) {
-					logger.debug("Ignoring LF");
-				} else if (c == -1) {
-					logger.debug("End of stdin - exiting debugger");
-					return;
-				}
-				else {
-					logger.warn("Unknown console debugger command "+c);
-				}
-			}
-			catch (IOException e) {
-				logger.debug("Console debugger encountered IOException",e);
-				return;
-			}
-			catch (Exception e) {
-				e.printStackTrace();
-			}
-		}
-	}
-}

Deleted: branches/faster/src/org/griphyn/vdl/karajan/Monitor.java
===================================================================
--- branches/faster/src/org/griphyn/vdl/karajan/Monitor.java	2013-03-18 22:10:26 UTC (rev 6396)
+++ branches/faster/src/org/griphyn/vdl/karajan/Monitor.java	2013-03-19 00:24:44 UTC (rev 6397)
@@ -1,572 +0,0 @@
-/*
- * Copyright 2012 University of Chicago
- * 
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * 
- * http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-
-/*
- * Created on Jun 17, 2006
- */
-package org.griphyn.vdl.karajan;
-
-import java.awt.BorderLayout;
-import java.awt.Color;
-import java.awt.Dimension;
-import java.awt.FlowLayout;
-import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
-import java.awt.event.MouseEvent;
-import java.awt.event.MouseListener;
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.io.PrintStream;
-import java.net.InetAddress;
-import java.net.ServerSocket;
-import java.net.Socket;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-import javax.swing.BorderFactory;
-import javax.swing.JButton;
-import javax.swing.JFrame;
-import javax.swing.JOptionPane;
-import javax.swing.JPanel;
-import javax.swing.JScrollPane;
-import javax.swing.JTable;
-import javax.swing.table.AbstractTableModel;
-
-import k.rt.ConditionalYield;
-import k.rt.Future;
-import k.rt.FutureListener;
-import k.rt.FutureValue;
-import k.rt.Stack;
-import k.thr.LWThread;
-
-import org.globus.cog.karajan.analyzer.VariableNotFoundException;
-import org.globus.cog.karajan.compiled.nodes.Node;
-import org.griphyn.vdl.mapping.AbstractDataNode;
-import org.griphyn.vdl.mapping.ArrayDataNode;
-import org.griphyn.vdl.mapping.DSHandle;
-import org.griphyn.vdl.mapping.DependentException;
-import org.griphyn.vdl.mapping.MappingParam;
-import org.griphyn.vdl.mapping.Path;
-
-public class Monitor implements ActionListener, MouseListener {
-	public static final int VARS = 0;
-	public static final int THREADS = 1;
-	private JFrame frame;
-	private JPanel buttons, display;
-	private JTable t;
-	private JButton futures, waiting, tasks;
-	private List<Future> wr;
-	private List<LWThread> wt;
-	private int crtdisp;
-
-	public Monitor() {
-		Service s = new Service();
-		new Thread(s, "network debugger").start();
-	}
-
-	private synchronized void init() {
-		frame = new JFrame();
-		frame.setTitle("Swift Debugger");
-		buttons = new JPanel();
-		frame.getContentPane().setLayout(new BorderLayout());
-		frame.getContentPane().add(buttons, BorderLayout.NORTH);
-		display = new JPanel();
-		display.setPreferredSize(new Dimension(500, 400));
-		display.setLayout(new BorderLayout());
-		frame.getContentPane().add(display, BorderLayout.CENTER);
-
-		buttons.setLayout(new FlowLayout());
-
-		futures = new JButton("Variable dump");
-		buttons.add(futures);
-		futures.addActionListener(this);
-
-		waiting = new JButton("Waiting threads");
-		buttons.add(waiting);
-		waiting.addActionListener(this);
-
-		tasks = new JButton("Tasks");
-		buttons.add(tasks);
-		tasks.addActionListener(this);
-
-		frame.pack();
-	}
-
-	public void actionPerformed(ActionEvent e) {
-		if (e.getSource() == futures) {
-			if (t != null) {
-				t.removeMouseListener(this);
-			}
-			crtdisp = VARS;
-			ArrayList<List<Object>> al = new ArrayList<List<Object>>();
-			wr = new ArrayList<Future>();
-			Map<DSHandle, Future> map = FutureTracker.get().getMap();
-			synchronized (map) {
-			    for (Map.Entry<DSHandle, Future> en : map.entrySet()) {
-					List<Object> entry = new ArrayList<Object>();
-					Future f = en.getValue();
-					DSHandle handle = en.getKey();
-					String value = "-";
-					Object v;
-					try {
-						v = handle.getValue();
-						if (v != null) {
-							value = v.toString();
-						}
-					}
-					catch (DependentException ex) {
-						v = "<text color=\"red\">Exception</text>";
-					}
-					String h = handle.toString();
-					if (h.indexOf(' ') != -1) {
-						h = h.substring(0, h.indexOf(' '));
-					}
-					String sz = "-";
-					if (handle.getType().isArray()) {
-						if (handle instanceof ArrayDataNode) {
-							sz = String.valueOf(((ArrayDataNode) handle).size());
-						}
-						else{
-							sz = "unknown";
-						}
-					}
-					entry.add(handle.getType());
-					entry.add(h);
-					entry.add(value);
-					if (f instanceof FutureValue) {
-						try {
-							((FutureValue) f).getValue();
-							entry.add("Closed");
-						}
-						catch (ConditionalYield y) {
-							entry.add("Open");
-						}
-					}
-					else {
-						entry.add("-");
-					}
-					entry.add(sz);
-					String fs;
-					// TODO
-					/*if (f instanceof FutureWrapper) {
-						fs = String.valueOf(((FutureWrapper) f).listenerCount());
-					}
-					else {*/
-						fs = f.toString();
-						fs = fs.substring(fs.indexOf(' ') + 1);
-					//}
-					entry.add(fs);
-					entry.add("2");
-					al.add(entry);
-					wr.add(f);
-				}
-			}
-			VariableModel m = new VariableModel(al);
-			t = new JTable(m);
-			t.getColumnModel().getColumn(1).setPreferredWidth(120);
-			t.getColumnModel().getColumn(2).setPreferredWidth(50);
-			t.getColumnModel().getColumn(4).setPreferredWidth(40);
-			t.getColumnModel().getColumn(5).setPreferredWidth(60);
-			t.getColumnModel().getColumn(6).setPreferredWidth(200);
-			t.addMouseListener(this);
-			JScrollPane sp = new JScrollPane(t);
-			display.removeAll();
-			display.setBorder(BorderFactory.createLineBorder(Color.BLUE));
-			display.add(sp, BorderLayout.CENTER);
-			display.validate();
-			display.repaint();
-		}
-		else if (e.getSource() == waiting) {
-			if (t != null) {
-				t.removeMouseListener(this);
-			}
-			crtdisp = THREADS;
-			ArrayList<String> al = new ArrayList<String>();
-			wt = new ArrayList<LWThread>();
-			Map<LWThread, DSHandle> c = WaitingThreadsMonitor.getAllThreads();
-			for (Map.Entry<LWThread, DSHandle> entry : c.entrySet()) {
-				try {
-					al.add(entry.getKey().getName());
-				}
-				catch (VariableNotFoundException e1) {
-					al.add("unknown thread");
-				}
-				wt.add(entry.getKey());
-			}
-
-			ThreadModel m = new ThreadModel(al);
-			t = new JTable(m);
-			t.addMouseListener(this);
-			JScrollPane sp = new JScrollPane(t);
-			display.removeAll();
-			display.setBorder(BorderFactory.createLineBorder(Color.RED));
-			display.add(sp, BorderLayout.CENTER);
-			display.validate();
-			display.repaint();
-		}
-		else if (e.getSource() == tasks) {
-
-		}
-	}
-
-	public void dumpVariables() {
-		dumpVariables(System.out);
-	}
-
-	public static void dumpVariables(PrintStream ps) {
-		ps.println("\nRegistered futures:");
-		Map<DSHandle, Future> copy = FutureTracker.get().getMapSafe();
-		for (Map.Entry<DSHandle, Future> en : copy.entrySet()) {
-			Future f = en.getValue();
-			AbstractDataNode handle = (AbstractDataNode) en.getKey();
-			if (handle.isClosed()) {
-				continue;
-			}
-			String value = "-";
-			try {
-				if (handle.getValue() != null) {
-					value = "";
-				}
-			}
-			catch (DependentException e) {
-				value = "<dependent exception>";
-			}
-			catch (Exception e) {
-			    value = "<exception>";
-			}
-			try {
-			    ps.println(handle.getType() + " " + handle.getDisplayableName() + " " + value + " " + f);
-			}
-			catch (Exception e) {
-				if (!handle.isClosed()) {
-				    ps.println(handle.getDisplayableName() + " - error");
-				    e.printStackTrace(ps);
-				}
-			}
-			ps.println("----");
-		}
-	}
-	
-    public void dumpThreads() {
-		dumpThreads(System.out);
-	}
-
-	public static void dumpThreads(PrintStream pw) {
-		pw.println("\nWaiting threads:");
-		Map<LWThread, DSHandle> c = WaitingThreadsMonitor.getAllThreads();
-		for (Map.Entry<LWThread, DSHandle> e : c.entrySet()) {
-		    dumpThread(pw, e.getKey(), e.getValue());
-			pw.println();
-		}
-		pw.println("----");
-	}
-
-	public static void dumpThread(PrintStream pw, LWThread thr, DSHandle handle) {
-	    try {
-            pw.println("Thread: " + thr.getName() 
-                + (handle == null ? "" : ", waiting on " + varWithLine(handle)));
-
-            for (String t : getSwiftTrace(thr)) {
-                pw.println("\t" + t);
-            }
-        }
-        catch (VariableNotFoundException e1) {
-            pw.println("unknown thread");
-        }
-    }
-
-    public static String varWithLine(DSHandle value) {
-		String line = value.getRoot().getParam(MappingParam.SWIFT_LINE);
-		Path path = value.getPathFromRoot();
-		return value.getRoot().getParam(MappingParam.SWIFT_DBGNAME) + 
-            (value == value.getRoot() ? "" : (path.isArrayIndex(0) ? path : "." + path)) + 
-            (line == null ? "" : " (declared on line " + line + ")");
-    }
-    
-    public static String getLastCall(LWThread thr) {
-        List<Object> trace = thr.getTrace();
-        if (trace != null) {
-            for (Object o : trace) {
-                if (o instanceof Node) {
-                    Node n = (Node) o;
-                    int line = n.getLine();
-                    return(n.getTextualName() + ", " + 
-                            fileName(n) + ", line " + line);
-                }
-            }
-        }
-        return "?";
-    }
-    
-    public static List<String> getSwiftTrace(LWThread thr) {
-    	List<String> ret = new ArrayList<String>();
-    	List<Object> trace = thr.getTrace();
-    	if (trace != null) {
-            for (Object o : trace) {
-                if (o instanceof Node) {
-                    Node n = (Node) o;
-                    int line = n.getLine();
-                	ret.add(n.getTextualName() + ", " + 
-                            fileName(n) + ", line " + line);
-                
-                }
-            }
-    	}
-        return ret;
-    }
-    
-    public static List<Object> getSwiftTraceElements(LWThread thr) {
-        List<Object> ret = new ArrayList<Object>();
-        List<Object> trace = thr.getTrace();
-        if (trace != null) {
-            for (Object o : trace) {
-                if (o instanceof Node) {
-                    Node n = (Node) o;
-                    ret.add(n.getLine());
-                }
-            }
-        }
-        return ret;
-    }
-
-    private static String fileName(Node n) {
-        return new File(n.getFileName()).getName().replace(".kml", ".swift");
-    }
-
-    public class VariableModel extends AbstractTableModel {
-		private List<Object[]> l;
-
-		public VariableModel(List<List<Object>> lp) {
-			l = new ArrayList<Object[]>();
-			Iterator<List<Object>> i = lp.iterator();
-			while (i.hasNext()) {
-				List<Object> s = i.next();
-				Object[] e = s.toArray();
-				l.add(e);
-			}
-		}
-
-		public int getRowCount() {
-			return l.size();
-		}
-
-		public int getColumnCount() {
-			return 7;
-		}
-
-		public Object getValueAt(int rowIndex, int columnIndex) {
-			if (columnIndex < 6) {
-				return l.get(rowIndex)[columnIndex];
-			}
-			else {
-				List<FutureListener> l = Monitor.this.getListeners(rowIndex);
-				if (l != null) {
-					ArrayList<Object> a = new ArrayList<Object>();
-					for (int i = 0; i < l.size(); i++) {
-						FutureListener o = l.get(i);
-						if (o instanceof LWThread.Listener) {
-						    a.add(((LWThread.Listener) o).getThread().getName());
-						}
-						else {
-							a.add("unknown");
-						}
-					}
-					return a.toString();
-				}
-				else {
-					return "[]";
-				}
-			}
-		}
-
-		public String getColumnName(int column) {
-			switch (column) {
-				case 0:
-					return "Type";
-				case 1:
-					return "Path";
-				case 2:
-					return "Value";
-				case 3:
-					return "State";
-				case 4:
-					return "Crt. Size";
-				case 5:
-					return "# of listeners";
-				case 6:
-					return "Threads";
-				default:
-					return "??";
-			}
-		}
-	}
-
-	public static class ThreadModel extends AbstractTableModel {
-		private List<String> l;
-
-		public ThreadModel(List<String> lp) {
-			l = lp;
-		}
-
-		public int getRowCount() {
-			return l.size();
-		}
-
-		public int getColumnCount() {
-			return 1;
-		}
-
-		public Object getValueAt(int rowIndex, int columnIndex) {
-			return l.get(rowIndex);
-		}
-
-		public String getColumnName(int column) {
-			switch (column) {
-				case 0:
-					return "Thread id";
-				default:
-					return "??";
-			}
-		}
-	}
-
-	public void mouseClicked(MouseEvent e) {
-		if (e.getClickCount() == 2) {
-			int row = t.rowAtPoint(e.getPoint());
-			if (crtdisp == VARS) {
-				List<FutureListener> ls = getListeners(row);
-				if (ls != null) {
-					try {
-					    for (FutureListener l : ls) {
-					        
-							displayPopup("Stack trace for " + t.getValueAt(row, 1),
-									getTrace(l));
-						}
-					}
-					catch (NullPointerException ex) {
-						throw ex;
-					}
-				}
-			}
-			else if (crtdisp == THREADS) {
-				Object o = wt.get(row);
-				if (o instanceof Stack) {
-					displayPopup("Stack trace for " + t.getValueAt(row, 0), " N/A");
-				}
-			}
-		}
-	}
-
-	private String getTrace(FutureListener l) {
-        if (l instanceof LWThread.Listener) {
-            LWThread.Listener lt = (LWThread.Listener) l;
-            return String.valueOf(lt.getThread().getTrace());
-        }
-        else {
-            return "unknown";
-        }
-    }
-
-    private void displayPopup(String title, String s) {
-		JOptionPane.showMessageDialog(frame, s, title, JOptionPane.INFORMATION_MESSAGE);
-	}
-
-	public List<FutureListener> getListeners(int wrindex) {
-		Object o = wr.get(wrindex);
-		// TODO
-		/*if (o instanceof FutureWrapper) {
-			return ((FutureWrapper) o).getListeners();
-		}
-		else {
-		    return null;
-		}*/
-		return null;
-	}
-
-	public void mousePressed(MouseEvent e) {
-	}
-
-	public void mouseReleased(MouseEvent e) {
-	}
-
-	public void mouseEntered(MouseEvent e) {
-	}
-
-	public void mouseExited(MouseEvent e) {
-	}
-
-	public synchronized void toggle() {
-		if (frame == null) {
-			init();
-		}
-		frame.setVisible(!frame.isVisible());
-	}
-
-	private class Service implements Runnable {
-
-		public void run() {
-			try {
-				ServerSocket s = new ServerSocket(10479, 0, InetAddress.getByName("localhost"));
-				while (true) {
-					Socket ins = s.accept();
-					try {
-						InputStream is = ins.getInputStream();
-						OutputStream os = ins.getOutputStream();
-						PrintStream ps = new PrintStream(os, true);
-						ps.println("Swift Debugger");
-						while (true) {
-							ps.print("\n> ");
-							char c = (char) is.read();
-							ps.println(c + '\n');
-							switch (c) {
-								case 'd': {
-									toggle();
-									break;
-								}
-								case 'v': {
-									dumpVariables(ps);
-									break;
-								}
-								case 't': {
-									dumpThreads(ps);
-									break;
-								}
-								case 'q': {
-									ps.println("Ending the session");
-									ins.close();
-									break;
-								}
-								default: {
-									os.write("? Unknown command. Try d, v, t, or q\n".getBytes());
-								}
-							}
-						}
-					}
-					catch (IOException e) {
-						break;
-					}
-				}
-			}
-			catch (Exception e) {
-			}
-		}
-	}
-}




More information about the Swift-commit mailing list