gzz-commits
[Top][All Lists]
Advanced

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

[Gzz-commits] gzz/lava/gzz/storm Collector.java IndexedPool.j...


From: Benja Fallenstein
Subject: [Gzz-commits] gzz/lava/gzz/storm Collector.java IndexedPool.j...
Date: Sun, 22 Dec 2002 22:20:59 -0500

CVSROOT:        /cvsroot/gzz
Module name:    gzz
Changes by:     Benja Fallenstein <address@hidden>      02/12/22 22:20:59

Modified files:
        lava/gzz/storm : Collector.java IndexedPool.java Pointer.java 
                         StormPool.java 
        lava/gzz/storm/impl: DirPool.java TransientPool.java 
                             ZipPool.java 
Added files:
        lava/gzz/storm : BlockListener.java 
        lava/gzz/storm/impl: AbstractLocalPool.java 
Removed files:
        lava/gzz/storm : JobListener.java 

Log message:
        I think the async and indexing interfaces are almost there now

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/lava/gzz/storm/BlockListener.java?rev=1.1
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/lava/gzz/storm/Collector.java.diff?tr1=1.2&tr2=1.3&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/lava/gzz/storm/IndexedPool.java.diff?tr1=1.4&tr2=1.5&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/lava/gzz/storm/Pointer.java.diff?tr1=1.1&tr2=1.2&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/lava/gzz/storm/StormPool.java.diff?tr1=1.10&tr2=1.11&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/lava/gzz/storm/impl/AbstractLocalPool.java?rev=1.1
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/lava/gzz/storm/impl/DirPool.java.diff?tr1=1.12&tr2=1.13&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/lava/gzz/storm/impl/TransientPool.java.diff?tr1=1.19&tr2=1.20&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/lava/gzz/storm/impl/ZipPool.java.diff?tr1=1.7&tr2=1.8&r1=text&r2=text

Patches:
Index: gzz/lava/gzz/storm/Collector.java
diff -u gzz/lava/gzz/storm/Collector.java:1.2 
gzz/lava/gzz/storm/Collector.java:1.3
--- gzz/lava/gzz/storm/Collector.java:1.2       Sun Dec 22 21:28:18 2002
+++ gzz/lava/gzz/storm/Collector.java   Sun Dec 22 22:20:58 2002
@@ -7,6 +7,30 @@
  *  This is an unmodifiable collection, but until
  *  the lookup has been finished, additional elements
  *  may appear in it. 
