gzz-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Gzz-commits] gzz ./Gzz.py lava/gzz/loom/SimpleView.java lava...


From: Benja Fallenstein
Subject: [Gzz-commits] gzz ./Gzz.py lava/gzz/loom/SimpleView.java lava...
Date: Sat, 22 Feb 2003 05:52:57 -0500

CVSROOT:        /cvsroot/gzz
Module name:    gzz
Changes by:     Benja Fallenstein <address@hidden>      03/02/22 05:52:57

Modified files:
        .              : Gzz.py 
        lava/gzz/loom  : SimpleView.java 
        lava/gzz/modules/gispmap: GispP2PMap.java 
        lava/test/gzz/modules/gispmap: GispP2PMap.test 
        lava/test/gzz/storm/impl: MockP2PMap.test P2PMap.meta 
Added files:
        lava/test/gzz/modules/gispmap: GispP2PMapSimple.test 

Log message:
        view code that makes the test pass

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/Gzz.py.diff?tr1=1.77&tr2=1.78&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/lava/gzz/loom/SimpleView.java.diff?tr1=1.1&tr2=1.2&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/lava/gzz/modules/gispmap/GispP2PMap.java.diff?tr1=1.5&tr2=1.6&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/lava/test/gzz/modules/gispmap/GispP2PMapSimple.test?rev=1.1
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/lava/test/gzz/modules/gispmap/GispP2PMap.test.diff?tr1=1.4&tr2=1.5&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/lava/test/gzz/storm/impl/MockP2PMap.test.diff?tr1=1.3&tr2=1.4&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/lava/test/gzz/storm/impl/P2PMap.meta.diff?tr1=1.4&tr2=1.5&r1=text&r2=text

Patches:
Index: gzz/Gzz.py
diff -u gzz/Gzz.py:1.77 gzz/Gzz.py:1.78
--- gzz/Gzz.py:1.77     Fri Feb 21 15:02:16 2003
+++ gzz/Gzz.py  Sat Feb 22 05:52:56 2003
@@ -35,22 +35,10 @@
 # Flags that can be passed to Gzz.py
 # (prefix with '--' on the command line)
 flagset = ['multiline', 'double-size', 'triple-size', 'lollipop',
-           'python-bindings', 'potion-bindings', 'four-lines',
+           'potion-bindings', 'four-lines',
            'bounded-vanishing-scale']
 
 
-def call(list, type=None):
-    if type is None: type = gzz.potion.CommandCall
-    if list is None: return None
-    if isinstance(list, gzz.potion.Expression): return list
-    #print list
-    head = list[0]
-    params = [call(l, gzz.potion.FunctionCall) for l in list[1:]]
-    return type(head(), params)
-
-def action(list, win=1):
-    return gzz.client.PotionFallbackBinder.Action(call(list), win)
-
 class Gzz(java.lang.Runnable):
     """The main Gzz client class."""
 
@@ -121,118 +109,9 @@
             gzz.view.DimDecorator(),
         ]
 
-        if 'python-bindings' in self.flags:
-            print "Using Python bindings"
-            import bindings
-            self.binder = gzz.client.pythonbinder.PythonBinder(
-                bindings.normal_mode, bindings.edit_mode, bindings.search_mode)
-
         elif 'potion-bindings' in self.flags:
