info.aduna.concurrent.locks
Class LockingIteration<E,X extends Exception>

java.lang.Object
  extended by info.aduna.iteration.CloseableIterationBase<E,X>
      extended by info.aduna.iteration.IterationWrapper<E,X>
          extended by info.aduna.concurrent.locks.LockingIteration<E,X>
All Implemented Interfaces:
CloseableIteration<E,X>, Iteration<E,X>

public class LockingIteration<E,X extends Exception>
extends IterationWrapper<E,X>

An Iteration that holds on to a lock until the Iteration is closed. Upon closing, the underlying Iteration is closed before the lock is released. This iterator closes itself as soon as all elements have been read.


Field Summary
 
Fields inherited from class info.aduna.iteration.IterationWrapper
wrappedIter
 
Constructor Summary
LockingIteration(Lock lock, Iteration<? extends E,X> iter)
          Creates a new LockingIteration.
 
Method Summary
protected  void handleClose()
          Closed this Iteration and also closes the wrapped Iteration if it is a CloseableIteration.
 boolean hasNext()
          Checks whether the wrapped Iteration contains more elements, closing this Iteration when this is not the case.
 E next()
          Returns the next element from the wrapped Iteration.
 void remove()
          Removes the last element that has been returned from the wrapped Iteration.
 
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

LockingIteration

public LockingIteration(Lock lock,
                        Iteration<? extends E,X> iter)
Creates a new LockingIteration.

Parameters:
lock - The lock to release when the itererator is closed, must not be null.
iter - The underlying Iteration, must not be null.
Method Detail

hasNext

public boolean hasNext()
                throws X extends Exception
Description copied from class: IterationWrapper
Checks whether the wrapped Iteration contains more elements, closing this Iteration when this is not the case.

Specified by:
hasNext in interface Iteration<E,X extends Exception>
Overrides:
hasNext in class IterationWrapper<E,X extends Exception>
Returns:
true if the wrapped Iteration contains more elements, false otherwise.
Throws:
X
X extends Exception

next

public E next()
       throws X extends Exception
Description copied from class: IterationWrapper
Returns the next element from the wrapped Iteration.

Specified by:
next in interface Iteration<E,X extends Exception>
Overrides:
next in class IterationWrapper<E,X extends Exception>
Returns:
the next element in the iteration.
Throws:
X extends Exception

remove

public void remove()
            throws X extends Exception
Description copied from class: IterationWrapper
Removes the last element that has been returned from the wrapped Iteration.

Specified by:
remove in interface Iteration<E,X extends Exception>
Overrides:
remove in class IterationWrapper<E,X extends Exception>
Throws:
X extends Exception

handleClose

protected void handleClose()
                    throws X extends Exception
Description copied from class: IterationWrapper
Closed this Iteration and also closes the wrapped Iteration if it is a CloseableIteration.

Overrides:
handleClose in class IterationWrapper<E,X extends Exception>
Throws:
X
X extends Exception


Copyright © 2001-2012 Aduna. All Rights Reserved.