+ *  <p>
+ *  Note: All methods in this interface are guaranteed
+ *  to be synchronized so that they can be safely used
+ *  from a single thread without worrying about
+ *  the other thread that possibly pours additional
+ *  objects into this collection. However, if you want to
+ *  use this object from more than one of your threads,
+ *  you need to do your own synchronization (this permits
+ *  implementations that do <em>not</em> read
+ *  from the network not to be synchronized). Additionally,
+ *  you need to synchronize if your code relies on the collection 
+ *  not to change between two function calls, or if you 
+ *  iterate over the collection. For example, you might write:
+ *  <pre>
+ *      Collector c = ...;
+ *      synchronized(c) {
+ *          Iterator i = c.iterator();
+ *          for(; i.hasNext();) {
+ *              ...
+ *          }
+ *      }
+ *  </pre>
+ *  Note that the <code>iterator()</code> call must be inside
+ *  the synchronized block.
  */
 public interface Collector extends Collection {
     
Index: gzz/lava/gzz/storm/IndexedPool.java
diff -u gzz/lava/gzz/storm/IndexedPool.java:1.4 
gzz/lava/gzz/storm/IndexedPool.java:1.5
--- gzz/lava/gzz/storm/IndexedPool.java:1.4     Fri Nov 22 07:41:29 2002
+++ gzz/lava/gzz/storm/IndexedPool.java Sun Dec 22 22:20:58 2002
@@ -30,7 +30,7 @@
  *  "get me all blocks that transclude this xanalogical span." This interface
  *  provides a general way to implement such indexes.
  *  <p>
- *  Indices aren't created on the fly for now: They are handed
+ *  Indices aren't created on the fly: They are handed
  *  to the pool's constructor. This is not only for false simplicity ;-),
  *  but also for safety: whoever has a pointer to a StormPool
  *  is allowed to read, add and delete blocks, but not to
@@ -38,34 +38,54 @@
  *  An evil Index implementation would be capable of that.
  *  <p>
  *  XXX Explain how this works.
- *  <p>
- *  XXX Does <code>Map</code> suffice for a db?
- *  It certainly does not have any support
- *  for asynchronizity. Hmmm...
  */
 public interface IndexedPool extends StormPool {
 
-    interface Index {}
+    interface Index {
+       Object get(Object key);
+    }
 
-    public final class IndexType {}
+    interface DB {
+       Collector get(byte[] key);
+    }
 
     interface Indexer {
-       void add(Block b);
-       void remove(Block b);
-       void change(Set add, Set remove);
+       /**
+        *  @return The set of <code>IndexedPool.Mapping</code>s
+        *          this index wants to extract from this block.
+        */
+       Set index(Block b);
+
+       /** Set the <code>DB</code> object this <code>Indexer</code>'s
+        *  associated <code>Index</code> object will use for lookups.
+        */
+       void setDB(DB db);
 
        Index getIndex();
-       IndexType getIndexType();
+       Class getIndexType();
     }
 
     /** Get the Index object for a given IndexType.
      *  Equivalent to <code>(Index)getIndices().get(type)</code>.
      */
-    Index getIndex(IndexType type);
+    Index getIndex(Class type);
 
     /** Return a mapping from <code>IndexType</code>s
      *  to <code>Index</code> objects. This map
      *  cannot be modified.
      */
     Map getIndices();
+
+    /** A convenience method to get a <code>Pointer</code> instance
+     *  for this pool. This is defined always to return this:
+     *  <pre>
+     *  ((PointerIndex)getIndex(Pointer.PointerIndex.class)).getPointer(uri)
+     *  </pre>
+     */
+    Pointer getPointer(String uri);
+
+    public final class Mapping {
+       public final byte[] key, value;
+       public Mapping(byte[] k, byte[] v) { key=k; value=v; }
+    }
 }
Index: gzz/lava/gzz/storm/Pointer.java
diff -u gzz/lava/gzz/storm/Pointer.java:1.1 gzz/lava/gzz/storm/Pointer.java:1.2
--- gzz/lava/gzz/storm/Pointer.java:1.1 Sat Aug 24 12:51:36 2002
+++ gzz/lava/gzz/storm/Pointer.java     Sun Dec 22 22:20:58 2002
@@ -28,12 +28,12 @@
  *  See <code>Documentation/Mediaserver</code> for information
  *  about what a pointer is... XXX
  *  <p>
- *  To retrieve a <code>Pointer</code> instance, use the
- *  <code>getPointer()</code> method of <code>IndexedPool</code>.
+ *  To retrieve a <code>Pointer</code> instance,
+ *  use <code>IndexedPool.getPointer()</code>.
  *  @see IndexedPool
  */
 public interface Pointer {
-    /** Get the <code>storm:pointer:</code> URI of this pointer.
+    /** Get the URI of this pointer.
      */
     String getURI();
 
@@ -64,4 +64,13 @@
      */
     void addPointerBlock(BlockId target, Set obsoleteBlocks)
                                                 throws IOException;
+
+
+    /** XXX
+     *  You generally don't want to use this interface, even though you can;
+     *  it is much more convenient to call 
<code>IndexedPool.getPointer()</code>.
+     */
+    interface PointerIndex extends IndexedPool.Index {
+       Pointer getPointer(String uri);
+    }
 }
Index: gzz/lava/gzz/storm/StormPool.java
diff -u gzz/lava/gzz/storm/StormPool.java:1.10 
gzz/lava/gzz/storm/StormPool.java:1.11
--- gzz/lava/gzz/storm/StormPool.java:1.10      Sun Dec 22 21:28:18 2002
+++ gzz/lava/gzz/storm/StormPool.java   Sun Dec 22 22:20:58 2002
@@ -39,13 +39,9 @@
      *  detected until an InputStream retrieved from the Block
      *  is closed.
      *  <p>
-     *  If the block has to be requested from the network,
-     *  <code>null</code> is returned and a new thread is spawned
-     *  that performs the request. When the block becomes available,
-     *  or it becomes known that it cannot be found on the network,
-     *  <code>listener.finished()</code> is called. When this method
-     *  is called again, it will either return a <code>Block</code>
-     *  or throw an exception. [XXX not yet]
+     *  Note: If the block has to be requested from the network,
+     *  this method blocks until it has been loaded!
+     *  For asynchronous loading, see <code>request()</code>.
      *  <p>
      *  Calling <code>getPool()</code> on the returned block may return
      *  a different pool than this: If the block is retrieved from
@@ -54,8 +50,22 @@
      *  @throws FileNotFoundException if the block is not found
      *                                in the pool.
      */
-    Block get(BlockId id/*, JobListener listener*/) 
+    Block get(BlockId id) 
        throws FileNotFoundException, IOException;
+
+    /** Load a block from the network, if it is not available locally.
+     *  If <code>listener</code> is given, it is informed when
+     *  the block has either been loaded, or the pool
+     *  has given up on loading it.
+     *  XXX
+     */
+    void request(BlockId id, BlockListener listener);
+
+    /** Load a block from the network, if it is not available locally.
+     *  XXX
+     *  Equivalent to <code>request(id, null)</code>.
+     */
+    void request(BlockId id);
 
     /** Add a block to this pool.
      *  The data in the block is checked by this class to assure
Index: gzz/lava/gzz/storm/impl/DirPool.java
diff -u gzz/lava/gzz/storm/impl/DirPool.java:1.12 
gzz/lava/gzz/storm/impl/DirPool.java:1.13
--- gzz/lava/gzz/storm/impl/DirPool.java:1.12   Sun Dec 22 21:28:18 2002
+++ gzz/lava/gzz/storm/impl/DirPool.java        Sun Dec 22 22:20:59 2002
@@ -29,7 +29,7 @@
 /** A StormPool storing blocks in individual files in a directory.
  *  File names have the form <code>b_</code><i>idstring</i>.
  */
-public class DirPool extends AbstractPool {
+public class DirPool extends AbstractLocalPool {
 
     /** The directory we store our blocks in.
      */
Index: gzz/lava/gzz/storm/impl/TransientPool.java
diff -u gzz/lava/gzz/storm/impl/TransientPool.java:1.19 
gzz/lava/gzz/storm/impl/TransientPool.java:1.20
--- gzz/lava/gzz/storm/impl/TransientPool.java:1.19     Sun Dec 22 21:28:18 2002
+++ gzz/lava/gzz/storm/impl/TransientPool.java  Sun Dec 22 22:20:59 2002
@@ -30,7 +30,7 @@
 /** A StormPool whose contents are exclusively stored in memory.
  *  Should become an IndexedPool eventually.
  */
-public class TransientPool extends AbstractPool {
+public class TransientPool extends AbstractLocalPool {
     /** The blocks in this pool.
      *  A mapping from <code>BlockId</code> objects
      *  to <code>TransientBlock</code>s.
Index: gzz/lava/gzz/storm/impl/ZipPool.java
diff -u gzz/lava/gzz/storm/impl/ZipPool.java:1.7 
gzz/lava/gzz/storm/impl/ZipPool.java:1.8
--- gzz/lava/gzz/storm/impl/ZipPool.java:1.7    Sun Dec 22 21:28:18 2002
+++ gzz/lava/gzz/storm/impl/ZipPool.java        Sun Dec 22 22:20:59 2002
@@ -7,7 +7,7 @@
 import java.util.*;
 import java.util.zip.*;
 
-public class ZipPool extends AbstractPool {
+public class ZipPool extends AbstractLocalPool {
 
        protected Map blocks = new HashMap();
        protected ZipFile file;



reply via email to

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