-            arr = gzz.client.PotionFallbackBinder.Arrow
-            def map(dict):
-                m = java.util.HashMap()
-                for k,v in dict.items(): m.put(k, v)
-                return m
-
-            from gzz.potion.potions import NewCell, Connect, PrefixOrOther, \
-                                          Hop2, Put, PrefixOrThis, Go, Clone, \
-                                           ToggleMark, Quit, ChangeView, 
ChangeDim, \
-                                           Break, Delete, GoToOriginal, 
ThisWindow, \
-                                          PrefixOrRight, PrefixOrLeft, 
EventKey, \
-                                          InsertChar, TextCursorLeft, \
-                                          TextCursorRight, SwitchToTextMode, \
-                                          SwitchToNormalMode, MarkHalfRank, \
-                                           ExtEdit, ViewContainedText, 
AndFilterFn, \
-                                           OrFilterFn, RootClone, Step, 
ChangeCellView, \
-                                           DeleteChar
-
-            from gzz.modules.email import AllEmailsThat, SubjectFilterFn, 
FromFilterFn, \
-                                          ToFilterFn, OlderFilterFn, 
NewerFilterFn
-
-            def fn(fn):
-                return call(fn, gzz.potion.FunctionCall)
-
-           def const(i):
-               from gzz.potion.potions import ConstantExpression
-               return ConstantExpression(i, str(i))
-
-            bindings = {
-                'Up': arr(1,1,-1), 'i': arr(1,1,-1), 'e': arr(0,1,-1),
-                'Down': arr(1,1,1), ',': arr(1,1,1), 'c': arr(0,1,1),
-                'Left': arr(1,0,-1), 'j': arr(1,0,-1), 's': arr(0,1,-1),
-                'Right': arr(1,0,1), 'l': arr(1,0,1), 'f': arr(0,0,1),
-                'k': arr(1,2,1), 'K': arr(1,2,-1),
-                'd': arr(0,2,1), 'D': arr(0,2,-1),
-                'n': action([NewCell, None]),
-                '-': action([Connect, [PrefixOrOther], None]),
-               'h': action([Hop2, None]),
-                'p': action([Put,[ThisWindow], [PrefixOrOther]], 1),
-                'P': action([Put,[ThisWindow], [PrefixOrOther]], 0),
-               'g': action([Go, [PrefixOrOther]], 1),
-               'G': action([Go, [PrefixOrOther]], 0),
-               't': action([Clone,[PrefixOrRight], None]),
-                'T': action([Clone,[PrefixOrLeft], None]),
-               'm': action([ToggleMark, [ThisWindow]], 1),
-               'M': action([ToggleMark, [ThisWindow]], 0),
-                'Alt-M': action([MarkHalfRank, [PrefixOrThis], None]),
-               'q': action(call([Quit])),
-               'Q': action(call([Quit])),
-               'x': action(call([ChangeDim, const(0), const(1)]), 1),
-               'y': action(call([ChangeDim, const(1), const(1)]), 1),
-               'z': action(call([ChangeDim, const(2), const(1)]), 1),
-               'X': action(call([ChangeDim, const(0), const(1)]), 0),
-               'Y': action(call([ChangeDim, const(1), const(1)]), 0),
-               'Z': action(call([ChangeDim, const(2), const(1)]), 0),
-               'Alt-X': action(call([ChangeDim, const(0), const(-1)]), 1),
-               'Alt-Y': action(call([ChangeDim, const(1), const(-1)]), 1),
-               'Alt-Z': action(call([ChangeDim, const(2), const(-1)]), 1),
-               'Alt-Shift-X': action(call([ChangeDim, const(0), const(-1)]), 
0),
-               'Alt-Shift-Y': action(call([ChangeDim, const(1), const(-1)]), 
0),
-               'Alt-Shift-Z': action(call([ChangeDim, const(2), const(-1)]), 
0),
-               'v': action(call([ChangeView, const(1)])),
-               'Alt-V': action(call([ChangeView, const(-1)])),
-                'b': action(call([Break, None])),
-                'B': action(call([Break, None])),
-                'Delete': action(call([Delete, [PrefixOrThis]])),
-                'Alt-Backspace': action(call([Delete, [PrefixOrThis]])),
-                'Shift-Delete': action(call([Delete, [PrefixOrThis]])),
-                'Alt-Shift-Backspace': action(call([Delete, [PrefixOrThis]])),
-                'o': action(call([Go, [RootClone, [ThisWindow]]]), 1),
-                'O': action(call([Go, [RootClone, [ThisWindow]]]), 0),
-               'Tab': action(call([SwitchToTextMode])),
-               'Tabulator': action(call([SwitchToTextMode])),
-                'Ctrl-E': action(call([ExtEdit, [PrefixOrThis]]), 1),
-                'Ctrl-Shift-E': action(call([ExtEdit, [PrefixOrThis]]), 0),
-                'Ctrl-V': action(call([ViewContainedText, [PrefixOrThis]]), 1),
-                'Ctrl-Shift-V': action(call([ViewContainedText, 
[PrefixOrThis]]), 0),
-                'Ctrl-9': action(call([ChangeCellView, const(1)])),
-
-                'Ctrl-A': fn([AllEmailsThat, None]),
-                'Ctrl-F': fn([FromFilterFn, None]),
-                'Ctrl-T': fn([ToFilterFn, None]),
-                'Ctrl-O': fn([OlderFilterFn, None]),
-                'Ctrl-Alt-O': fn([NewerFilterFn, None]),
-                'Alt-S': fn([SubjectFilterFn, None]),
-                '&': fn([AndFilterFn, None, None]),
-                '|': fn([OrFilterFn, None, None]),
-           }
-
-           text_bindings = {
-               gzz.client.PotionFallbackBinder.CHAR_KEY:
-                           action(call([InsertChar, [EventKey]])),
-               'Left': action(call([TextCursorLeft])),
-               'Right': action(call([TextCursorRight])),
-               'Tab': action(call([SwitchToNormalMode])),
-               'Tabulator': action(call([SwitchToNormalMode])),
-                'Backspace': action(call([DeleteChar])),
-           }
-
-           bindings = map(bindings)
-           bindingsByMode = java.util.HashMap()
-           bindingsByMode.put(gzz.client.PotionFallbackBinder.NORMAL_MODE,
-                              bindings)
-           bindingsByMode.put("text mode", map(text_bindings))
-
+            from bindings import bindingsByMode
+            
             self.binder = gzz.client.PotionFallbackBinder(bindingsByMode)
             self.decorators.append(gzz.view.PendingPotionDecorator())
         else:
