Class PipedRDFIterator<T>
- java.lang.Object
-
- org.apache.jena.riot.lang.PipedRDFIterator<T>
-
- Type Parameters:
T- The type of the RDF primitive, should be one ofTriple,Quad, orTuple<Node>
- All Implemented Interfaces:
java.util.Iterator<T>,org.apache.jena.atlas.lib.Closeable
public class PipedRDFIterator<T> extends java.lang.Object implements java.util.Iterator<T>, org.apache.jena.atlas.lib.CloseableA
PipedRDFIteratorshould be connected to aPipedRDFStreamimplementation; the piped iterator then provides whatever RDF primitives are written to thePipedRDFStreamTypically, data is read from a
PipedRDFIteratorby one thread (the consumer) and data is written to the correspondingPipedRDFStreamby some other thread (the producer). Attempting to use both objects from a single thread is not recommended, as it may deadlock the thread. ThePipedRDFIteratorcontains a buffer, decoupling read operations from write operations, within limits.Inspired by Java's
PipedInputStreamandPipedOutputStream- See Also:
PipedTriplesStream,PipedQuadsStream,PipedTuplesStream
-
-
Field Summary
Fields Modifier and Type Field Description static intDEFAULT_BUFFER_SIZEConstant for default buffer sizestatic intDEFAULT_MAX_POLLSConstant for max number of failed poll attempts before the producer will be declared as deadstatic intDEFAULT_POLL_TIMEOUTConstant for default poll timeout in milliseconds, used to stop the consumer deadlocking in certain circumstances
-
Constructor Summary
Constructors Constructor Description PipedRDFIterator()Creates a new piped RDF iterator with the default buffer size ofDEFAULT_BUFFER_SIZE.PipedRDFIterator(int bufferSize)Creates a new piped RDF iteratorPipedRDFIterator(int bufferSize, boolean fair)Creates a new piped RDF iteratorPipedRDFIterator(int bufferSize, boolean fair, int pollTimeout, int maxPolls)Creates a new piped RDF iterator
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()May be called by the consumer when it is finished reading from the iterator, if the producer thread has not finished it will receive an error the next time it tries to write to the iteratorjava.lang.StringgetBaseIri()Gets the most recently seen Base IRIPrefixMapgetPrefixes()Gets the prefix map which contains the prefixes seen so far in the streambooleanhasNext()Tnext()voidremove()
-
-
-
Field Detail
-
DEFAULT_BUFFER_SIZE
public static final int DEFAULT_BUFFER_SIZE
Constant for default buffer size- See Also:
- Constant Field Values
-
DEFAULT_POLL_TIMEOUT
public static final int DEFAULT_POLL_TIMEOUT
Constant for default poll timeout in milliseconds, used to stop the consumer deadlocking in certain circumstances- See Also:
- Constant Field Values
-
DEFAULT_MAX_POLLS
public static final int DEFAULT_MAX_POLLS
Constant for max number of failed poll attempts before the producer will be declared as dead- See Also:
- Constant Field Values
-
-
Constructor Detail
-
PipedRDFIterator
public PipedRDFIterator()
Creates a new piped RDF iterator with the default buffer size ofDEFAULT_BUFFER_SIZE.Buffer size must be chosen carefully in order to avoid performance problems, if you set the buffer size too low you will experience a lot of blocked calls so it will take longer to consume the data from the iterator. For best performance the buffer size should be at least 10% of the expected input size though you may need to tune this depending on how fast your consumer thread is.
-
PipedRDFIterator
public PipedRDFIterator(int bufferSize)
Creates a new piped RDF iteratorBuffer size must be chosen carefully in order to avoid performance problems, if you set the buffer size too low you will experience a lot of blocked calls so it will take longer to consume the data from the iterator. For best performance the buffer size should be roughly 10% of the expected input size though you may need to tune this depending on how fast your consumer thread is.
- Parameters:
bufferSize- Buffer size
-
PipedRDFIterator
public PipedRDFIterator(int bufferSize, boolean fair)Creates a new piped RDF iteratorBuffer size must be chosen carefully in order to avoid performance problems, if you set the buffer size too low you will experience a lot of blocked calls so it will take longer to consume the data from the iterator. For best performance the buffer size should be roughly 10% of the expected input size though you may need to tune this depending on how fast your consumer thread is.
The fair parameter controls whether the locking policy used for the buffer is fair. When enabled this reduces throughput but also reduces the chance of thread starvation. This likely need only be set to
trueif there will be multiple consumers.- Parameters:
bufferSize- Buffer sizefair- Whether the buffer should use a fair locking policy
-
PipedRDFIterator
public PipedRDFIterator(int bufferSize, boolean fair, int pollTimeout, int maxPolls)Creates a new piped RDF iteratorBuffer size must be chosen carefully in order to avoid performance problems, if you set the buffer size too low you will experience a lot of blocked calls so it will take longer to consume the data from the iterator. For best performance the buffer size should be roughly 10% of the expected input size though you may need to tune this depending on how fast your consumer thread is.
The
fairparameter controls whether the locking policy used for the buffer is fair. When enabled this reduces throughput but also reduces the chance of thread starvation. This likely need only be set totrueif there will be multiple consumers.The
pollTimeoutparameter controls how long each poll attempt waits for data to be produced. This prevents the consumer thread from blocking indefinitely and allows it to detect various potential deadlock conditions e.g. dead producer thread, another consumer closed the iterator etc. and errors out accordingly. It is unlikely that you will ever need to adjust this from the default value provided byDEFAULT_POLL_TIMEOUT.The
maxPollsparameter controls how many poll attempts will be made by a single consumer thread within the context of a single call tohasNext()before the iterator declares the producer to be dead and errors out accordingly. You may need to adjust this if you have a slow producer thread or many consumer threads.- Parameters:
bufferSize- Buffer sizefair- Whether the buffer should use a fair locking policypollTimeout- Poll timeout in millisecondsmaxPolls- Max poll attempts
-
-
Method Detail
-
hasNext
public boolean hasNext()
- Specified by:
hasNextin interfacejava.util.Iterator<T>
-
remove
public void remove()
- Specified by:
removein interfacejava.util.Iterator<T>
-
getBaseIri
public java.lang.String getBaseIri()
Gets the most recently seen Base IRI- Returns:
- Base IRI
-
getPrefixes
public PrefixMap getPrefixes()
Gets the prefix map which contains the prefixes seen so far in the stream- Returns:
- Prefix Map
-
close
public void close()
May be called by the consumer when it is finished reading from the iterator, if the producer thread has not finished it will receive an error the next time it tries to write to the iterator- Specified by:
closein interfaceorg.apache.jena.atlas.lib.Closeable
-
-