Philip Levis wrote:
> It turns out this depends on what VM you're using. Some have no problem,
> others are CPU bound.

this still means that there is some issue within the application.

I ran it under the JBM JDK, on Gentoo Linux (64 bit)

>> I change the application to remove motes / links that are unheard of for
>> some time. I could send a patch over if you guys find this interesting.
> 
> That would be great.

see attached.

BTW, the line endings on some of the source files are incostitent. it's
not that it's either DOS or UNIX, but just bad :(


Akos

diff -Naur tinyos-2.0.2/opt/tinyos-2.x/support/sdk/java/net/tinyos/mviz/DDocument.java tinyos-2.0.2-mvizfix/opt/tinyos-2.x/support/sdk/java/net/tinyos/mviz/DDocument.java
--- tinyos-2.0.2/opt/tinyos-2.x/support/sdk/java/net/tinyos/mviz/DDocument.java	2006-11-06 12:57:01.000000000 +0100
+++ tinyos-2.0.2-mvizfix/opt/tinyos-2.x/support/sdk/java/net/tinyos/mviz/DDocument.java	2007-09-01 16:49:42.000000000 +0200
@@ -74,6 +74,9 @@
     private JTextField jText;
     private DrawTableModel tableModel;
     private JTable jTable;
+
+    // make motes expire after 10 seconds of not hearing from them
+    private static final long MAX_MOTE_AGE = 60 * 1000;
 	
     private String[] toStringArray(Vector v) {
 	String[] array = new String[v.size()];
@@ -196,6 +199,18 @@
 	navigator.addMote(m);
 	return m;
     }
+
+    private void deleteMote(int moteId) {
+        DMoteModel mote = (DMoteModel) moteIndex.get(moteId);
+        if (mote == null) {
+            return;
+        }
+        navigator.removeMote(mote);
+        tableModel.remove(mote);
+
+        moteIndex.remove(moteId);
+        motes.remove(mote);
+    }
     
     public void setMoteValue(int moteID, String name, int value) {
 	ValueSetEvent vsv = new ValueSetEvent(this, moteID, name, value);
@@ -211,13 +226,73 @@
 	return dl;
     }
     
+    private void deleteLink(String linkId) {
+        DLinkModel link = (DLinkModel) linkIndex.get(linkId);
+        if (link == null) {
+            return;
+        }
+
+        linkIndex.remove(linkId);
+        links.remove(link);
+    }
+    
     public void setLinkValue(int startMote, int endMote, String name, int value) {
 	LinkSetEvent lsv = new LinkSetEvent(this, name, value, startMote, endMote);
 	EventQueue eq = Toolkit.getDefaultToolkit().getSystemEventQueue();
 	eq.postEvent(lsv);
     }
 
+    protected void removeStaleMotes() {
+        long   now          = (new Date()).getTime();
+        Vector staleMoteIds = new Vector();
+
+        for (Iterator it = moteIndex.entrySet().iterator();
+             it.hasNext(); ) {
+
+            Map.Entry  entry = (Map.Entry) it.next();
+            DMoteModel mote  = (DMoteModel) entry.getValue();
+            if (now - mote.getLastReading() > MAX_MOTE_AGE) {
+                staleMoteIds.add(entry.getKey());
+            }
+        }
+
+        for (Iterator it = staleMoteIds.iterator();
+            it.hasNext(); ) {
+
+            Integer moteId = (Integer) it.next();
+            System.out.println("removing mote " + moteId); 
+            deleteMote(moteId);
+        }
+    }
+
+    protected void removeStaleLinks() {
+        long   now          = (new Date()).getTime();
+        Vector staleLinkIds = new Vector();
+
+        for (Iterator it = linkIndex.entrySet().iterator();
+             it.hasNext(); ) {
+
+            Map.Entry  entry = (Map.Entry) it.next();
+            DLinkModel link  = (DLinkModel) entry.getValue();
+            if (now - link.getLastReading() > MAX_MOTE_AGE) {
+                staleLinkIds.add(entry.getKey());
+            }
+        }
+
+        for (Iterator it = staleLinkIds.iterator();
+            it.hasNext(); ) {
+
+            String linkId = (String) it.next();
+            System.out.println("removing link " + linkId); 
+            deleteLink(linkId);
+        }
+    }
+
     protected void processEvent(AWTEvent event) {
+    removeStaleMotes();
+    removeStaleLinks();
+    long now = (new Date()).getTime();
+
 	if (event instanceof ValueSetEvent) {
 	    ValueSetEvent vsv = (ValueSetEvent)event;
 	    String name = vsv.name();
@@ -229,6 +304,7 @@
 	    }
 	    //System.out.println("Set " + moteID + ":" + name + " to " + value);
 	    m.setMoteValue(name, value);
+        m.setLastReading(now);
 	    navigator.redrawAllLayers();
 	}
 	else if (event instanceof LinkSetEvent) {
@@ -252,6 +328,9 @@
 	    }
 	    //System.out.println("Setting " + name + " " + startMote + " -> " + endMote + " to " + value);
 	    dl.setLinkValue(name, value);