Index: gzz/lava/gzz/loom/SimpleView.java
diff -u gzz/lava/gzz/loom/SimpleView.java:1.1 
gzz/lava/gzz/loom/SimpleView.java:1.2
--- gzz/lava/gzz/loom/SimpleView.java:1.1       Sat Feb 22 05:09:05 2003
+++ gzz/lava/gzz/loom/SimpleView.java   Sat Feb 22 05:52:56 2003
@@ -28,8 +28,33 @@
 import gzz.vob.*;
 import com.hp.hpl.mesa.rdf.jena.model.*;
 
+/** A very simple view of an RDF graph.
+ *  Example:
+ *  <pre>
+ *      neg1 \
+ *      neg2 \       / pos1
+ *      neg3 - focus - pos2
+ *      neg4 /       \ pos3
+ *      neg5 /
+ *  </pre>
+ */
 public class SimpleView implements View {
 
     public void render(VobScene sc, int into, Resource focus, RDFNode 
rotation) {
+       try {
+           int cs = sc.boxCS(into, focus, 0, 0, 50, 20);
+           int csr = sc.boxCS(into, rotation, 100, 0, 50, 20);
+           StmtIterator i=focus.listProperties();
+           int y = 50;
+           for(; i.hasNext();) {
+               Statement s = i.next();
+               if(s.getObject().equals(rotation)) continue;
+               sc.boxCS(into, s.getObject(), 100, y, 50, 20);
+               y += 50;
+           }
+           i.close();
+       } catch(RDFException e) {
+           throw new Error("RDFException: "+e);
+       }
     }
 }
Index: gzz/lava/gzz/modules/gispmap/GispP2PMap.java
diff -u gzz/lava/gzz/modules/gispmap/GispP2PMap.java:1.5 
gzz/lava/gzz/modules/gispmap/GispP2PMap.java:1.6
--- gzz/lava/gzz/modules/gispmap/GispP2PMap.java:1.5    Fri Feb 21 15:02:51 2003
+++ gzz/lava/gzz/modules/gispmap/GispP2PMap.java        Sat Feb 22 05:52:56 2003
@@ -62,6 +62,7 @@
 import gzz.storm.*;
 import gzz.storm.impl.*;
 import gzz.util.HexUtil;
