org.openrdf.cursor
Class QueueCursor<E>

java.lang.Object
  extended by info.aduna.iteration.CloseableIterationBase<E,X>
      extended by info.aduna.iteration.LookAheadIteration<E,QueryEvaluationException>
          extended by org.openrdf.cursor.QueueCursor<E>
All Implemented Interfaces:
CloseableIteration<E,QueryEvaluationException>, Iteration<E,QueryEvaluationException>

public class QueueCursor<E>
extends LookAheadIteration<E,QueryEvaluationException>

Makes working with a queue easier by adding the methods done() and toss(Exception) and automatically converting the exception into a StoreException with an appropriate stack trace.

Author:
James Leigh

Constructor Summary
QueueCursor(int capacity)
          Creates an QueueCursor with the given (fixed) capacity and default access policy.
QueueCursor(int capacity, boolean fair)
          Creates an QueueCursor with the given (fixed) capacity and the specified access policy.
 
Method Summary
 void checkException()
           
 void done()
          Indicates the method put(Object) will not be called in the queue anymore.
 E getNextElement()
          Returns the next item in the queue or throws an exception.
 void handleClose()
           
 void put(E st)
          Adds another item to the queue, blocking while the queue is full.
 void toss(Exception exception)
          The next time LookAheadIteration.next() is called this exception will be thrown.
 
Methods inherited from class info.aduna.iteration.LookAheadIteration
hasNext, next, remove
 
Methods inherited from class info.aduna.iteration.CloseableIterationBase
close, isClosed
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

QueueCursor

public QueueCursor(int capacity)
Creates an QueueCursor with the given (fixed) capacity and default access policy.

Parameters:
capacity - the capacity of this queue

QueueCursor

public QueueCursor(int capacity,
                   boolean fair)
Creates an QueueCursor with the given (fixed) capacity and the specified access policy.

Parameters:
capacity - the capacity of this queue
fair - if true then queue accesses for threads blocked on insertion or removal, are processed in FIFO order; if false the access order is unspecified.
Method Detail

toss

public void toss(Exception exception)
The next time LookAheadIteration.next() is called this exception will be thrown. If it is not a StoreException or RuntimeException it will be wrapped in a StoreException.


put

public void put(E st)
         throws InterruptedException
Adds another item to the queue, blocking while the queue is full.

Throws:
InterruptedException

done

public void done()
Indicates the method put(Object) will not be called in the queue anymore.


getNextElement

public E getNextElement()
                 throws QueryEvaluationException
Returns the next item in the queue or throws an exception.

Specified by:
getNextElement in class LookAheadIteration<E,QueryEvaluationException>
Throws:
QueryEvaluationException

handleClose

public void handleClose()
                 throws QueryEvaluationException
Overrides:
handleClose in class LookAheadIteration<E,QueryEvaluationException>
Throws:
QueryEvaluationException

checkException

public void checkException()
                    throws QueryEvaluationException
Throws:
QueryEvaluationException


Copyright © 2004-2011 James Leigh Services Inc.. All Rights Reserved.