+        dl.setLastReading(now);
+        m.setLastReading(now);
+        m2.setLastReading(now);
 	    navigator.redrawAllLayers();
 	}
 	else {
@@ -371,6 +450,7 @@
 	//-----------------------------o
 	public void remove(DMoteModel model){
 	    int row = findModel(model);
+        System.out.println("found row: " + row);
 	    if (row != -1) fireTableRowsDeleted(row, row);	        
 	}
 	//-----------------------------o
diff -Naur tinyos-2.0.2/opt/tinyos-2.x/support/sdk/java/net/tinyos/mviz/DLayer.java tinyos-2.0.2-mvizfix/opt/tinyos-2.x/support/sdk/java/net/tinyos/mviz/DLayer.java
--- tinyos-2.0.2/opt/tinyos-2.x/support/sdk/java/net/tinyos/mviz/DLayer.java	2006-11-06 12:57:01.000000000 +0100
+++ tinyos-2.0.2-mvizfix/opt/tinyos-2.x/support/sdk/java/net/tinyos/mviz/DLayer.java	2007-09-01 16:10:00.000000000 +0200
@@ -282,8 +282,19 @@
 	    addMote((DMoteModel) it.next(), paint);
 	} 	    
     }
+
+    protected void removeMote(DMoteModel mote, boolean paint) {
+        for (Iterator it = layer.iterator();
+             it.hasNext(); ) {
+
+            DShape     shape = (DShape) it.next();
+            if (shape.getModel().equals(mote)) {
+                layer.remove(shape);
+                break;
+            }
+        }
+    }
     
-	
     public void updateIndex(int index, boolean repaint){
 	zIndex = index;
 	z_index = (navigator.totalLayers - zIndex)*100;
diff -Naur tinyos-2.0.2/opt/tinyos-2.x/support/sdk/java/net/tinyos/mviz/DLinkModel.java tinyos-2.0.2-mvizfix/opt/tinyos-2.x/support/sdk/java/net/tinyos/mviz/DLinkModel.java
--- tinyos-2.0.2/opt/tinyos-2.x/support/sdk/java/net/tinyos/mviz/DLinkModel.java	2006-11-06 12:57:01.000000000 +0100
+++ tinyos-2.0.2-mvizfix/opt/tinyos-2.x/support/sdk/java/net/tinyos/mviz/DLinkModel.java	2007-09-01 16:20:08.000000000 +0200
@@ -64,6 +64,9 @@
     DMoteModel m2;
     
     protected int COLOR_MAX = 230;
+
+    protected long lastReading;
+
 	
     public DLinkModel(DMoteModel m1, DMoteModel m2, Random rand, DDocument root){
         this.root = root;
@@ -80,6 +83,7 @@
         }   
         
 
+        lastReading = (new Date()).getTime();
         //.listeners = null;
     }
 
@@ -132,6 +136,12 @@
 	    return y12;
 	}		
 	
