gzz-commits
[Top][All Lists]
Advanced

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

[Gzz-commits] storm/org/nongnu/storm Collector.java impl/Asyn...


From: Benja Fallenstein
Subject: [Gzz-commits] storm/org/nongnu/storm Collector.java impl/Asyn...
Date: Mon, 21 Apr 2003 14:15:43 -0400

CVSROOT:        /cvsroot/storm
Module name:    storm
Changes by:     Benja Fallenstein <address@hidden>      03/04/21 14:15:43

Modified files:
        org/nongnu/storm: Collector.java 
        org/nongnu/storm/impl: AsyncSetCollector.java 
                               SimpleSetCollector.java 
        org/nongnu/storm/impl/p2p: P2PPool.java 

Log message:
        A sometimes more convenient way to access Collectors

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/storm/storm/org/nongnu/storm/Collector.java.diff?tr1=1.3&tr2=1.4&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/storm/storm/org/nongnu/storm/impl/AsyncSetCollector.java.diff?tr1=1.3&tr2=1.4&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/storm/storm/org/nongnu/storm/impl/SimpleSetCollector.java.diff?tr1=1.3&tr2=1.4&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/storm/storm/org/nongnu/storm/impl/p2p/P2PPool.java.diff?tr1=1.3&tr2=1.4&r1=text&r2=text

Patches:
Index: storm/org/nongnu/storm/Collector.java
diff -u storm/org/nongnu/storm/Collector.java:1.3 
storm/org/nongnu/storm/Collector.java:1.4
--- storm/org/nongnu/storm/Collector.java:1.3   Mon Apr  7 15:35:58 2003
+++ storm/org/nongnu/storm/Collector.java       Mon Apr 21 14:15:43 2003
@@ -100,6 +100,14 @@
      */
     Collector block();
 
+    /** Return an iterator that blocks when it has gone through all
+     *  elements currently known, but the request has not completed.
+     *  <p>
+     *  XXX(benja): I'm not sure whether this should require
+     *  synchronization or not...
+     */
+    Iterator blockingIterator();
+
     /** Send the elements in this collection to a callback interface
      *  as they arrive.
      *  All elements already in the collection are also sent
Index: storm/org/nongnu/storm/impl/AsyncSetCollector.java
diff -u storm/org/nongnu/storm/impl/AsyncSetCollector.java:1.3 
storm/org/nongnu/storm/impl/AsyncSetCollector.java:1.4
--- storm/org/nongnu/storm/impl/AsyncSetCollector.java:1.3      Thu Apr 17 
04:36:34 2003
+++ storm/org/nongnu/storm/impl/AsyncSetCollector.java  Mon Apr 21 14:15:43 2003
@@ -129,6 +129,46 @@
        return set.iterator();
     }
 
+    public Iterator blockingIterator() {
+       final List queue;
+       synchronized(set) {
+           queue = Collections.synchronizedList(new ArrayList(set));
+       }
+       addCollectionListener(new CollectionListener() {
+               public boolean item(Object item) {
+                   queue.add(item);
+                   queue.notifyAll();
+                   return true;
+               }
+           });
+       return new Iterator() {
+               public boolean hasNext() {
+                   if(!queue.isEmpty())
+                       return true;
+                   try {
+                       queue.wait();
+                   } catch(InterruptedException e) {}
+                   return !queue.isEmpty();
+               }
+               public Object next() {
+                   if(!queue.isEmpty()) {
+                       return queue.remove(0);
+                   }
+                   synchronized(queue) {
+                       try {
+                           queue.wait();
+                       } catch(InterruptedException e) {}
+                   }
+                   // throws NoSuchElementException 
+                   // in the correct case
+                   return queue.remove(0);
+               }
+               public void remove() {
+                   throw new UnsupportedOperationException("modification");
+               }
+           };
+    }
+
     public Object[] toArray() {
        return set.toArray();
     }
Index: storm/org/nongnu/storm/impl/SimpleSetCollector.java
diff -u storm/org/nongnu/storm/impl/SimpleSetCollector.java:1.3 
storm/org/nongnu/storm/impl/SimpleSetCollector.java:1.4
--- storm/org/nongnu/storm/impl/SimpleSetCollector.java:1.3     Mon Apr  7 
16:07:38 2003
+++ storm/org/nongnu/storm/impl/SimpleSetCollector.java Mon Apr 21 14:15:43 2003
@@ -116,6 +116,10 @@
        return set.iterator();
     }
 
+    public Iterator blockingIterator() {
+       return set.iterator();
+    }
+
     public Object[] toArray() {
        return set.toArray();
     }
Index: storm/org/nongnu/storm/impl/p2p/P2PPool.java
diff -u storm/org/nongnu/storm/impl/p2p/P2PPool.java:1.3 
storm/org/nongnu/storm/impl/p2p/P2PPool.java:1.4
--- storm/org/nongnu/storm/impl/p2p/P2PPool.java:1.3    Sat Apr 19 08:20:32 2003
+++ storm/org/nongnu/storm/impl/p2p/P2PPool.java        Mon Apr 21 14:15:43 2003
@@ -60,8 +60,8 @@
        try {
            return cache.get(id);
        } catch(FileNotFoundException _) {
-           Collection c = map.get(id.toString()).block();
-           for(Iterator i=c.iterator(); i.hasNext();) {
+           Collector c = map.get(id.toString());
+           for(Iterator i=c.blockingIterator(); i.hasNext();) {
                String url = (String)i.next();
                URLConnection conn = new URL(url).openConnection();
                BlockOutputStream bos = 




reply via email to

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