Class QueueIteration<E,T extends Exception>
- java.lang.Object
-
- org.eclipse.rdf4j.common.iteration.AbstractCloseableIteration<E,X>
-
- org.eclipse.rdf4j.common.iteration.LookAheadIteration<E,T>
-
- org.eclipse.rdf4j.common.iteration.QueueIteration<E,T>
-
- All Implemented Interfaces:
AutoCloseable,CloseableIteration<E,T>,Iteration<E,T>
- Direct Known Subclasses:
QueueCursor
public abstract class QueueIteration<E,T extends Exception> extends LookAheadIteration<E,T>
Makes working with a queue easier by adding the methodsdone()andtoss(Exception)and after converting the Exception to the required type usingconvert(Exception).- Author:
- James Leigh
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedQueueIteration(int capacity, boolean fair, WeakReference<?> callerRef)Creates an QueueIteration with the given (fixed) capacity and the specified access policy.protectedQueueIteration(int capacity, WeakReference<?> callerRef)Creates an QueueIteration with the given (fixed) capacity and default access policy.protectedQueueIteration(BlockingQueue<E> queue, WeakReference<?> callerRef)Creates an QueueIteration with the givenBlockingQueueas its backing queue.
It may not be threadsafe to modify or access the givenBlockingQueuefrom other locations.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidcheckException()protected abstract Tconvert(Exception e)Converts an exception from the underlying iteration to an exception of type X.voiddone()Indicates the methodput(Object)will not be called in the queue anymore.EgetNextElement()Returns the next item in the queue, which may be null, or throws an exception.voidhandleClose()Called byAbstractCloseableIteration.close()when it is called for the first time.voidput(E item)Adds another item to the queue, blocking while the queue is full.voidtoss(Exception exception)The next timeLookAheadIteration.next()is called this exception will be thrown.-
Methods inherited from class org.eclipse.rdf4j.common.iteration.LookAheadIteration
hasNext, next, remove
-
Methods inherited from class org.eclipse.rdf4j.common.iteration.AbstractCloseableIteration
close, isClosed
-
-
-
-
Constructor Detail
-
QueueIteration
protected QueueIteration(int capacity, WeakReference<?> callerRef)Creates an QueueIteration with the given (fixed) capacity and default access policy.- Parameters:
capacity- the capacity of this queue
-
QueueIteration
protected QueueIteration(int capacity, boolean fair, WeakReference<?> callerRef)Creates an QueueIteration with the given (fixed) capacity and the specified access policy.- Parameters:
capacity- the capacity of this queuefair- if true then queue accesses for threads blocked on insertion or removal, are processed in FIFO order; if false the access order is unspecified.
-
QueueIteration
protected QueueIteration(BlockingQueue<E> queue, WeakReference<?> callerRef)
Creates an QueueIteration with the givenBlockingQueueas its backing queue.
It may not be threadsafe to modify or access the givenBlockingQueuefrom other locations. This method only enables the defaultArrayBlockingQueueto be overridden.- Parameters:
queue- A BlockingQueue that is not used in other locations, but will be used as the backing Queue implementation for this cursor.
-
-
Method Detail
-
convert
protected abstract T convert(Exception e)
Converts an exception from the underlying iteration to an exception of type X.
-
toss
public void toss(Exception exception)
The next timeLookAheadIteration.next()is called this exception will be thrown. If it is not a QueryEvaluationException or RuntimeException it will be wrapped in a QueryEvaluationException.
-
put
public void put(E item) throws InterruptedException, T extends Exception
Adds another item to the queue, blocking while the queue is full.- Throws:
InterruptedExceptionT extends Exception
-
done
public void done()
Indicates the methodput(Object)will not be called in the queue anymore.
-
getNextElement
public E getNextElement() throws T extends Exception
Returns the next item in the queue, which may be null, or throws an exception.- Specified by:
getNextElementin classLookAheadIteration<E,T extends Exception>- Returns:
- The next element, or null if no more elements are available.
- Throws:
T extends Exception
-
handleClose
public void handleClose() throws T extends ExceptionDescription copied from class:AbstractCloseableIterationCalled byAbstractCloseableIteration.close()when it is called for the first time. This method is only called once on each iteration. By default, this method does nothing.- Overrides:
handleClosein classLookAheadIteration<E,T extends Exception>- Throws:
T extends Exception
-
-