+    public long getLastReading() {
+        return lastReading;
+    }
+    public void setLastReading(long lastReading) {
+        this.lastReading = lastReading;
+    }
 	
 	public void addListener(DLinkModelListener listener) {
 	    if (listeners == null) listeners = new ArrayList();
diff -Naur tinyos-2.0.2/opt/tinyos-2.x/support/sdk/java/net/tinyos/mviz/DMote.java tinyos-2.0.2-mvizfix/opt/tinyos-2.x/support/sdk/java/net/tinyos/mviz/DMote.java
--- tinyos-2.0.2/opt/tinyos-2.x/support/sdk/java/net/tinyos/mviz/DMote.java	2006-11-06 12:57:01.000000000 +0100
+++ tinyos-2.0.2-mvizfix/opt/tinyos-2.x/support/sdk/java/net/tinyos/mviz/DMote.java	2007-09-01 15:21:53.000000000 +0200
@@ -1 +1,98 @@
-/*
 * Copyright (c) 2006 Stanford University.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * - Redistributions of source code must retain the above copyright
 *   notice, this list of conditions and the following disclaimer.
 * - Redistributions in binary form must reproduce the above copyright
 *   notice, this list of conditions and the following disclaimer in the
 *   documentation and/or other materials provided with the
 *   distribution.
 * - Neither the name of the Stanford University nor the names of
 *   its contributors may be used to endorse or promote products derived
 *   from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL STANFORD
 * UNIVERSITY OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
 * OF THE POSSIBILITY OF SUCH DAMAGE.
 */

package net.tinyos.mviz;

import java.awt.*;


public class DMote
extends DShape 
implements DMoteModelListener
{
    
    private DDocument document;
    private DMoteModel model;
    
    public DMote(DMoteModel model, DDocument document, DLayer layer) {
        super(model, document, layer);
	this.document = document;
	this.model = model;
    }
    

    static int counter =0;
    public void paintShape(Graphics g) {
	int x = model.getLocX();
	int y = model.getLocY();
	//System.out.println("Mode " + layer.paintMode);
    	switch(layer.paintMode){
    	case DLayer.IMG:
	    Image img = model.getImage();
	    java.awt.MediaTracker tracker = new java.awt.MediaTracker(this);
	    tracker.addImage(img, 0);
	    if (document.selected == model) {
		g.setColor(Color.RED);
		g.fillOval(x-22, y-22, 44, 44);
	    }
	    g.drawImage(img, x-20, y-20, 40, 40, document.canvas);
	    try {tracker.waitForAll();}
	    catch(InterruptedException e){} 
	    //System.out.println("Draw image " + img + " " + x + " " + y + " " + img.getHeight(document.canvas) + " " + tracker.isErrorAny());

	    //img = model.getIcon().getImage();
	    //System.out.println("Draw image " + img + " " + x + " " + y);
	    //document.canvas.getGraphics().drawImage(img, x, y, this.model.root);
	    break;
    	case DLayer.OVAL:
	    if (document.selected != model) {
		g.setColor(Color.GRAY);
	    }
	    else {
		g.setColor(Color.RED);
	    }
	    counter++;
	    g.fillOval(x-20, y-20, 40, 40);
	    break;
    	case DLayer.TXT_MOTE:
	    g.setFont(new Font("Helvetica", Font.PLAIN, 8));
	    g.setColor(Color.BLACK);
	    g.drawString(document.sensed_motes.elementAt(layer.index) + ": " + (int)model.getValue(layer.index), x+22, y-2);
	    break;
	default:
    	}

    }

}


\ No newline at end of file
+/*
+ * Copyright (c) 2006 Stanford University.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the
+ *   distribution.
+ * - Neither the name of the Stanford University nor the names of
+ *   its contributors may be used to endorse or promote products derived
+ *   from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL STANFORD
+ * UNIVERSITY OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+package net.tinyos.mviz;
+
+import java.awt.*;
+
+
+public class DMote
+extends DShape 
+implements DMoteModelListener
+{
+    
+    private DDocument document;
+    private DMoteModel model;
+    
+    public DMote(DMoteModel model, DDocument document, DLayer layer) {
+        super(model, document, layer);
+	this.document = document;
+	this.model = model;
+    }
+    
+
+    static int counter =0;
+    public void paintShape(Graphics g) {
+	int x = model.getLocX();
+	int y = model.getLocY();
+	//System.out.println("Mode " + layer.paintMode);
+    	switch(layer.paintMode){
+    	case DLayer.IMG:
+	    Image img = model.getImage();
+	    java.awt.MediaTracker tracker = new java.awt.MediaTracker(this);
+	    tracker.addImage(img, 0);
+	    if (document.selected == model) {
+		g.setColor(Color.RED);
+		g.fillOval(x-22, y-22, 44, 44);
+	    }
+	    g.drawImage(img, x-20, y-20, 40, 40, document.canvas);
+	    try {tracker.waitForAll();}
+	    catch(InterruptedException e){} 
+	    //System.out.println("Draw image " + img + " " + x + " " + y + " " + img.getHeight(document.canvas) + " " + tracker.isErrorAny());
+
+	    //img = model.getIcon().getImage();
+	    //System.out.println("Draw image " + img + " " + x + " " + y);
+	    //document.canvas.getGraphics().drawImage(img, x, y, this.model.root);
+	    break;
+    	case DLayer.OVAL:
+	    if (document.selected != model) {
+		g.setColor(Color.GRAY);
+	    }
+	    else {
+		g.setColor(Color.RED);
+	    }
+	    counter++;
+	    g.fillOval(x-20, y-20, 40, 40);
+	    break;
+    	case DLayer.TXT_MOTE:
+	    g.setFont(new Font("Helvetica", Font.PLAIN, 8));
+	    g.setColor(Color.BLACK);
+	    g.drawString(document.sensed_motes.elementAt(layer.index) + ": " + (int)model.getValue(layer.index), x+22, y-2);
+	    break;
+	default:
+    	}
+
+    }
+
+}
+
+
+
diff -Naur tinyos-2.0.2/opt/tinyos-2.x/support/sdk/java/net/tinyos/mviz/DMoteModel.java tinyos-2.0.2-mvizfix/opt/tinyos-2.x/support/sdk/java/net/tinyos/mviz/DMoteModel.java
--- tinyos-2.0.2/opt/tinyos-2.x/support/sdk/java/net/tinyos/mviz/DMoteModel.java	2006-11-06 12:57:01.000000000 +0100
+++ tinyos-2.0.2-mvizfix/opt/tinyos-2.x/support/sdk/java/net/tinyos/mviz/DMoteModel.java	2007-09-01 15:46:56.000000000 +0200
@@ -61,6 +61,7 @@
     protected float[] values;
     protected Color[] colors;
     protected int[] sizes;
+    protected long lastReading;
     
     protected int SHAPE_SIZE_MAX = 100;
     protected int COLOR_MAX = 230;
@@ -85,6 +86,8 @@
         }
         
         listeners = null;
+
+        lastReading = (new Date()).getTime();
     }
 
 	
@@ -183,6 +186,12 @@
     public Color getColor(int index) { 
 	return colors[index]; 
     }
+    public long getLastReading() {
+        return lastReading;
+    }
+    public void setLastReading(long lastReading) {
+        this.lastReading = lastReading;
+    }
 	
 	
     public void addListener(DMoteModelListener listener) {
diff -Naur tinyos-2.0.2/opt/tinyos-2.x/support/sdk/java/net/tinyos/mviz/DNavigate.java tinyos-2.0.2-mvizfix/opt/tinyos-2.x/support/sdk/java/net/tinyos/mviz/DNavigate.java
--- tinyos-2.0.2/opt/tinyos-2.x/support/sdk/java/net/tinyos/mviz/DNavigate.java	2006-11-06 12:57:02.000000000 +0100
+++ tinyos-2.0.2-mvizfix/opt/tinyos-2.x/support/sdk/java/net/tinyos/mviz/DNavigate.java	2007-09-01 16:49:29.000000000 +0200
@@ -93,7 +93,15 @@
 	    layer.addMote(model, true);
 	}
    }
-	
+
+   protected void removeMote(DMoteModel mote) {
+	Iterator it = layers.iterator();
+	while(it.hasNext()){
+	    DLayer layer = (DLayer)it.next();
+	    layer.removeMote(mote, true);
+	}
+   }
+
 	private void addLayer(Vector labels, int type, ArrayList models){
 	    for (int i=0; i<labels.size(); i++, _tmp_i++){
 		DLayer d = new DLayer(_tmp_i, i, (String)labels.elementAt(i), type, parent, models, this);
@@ -137,7 +145,6 @@
 		layers.add(zIndex-1, d);
 		updateLayerIndex(true);
 		redrawNavigator();
-		redrawAllLayers(); 
 	}
 	
 	public void moveLayerDown(int zIndex){
@@ -146,7 +153,6 @@
 		layers.add(zIndex+1, d);
 		updateLayerIndex(true);
 		redrawNavigator();
-		redrawAllLayers();
 	}
 	
 	public void init(){
@@ -172,14 +178,16 @@
 
     
     private long currentSecond = -1;
-    private long PERIOD = 500;
+    private long PERIOD = 2000;
     
     protected void redrawAllLayers(){
 	Date date = new Date();
+    //System.out.println("time: " + (date.getTime() - currentSecond));
 	if (date.getTime() - currentSecond < PERIOD){
-	    //System.out.println("time: " + (date.getTime() - currentSecond));
+        //System.out.println("not redrawing...");
 	    return;
 	} else {
+        //System.out.println("redrawing...");
 	    currentSecond = date.getTime();
 	}
 	    
_______________________________________________
Tinyos-help mailing list
[email protected]
https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help

Reply via email to