[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Gzz-commits] gzz/lava/gzz/storm CollectionListener.java Coll...
From: |
Benja Fallenstein |
Subject: |
[Gzz-commits] gzz/lava/gzz/storm CollectionListener.java Coll... |
Date: |
Sun, 22 Dec 2002 21:28:18 -0500 |
CVSROOT: /cvsroot/gzz
Module name: gzz
Changes by: Benja Fallenstein <address@hidden> 02/12/22 21:28:18
Modified files:
lava/gzz/storm : CollectionListener.java Collector.java
SetCollector.java StormPool.java
lava/gzz/storm/impl: DirPool.java TransientPool.java
ZipPool.java
Log message:
getIds() uses an asynchronous interface now-- yay!
(Note: This does not mean that any of the implementations
are asynchronous-- the point is that the interface
supports such implementations cleanly.)
CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/lava/gzz/storm/CollectionListener.java.diff?tr1=1.1&tr2=1.2&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/lava/gzz/storm/Collector.java.diff?tr1=1.1&tr2=1.2&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/lava/gzz/storm/SetCollector.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.9&tr2=1.10&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/lava/gzz/storm/impl/DirPool.java.diff?tr1=1.11&tr2=1.12&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/lava/gzz/storm/impl/TransientPool.java.diff?tr1=1.18&tr2=1.19&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/lava/gzz/storm/impl/ZipPool.java.diff?tr1=1.6&tr2=1.7&r1=text&r2=text
Patches:
Index: gzz/lava/gzz/storm/CollectionListener.java
diff -u gzz/lava/gzz/storm/CollectionListener.java:1.1
gzz/lava/gzz/storm/CollectionListener.java:1.2
--- gzz/lava/gzz/storm/CollectionListener.java:1.1 Sun Dec 22 18:39:27 2002
+++ gzz/lava/gzz/storm/CollectionListener.java Sun Dec 22 21:28:18 2002
@@ -4,5 +4,10 @@
public interface CollectionListener {
+ /**
+ * @return Whether this listener wants to
+ * receive further events
+ * from this <code>Collector</code>.
+ */
boolean item(Object item);
}
Index: gzz/lava/gzz/storm/Collector.java
diff -u gzz/lava/gzz/storm/Collector.java:1.1
gzz/lava/gzz/storm/Collector.java:1.2
--- gzz/lava/gzz/storm/Collector.java:1.1 Sun Dec 22 18:39:27 2002
+++ gzz/lava/gzz/storm/Collector.java Sun Dec 22 21:28:18 2002
@@ -4,14 +4,20 @@
/** A <code>Collection</code> representing the results
* of a lookup that may be continuing on another thread.
- *
+ * This is an unmodifiable collection, but until
+ * the lookup has been finished, additional elements
+ * may appear in it.
*/
public interface Collector extends Collection {
/** Get the number of milliseconds since this request was started.
* This may be useful in deciding whether to re-lookup the data.
*/
- int getAge();
+ long getAge();
+
+ /** Return whether the lookup is completed.
+ * If true, this <code>Collection</code> is immutable.
+ */
boolean isReady();
/**
Index: gzz/lava/gzz/storm/SetCollector.java
diff -u gzz/lava/gzz/storm/SetCollector.java:1.1
gzz/lava/gzz/storm/SetCollector.java:1.2
--- gzz/lava/gzz/storm/SetCollector.java:1.1 Sun Dec 22 20:52:38 2002
+++ gzz/lava/gzz/storm/SetCollector.java Sun Dec 22 21:28:18 2002
@@ -5,4 +5,13 @@
/** A <code>Collector</code> which is also a <code>Set</code>.
*/
public interface SetCollector extends Set, Collector {
+
+ /** Same as <code>block()</code>, but with a <code>SetCollector</code>
+ * return value. Since <code>block()</code> always returns
+ * this object, and this object is a <code>SetCollector</code>,
+ * it necessarily returns a <code>SetCollector</code> always.
+ * This method saves us an unnecessary class cast
+ * in some places, resulting in cleaner code.
+ */
+ SetCollector blockSet();
}
Index: gzz/lava/gzz/storm/StormPool.java
diff -u gzz/lava/gzz/storm/StormPool.java:1.9
gzz/lava/gzz/storm/StormPool.java:1.10
--- gzz/lava/gzz/storm/StormPool.java:1.9 Sun Nov 24 11:02:19 2002
+++ gzz/lava/gzz/storm/StormPool.java Sun Dec 22 21:28:18 2002
@@ -92,17 +92,18 @@
* that represents a p2p network may not know the set of ids
* it is able to load.
* <p>
- * If this needs to start a network lookup, it returns
- * the set of ids known at this point (may be empty)
- * and spawns another thread to do the lookup. When new ids
- * become known, <code>listener.newDataArrived()</code>
- * is called. When all available ids have been retrieved,
- * <code>listener.finished()</code> is called.
- * [XXX not yet]
+ * This returns a <code>SetCollector</code> so that
+ * implementations that need to do a network lookup
+ * can spawn a thread to do that. If you want to
+ * block your thread until all ids have been read
+ * from the network, you can write:
+ * <pre>
+ * Set ids = pool.getIds().blockSet();
+ * </pre>
* <p>
* Never returns <code>null</code>.
*/
- Set getIds(/*JobListener listener*/) throws IOException;
+ SetCollector getIds() throws IOException;
// CREATING NEW BLOCKS
@@ -124,7 +125,7 @@
// GETTING POOL NAMES
- /** This is currently unimplemented and probably requires more thought.
+ /** This is currently not implemented and probably requires more thought.
* When the time comes to replace Mediaserver with Storm, we'll see
* how to implement the things currently done through pool names;
* these functions might be resurrected, replaced by something else,
Index: gzz/lava/gzz/storm/impl/DirPool.java
diff -u gzz/lava/gzz/storm/impl/DirPool.java:1.11
gzz/lava/gzz/storm/impl/DirPool.java:1.12
--- gzz/lava/gzz/storm/impl/DirPool.java:1.11 Sat Nov 16 00:59:46 2002
+++ gzz/lava/gzz/storm/impl/DirPool.java Sun Dec 22 21:28:18 2002
@@ -124,7 +124,7 @@
public void delete(Block b) throws IOException {
getFile(b.getId()).delete();
}
- public Set getIds() {
+ public SetCollector getIds() {
HashSet ids = new HashSet();
String[] list = dir.list();
@@ -132,7 +132,7 @@
if(list[i].startsWith("b_"))
ids.add(new BlockId("storm:block:" + list[i].substring(2)));
- return ids;
+ return new SimpleSetCollector(ids);
}
public BlockOutputStream getBlockOutputStream(String contentType)
throws IOException {
Index: gzz/lava/gzz/storm/impl/TransientPool.java
diff -u gzz/lava/gzz/storm/impl/TransientPool.java:1.18
gzz/lava/gzz/storm/impl/TransientPool.java:1.19
--- gzz/lava/gzz/storm/impl/TransientPool.java:1.18 Mon Nov 25 11:12:10 2002
+++ gzz/lava/gzz/storm/impl/TransientPool.java Sun Dec 22 21:28:18 2002
@@ -92,7 +92,9 @@
public void delete(Block b) {
blocks.keySet().remove(b.getId());
}
- public Set getIds() { return blocks.keySet(); }
+ public SetCollector getIds() {
+ return new SimpleSetCollector(new HashSet(blocks.keySet()));
+ }
public BlockOutputStream getBlockOutputStream(String contentType)
throws IOException {
Header822 hdr = new UniqueHeader822();
Index: gzz/lava/gzz/storm/impl/ZipPool.java
diff -u gzz/lava/gzz/storm/impl/ZipPool.java:1.6
gzz/lava/gzz/storm/impl/ZipPool.java:1.7
--- gzz/lava/gzz/storm/impl/ZipPool.java:1.6 Tue Dec 17 10:48:35 2002
+++ gzz/lava/gzz/storm/impl/ZipPool.java Sun Dec 22 21:28:18 2002
@@ -128,8 +128,8 @@
changeZipFile(bid, null, null);
}
- public Set getIds() {
- Set result = new HashSet();
+ public SetCollector getIds() {
+ Set ids = new HashSet();
for (Enumeration i = file.entries(); i.hasMoreElements() ;) {
ZipEntry e = (ZipEntry)i.nextElement();
@@ -139,10 +139,10 @@
continue;
BlockId id = new BlockId("storm:block:" + name.substring(2));
- result.add(id);
+ ids.add(id);
}
- return result;
+ return new SimpleSetCollector(ids);
}
public BlockOutputStream getBlockOutputStream(String contentType)throws