|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.eigenbase.runtime.TimeoutQueueIterator
public class TimeoutQueueIterator
Adapter which allows you to iterate over an Iterator with a timeout.
The interface is similar to an Iterator: the hasNext(long)
method tests whether there are more rows, and the next(long) method gets
the next row. Each has a timeout parameter, and throws a QueueIterator.TimeoutException if the timeout is exceeded. There is also a
close(long) method, which you must call.
The class is implemented using a thread which reads from the underlying
iterator and places the results into a QueueIterator. If a method
call times out, the underlying thread will wait for the result of the call
until it completes.
There is no facility to cancel the fetch from the underlying iterator.
| Field Summary | |
|---|---|
private Iterator |
producer
|
protected QueueIterator |
queueIterator
|
private Thread |
thread
|
| Constructor Summary | |
|---|---|
TimeoutQueueIterator(Iterator producer)
|
|
| Method Summary | |
|---|---|
void |
close(long timeoutMillis)
Releases the resources used by this iterator, including killing the underlying thread. |
private void |
doWork()
Reads objects from the producer and writes them into the QueueIterator. |
boolean |
hasNext(long timeoutMillis)
Returns whether the producer has another row, if that can be determined within the timeout interval. |
Object |
next(long timeoutMillis)
Returns the next row from the producer, if it can be fetched within the timeout interval. |
void |
start()
Starts the thread which reads from the consumer. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected final QueueIterator queueIterator
private final Iterator producer
private Thread thread
| Constructor Detail |
|---|
public TimeoutQueueIterator(Iterator producer)
| Method Detail |
|---|
public boolean hasNext(long timeoutMillis)
throws QueueIterator.TimeoutException
timeoutMillis - Millisonds to wait; less than or equal to zero means
don't wait
QueueIterator.TimeoutException - if producer does not answer within
the timeout interval
public Object next(long timeoutMillis)
throws QueueIterator.TimeoutException
QueueIterator.TimeoutException - if producer does not answer within
the timeout intervalpublic void start()
public void close(long timeoutMillis)
timeoutMillis - Timeout while waiting for the underlying thread to
die. Zero means wait forever.private void doWork()
start().
Never throws an exception.
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||