com.bigdata.striterator
Class AbstractChunkedResolverator<E,F,S>

java.lang.Object
  extended by com.bigdata.striterator.AbstractChunkedResolverator<E,F,S>
Type Parameters:
E - The generic type of the elements visited by the source iterator.
F - The generic type of the elements visited by this iterator (the resolved elements).
S - The generic type of the application state object.
All Implemented Interfaces:
ICloseableIterator<F>, Iterator<F>
Direct Known Subclasses:
BigdataSolutionResolverator, BigdataStatementIteratorImpl

public abstract class AbstractChunkedResolverator<E,F,S>
extends Object
implements ICloseableIterator<F>

Wraps an IChunkedIterator and asynchronously resolves chunks.

Version:
$Id: AbstractChunkedResolverator.java 2265 2009-10-26 12:51:06Z thompsonbry $
Author:
Bryan Thompson

Field Summary
protected static boolean DEBUG
          True iff the log level is DEBUG or less.
protected static org.apache.log4j.Logger log
           
protected  S state
          Application specified state object.
 
Constructor Summary
AbstractChunkedResolverator(S state, IChunkedOrderedIterator<E> src, BlockingBuffer<F[]> buffer)
           
 
Method Summary
 void close()
          Closes the iterator, releasing any associated resources.
 boolean hasNext()
           
 F next()
           
 void remove()
           
protected abstract  F[] resolveChunk(E[] chunk)
          Resolves the elements in a source chunk, returning a chunk of resolved elements.
 AbstractChunkedResolverator<E,F,S> start(ExecutorService service)
          Creates and runs a task that will consume chunks from the source iterator, resolve the elements in each chunk, and place the resolved chunks onto the BlockingBuffer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

protected static final org.apache.log4j.Logger log

DEBUG

protected static final boolean DEBUG
True iff the log level is DEBUG or less.


state

protected final S state
Application specified state object.

Constructor Detail

AbstractChunkedResolverator

public AbstractChunkedResolverator(S state,
                                   IChunkedOrderedIterator<E> src,
                                   BlockingBuffer<F[]> buffer)
Parameters:
state - Application specified state (optional).
src - The source iterator (will be closed exhausted or when this iterator is closed).
buffer - The BlockingBuffer on which the resolved chunks will be written by the ChunkConsumerTask and from which this iterator will read those chunks.
Method Detail

start

public AbstractChunkedResolverator<E,F,S> start(ExecutorService service)
Creates and runs a task that will consume chunks from the source iterator, resolve the elements in each chunk, and place the resolved chunks onto the BlockingBuffer.

You MUST invoke this before consuming results from the iterator.

Implementations SHOULD strengthen the return type.

Parameters:
service - The service on which the task will be executed.

resolveChunk

protected abstract F[] resolveChunk(E[] chunk)
Resolves the elements in a source chunk, returning a chunk of resolved elements.

Note: This method is invoked by the ChunkConsumerTask which runs asynchronously.

Parameters:
chunk - The next chunk from the source iterator.
Returns:
The resolved chunk.

hasNext

public boolean hasNext()
Specified by:
hasNext in interface Iterator<F>
Throws:
IllegalStateException - unless start(ExecutorService) has been invoked.

next

public F next()
Specified by:
next in interface Iterator<F>

remove

public void remove()
Specified by:
remove in interface Iterator<F>
Throws:
UnsupportedOperationException

close

public void close()
Description copied from interface: ICloseableIterator
Closes the iterator, releasing any associated resources. This method MAY be invoked safely if the iterator is already closed.

Note: Implementations that support Iterator.remove() MUST NOT eagerly close the iterator when it is exhausted since that would make it impossible to remove the last visited statement. Instead they MUST wait for an explicit ICloseableIterator.close() by the application.

Specified by:
close in interface ICloseableIterator<F>


Copyright © 2006-2009 SYSTAP, LLC. All Rights Reserved.