|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Object
|
+--saffron.runtime.QueueIterator
|
+--saffron.runtime.ThreadIterator
ThreadIterator converts 'push' code to 'pull'. You implement
doWork() to call QueueIterator.put(java.lang.Object) with each row, and this class invokes
it in a separate thread. Then the results come out via the familiar Iterator interface. For example,
class ArrayIterator extends ThreadIterator {
Object[] a_;
ArrayIterator(Object[] a) {
this.a_ = a;
start();
}
protected void doWork() {
for (int i = 0; i < a_.length; i++) {
put(a[i]);
}
}
}
Or, more typically, using an anonymous class:
Iterator i = new ThreadIterator() {
int limit;
public ThreadIterator start(int limit) {
this.limit = limit;
return super.start();
}
protected void doWork() {
for (int i = 0; i < limit; i++) {
put(new Integer(i));
}
}
}.start(100);
while (i.hasNext()) {
etc.
}
| Nested Class Summary | |
static class |
ThreadIterator.Test
Test harness for ThreadIterator. |
| Constructor Summary | |
ThreadIterator()
|
|
| Method Summary | |
void |
done(Throwable throwable)
Producer calls done to say that there are no more objects,
setting throwable if there was an error. |
protected abstract void |
doWork()
The implementation should call QueueIterator.put(java.lang.Object) with each row. |
boolean |
hasNext()
|
Iterator |
iterator()
Returns an iterator over the elements in this collection. |
Object |
next()
|
void |
put(Object o)
Producer calls put to add another object (which may be
null). |
void |
remove()
|
void |
run()
|
protected ThreadIterator |
start()
|
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Methods inherited from interface java.util.Iterator |
hasNext, next, remove |
| Constructor Detail |
public ThreadIterator()
| Method Detail |
protected ThreadIterator start()
public Iterator iterator()
IterableIf this method is called twice on the same object, and the object is not modified in between times, the iterators produced may or may not be the same iterator, and may or may not return the elements in the same order, but must return the same objects.
iterator in interface Iterableprotected abstract void doWork()
QueueIterator.put(java.lang.Object) with each row.
public void run()
run in interface Runnablepublic boolean hasNext()
hasNext in interface Iteratorpublic Object next()
next in interface Iteratorpublic void remove()
remove in interface Iteratorpublic void put(Object o)
put to add another object (which may be
null).
public void done(Throwable throwable)
done to say that there are no more objects,
setting throwable if there was an error.
|
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||