+import gzz.util.ByteArrayKey;
 
 import java.io.*;
 import java.util.*;
@@ -79,14 +80,26 @@
     static public boolean dbg = false;
     static private void pa(String s) { System.out.println(s); }
 
-    GISPUDP gisp;
+    protected GISP gisp;
+    protected Map cache = new HashMap();
 
-    public GispP2PMap() {
+    public GispP2PMap(String seedAddress) throws Exception {
        int offs = (int)(2000 * new java.util.Random().nextDouble());
-       gisp = new GISPUDP(12415 + offs);
-       gisp.start(new String[0]);
+       GISPUDP gisp = new GISPUDP(12415 + offs);
+       this.gisp = gisp;
+       if(seedAddress != null) {
+           String[] seeds = new String[] { seedAddress };
+           gisp.addSeedAddresses(seeds);
+       }
+       gisp.start(new String[] {"strength_min=1"});
+    }
+
+    public GispP2PMap() throws Exception {
+       this(null);
     }
 
+    public GISP getGisp() { return gisp; }
+
     public void put(byte[] key, byte[] value) throws IOException {
        // inelegant...
        String keyString = HexUtil.byteArrToHex(key);
@@ -94,21 +107,27 @@
        
        gisp.insert(keyString, valString);
 
+       cache.remove(new ByteArrayKey(key));
+
        // XXX keep alive after ttl...
     }
 
     public Collector get(byte[] key) throws IOException {
        if(dbg) pa("get collector");
-       return new MyCollector(key);
+       ByteArrayKey bak = new ByteArrayKey(key);
+       Collector c = (Collector)cache.get(bak);
+       if(c == null || c.getAge() > 2 * 60 * 1000) {
+           c = new MyCollector(key);
+           cache.put(bak, c);
+       }
+       return c;
     }
 
-    protected class MyCollector extends AsyncSetCollector 
-       implements ResultListener, Runnable {
+    protected class MyCollector extends AsyncSetCollector implements 
ResultListener {
 
        protected MyCollector(byte[] key) {
            String k = HexUtil.byteArrToHex(key);
-           gisp.query(k, this);
-           new Thread(this).start();
+           gisp.query(k, this, 3000);
        }
 
        public void stringResult(String data){
@@ -123,17 +142,8 @@
        public void xmlResult(byte[] data){
        }       
 
-       public void run() {
-           if(dbg) pa("start sleeping");
-           try {
-               Thread.sleep(3000);
-               if(dbg) pa("normal wakeup");
-           } catch(InterruptedException e) {
-               if(dbg) pa("interrupted");
-           }
-
+       public void queryExpired() {
            finish(true);
-           if(dbg) pa("finish");
        }
     }
 }
Index: gzz/lava/test/gzz/modules/gispmap/GispP2PMap.test
diff -u gzz/lava/test/gzz/modules/gispmap/GispP2PMap.test:1.4 
gzz/lava/test/gzz/modules/gispmap/GispP2PMap.test:1.5
--- gzz/lava/test/gzz/modules/gispmap/GispP2PMap.test:1.4       Fri Feb 21 
15:02:54 2003
+++ gzz/lava/test/gzz/modules/gispmap/GispP2PMap.test   Sat Feb 22 05:52:56 2003
@@ -52,8 +52,19 @@
 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE 
 # OR OTHER DEALINGS IN THE SOFTWARE.
 
-import gzz
+import java, gzz
 
-map = gzz.modules.gispmap.GispP2PMap()
+map1 = gzz.modules.gispmap.GispP2PMap()
+map2 = gzz.modules.gispmap.GispP2PMap(map1.getGisp().getMyAddress())
 
 execfile('lava/test/gzz/storm/impl/P2PMap.meta')
+
+testSimple.__doc__ = "\n\ncost: 10\n"
+
+def beforePut():
+    print 'waiting for GISP to initialize (20 sec)'
+    java.lang.Thread.sleep(20000)
+
+def afterPut():
+    print 'waiting for GISP to insert the item... (20 sec)'
+    java.lang.Thread.sleep(20000)
\ No newline at end of file
Index: gzz/lava/test/gzz/storm/impl/MockP2PMap.test
diff -u gzz/lava/test/gzz/storm/impl/MockP2PMap.test:1.3 
gzz/lava/test/gzz/storm/impl/MockP2PMap.test:1.4
--- gzz/lava/test/gzz/storm/impl/MockP2PMap.test:1.3    Fri Feb 21 15:02:55 2003
+++ gzz/lava/test/gzz/storm/impl/MockP2PMap.test        Sat Feb 22 05:52:56 2003
@@ -22,6 +22,9 @@
 
 import gzz, java
 
-map = gzz.storm.impl.MockP2PMap()
+# We pass the same object because that's what we'd do
+# when using MockP2PMap in other tests: we simply
+# pass the same MockP2PMap to two P2PPools.
+map1 = map2 = gzz.storm.impl.MockP2PMap()
 
 execfile('lava/test/gzz/storm/impl/P2PMap.meta')
Index: gzz/lava/test/gzz/storm/impl/P2PMap.meta
diff -u gzz/lava/test/gzz/storm/impl/P2PMap.meta:1.4 
gzz/lava/test/gzz/storm/impl/P2PMap.meta:1.5
--- gzz/lava/test/gzz/storm/impl/P2PMap.meta:1.4        Fri Feb 21 15:02:55 2003
+++ gzz/lava/test/gzz/storm/impl/P2PMap.meta    Sat Feb 22 05:52:57 2003
@@ -21,13 +21,26 @@
 # 
 
 """
-Needs attribute: map -- the P2PMap to be tested
+Needs attribute: map1, map2 -- two instances of
+the P2PMap to be tested. The two need to be connected,
+so that a change in one shows up in the other.
+
+The afterPut() hook function can be overridden
+to wait a few seconds after put()ting. This is required
+by the GISP implementation to make sure the item
+has really been entered into the database.
+By default, this function does nothing.
+
+Same with beforePut().
 """
 
 import gzz, java
 
 from jarray import array
 
+def beforePut(): pass
+def afterPut(): pass
+
 def set(collection):
     set = java.util.HashSet()
     if hasattr(collection, '__getitem__'):
@@ -46,19 +59,25 @@
     k4 = array([8,6,2,5,4], 'b')
     k5 = array([5,6,4], 'b')
 
-    map.put(k1, 'foo')
-    map.put(k2, 'bar')
-    map.put(k3, 'baz')
-    map.put(k4, 'wombat')
-    map.put(k5, 'flabberghasted')
-
-    q1, q2, q3, q4, q5 = [map.get(k) for k in [k1, k2, k3, k4, k5]]
-
-    print 'wait'
-    print set(q1.block()), set(q2.block()), set(['foo', 'bar'])
-    print 'ok'
+    beforePut()
+
+    map1.put(k1, 'foo')
+    map1.put(k2, 'bar')
+    map1.put(k3, 'baz')
+    map1.put(k4, 'wombat')
+    map1.put(k5, 'flabberghasted')
+
+    afterPut()
+
+    q1, q2, q3, q4, q5 = [map2.get(k) for k in [k1, k2, k3, k4, k5]]
+    qx = map1.get(k5)
+
+    #print 'wait'
+    #print set(q1.block()), set(q2.block()), set(['foo', 'bar'])
+    #print 'ok'
     assert set(q1.block()) == set(q2.block()) == set(['foo', 'bar'])
     assert set(q3.block()) == set(q4.block()) == set(['baz', 'wombat'])
-    assert set(q5.block()) == set(['flabberghasted'])
+    assert set(q5.block()) == set(qx.block()) == set(['flabberghasted'])
+
 
     




reply via email to

[Prev in Thread] Current Thread [Next in Thread]