T
- the type of items selected by the iteratorpublic class MultithreadedFocusTrackingIterator<T extends Item<?>> extends FocusTrackingIterator<T>
FocusTrackingIterator
. It is identical
to the superclass except that the methods a synchronized. It is used when there is any possibility
that the iterator will be used from multiple threads.
The class is not designed to allow arbitrary multi-threaded operation. For example, one thread
might exhaust the input after another thread has called hasNext()
, causing the first thread
to get no results from a call of next()
. Instead, the synchronization is designed only to
allow a call on getLength()
(caused by an XPath invocation of last()
) to occur
asynchronously with the thread that advances the iterator. This happens specifically when an
xsl:result-document
instruction is executed asynchronously, and the code within
the body of the xsl:result-document
instruction calls last()
. In this situation
the main thread (the one that advances the focus, and spawns new threads for xsl:result-document
)
must be suspended while the value of last()
is computed, which is done by reading the iterator
to completion; when the main thread resumes, there will be a new base iterator positioned over the materialized
sequence that was read into memory as a side-effect of calling last()
.
See bug 3927.
ATOMIZING, GROUNDED, LAST_POSITION_FINDER, LOOKAHEAD
Constructor and Description |
---|
MultithreadedFocusTrackingIterator(SequenceIterator<T> base) |
Modifier and Type | Method and Description |
---|---|
void |
close()
Close the iterator.
|
T |
current()
Get the current value in the sequence (the one returned by the
most recent call on next()).
|
int |
getLength()
Get the position of the last item in the sequence.
|
int |
getProperties()
Get properties of this iterator, as a bit-significant integer.
|
GroundedValue<T> |
getResidue()
Return a GroundedValue containing all the remaining items in the sequence returned by this
SequenceIterator, starting at the current position.
|
int |
getSiblingPosition(NodeInfo node,
NodeTest nodeTest,
int max)
Get the sibling position of a node: specifically, count how many preceding siblings
of a node satisfy the nodetest.
|
SequenceIterator<T> |
getUnderlyingIterator()
Get the underlying iterator
|
boolean |
hasNext()
Determine whether there are more items to come.
|
GroundedValue<T> |
materialize()
Return a GroundedValue containing all the items in the sequence returned by this
SequenceIterator.
|
T |
next()
Get the next item in the sequence.
|
int |
position()
Get the current position.
|
track
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
forEachOrFail
public MultithreadedFocusTrackingIterator(SequenceIterator<T> base)
public SequenceIterator<T> getUnderlyingIterator()
getUnderlyingIterator
in class FocusTrackingIterator<T extends Item<?>>
public T next() throws XPathException
next
in interface SequenceIterator<T extends Item<?>>
next
in class FocusTrackingIterator<T extends Item<?>>
XPathException
- if an error occurs retrieving the next itempublic T current()
current
in interface FocusIterator<T extends Item<?>>
current
in class FocusTrackingIterator<T extends Item<?>>
public int position()
This method does not change the state of the iterator.
position
in interface FocusIterator<T extends Item<?>>
position
in class FocusTrackingIterator<T extends Item<?>>
public int getLength() throws XPathException
getLength
in interface LastPositionFinder
getLength
in interface FocusIterator<T extends Item<?>>
getLength
in class FocusTrackingIterator<T extends Item<?>>
XPathException
- if a failure occurs reading the sequencepublic boolean hasNext()
This method must not be called unless the result of getProperties() on the iterator
includes the bit setting SequenceIterator.LOOKAHEAD
hasNext
in interface LookaheadIterator<T extends Item<?>>
hasNext
in class FocusTrackingIterator<T extends Item<?>>
java.lang.ClassCastException
- if the base iterator does not support lookahead processingpublic GroundedValue<T> materialize() throws XPathException
materialize
in interface SequenceIterator<T extends Item<?>>
materialize
in interface GroundedIterator<T extends Item<?>>
materialize
in class FocusTrackingIterator<T extends Item<?>>
XPathException
- in the cases of subclasses (such as the iterator over a MemoClosure)
which cause evaluation of expressions while materializing the value.java.lang.ClassCastException
- if the iterator does not have the SequenceIterator.GROUNDED
property.public GroundedValue<T> getResidue() throws XPathException
getResidue
in interface GroundedIterator<T extends Item<?>>
getResidue
in class FocusTrackingIterator<T extends Item<?>>
XPathException
- in the cases of subclasses (such as the iterator over a MemoClosure)
which cause evaluation of expressions while materializing the value.java.lang.ClassCastException
- if the iterator does not have the SequenceIterator.GROUNDED
property.public void close()
(Currently, closing an iterator is important only when the data is being "pushed" in another thread. Closing the iterator terminates that thread and means that it needs to do no additional work. Indeed, failing to close the iterator may cause the push thread to hang waiting for the buffer to be emptied.)
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
close
in interface SequenceIterator<T extends Item<?>>
close
in class FocusTrackingIterator<T extends Item<?>>
public int getProperties()
getProperties
in interface SequenceIterator<T extends Item<?>>
getProperties
in class FocusTrackingIterator<T extends Item<?>>
SequenceIterator.GROUNDED
, SequenceIterator.LAST_POSITION_FINDER
,
and SequenceIterator.LOOKAHEAD
. It is always
acceptable to return the value zero, indicating that there are no known special properties.
It is acceptable for the properties of the iterator to change depending on its state.public int getSiblingPosition(NodeInfo node, NodeTest nodeTest, int max)
xsl:apply-templates
select="*"
(which selects a set of sibling nodes) is used in conjunction with patterns
such as match="*[position() mod 2 = 1]
, then calculation of the position of one
node in the sequence of siblings can take advantage of the fact that the position of the
immediately preceding sibling is already known.
This optimization was suggested by the late Sebastian Rahtz, one of Saxon's earliest power users, and it is dedicated to his memory.
getSiblingPosition
in class FocusTrackingIterator<T extends Item<?>>
node
- the starting node, which is assumed to satisfy the node testnodeTest
- the node testmax
- the maximum number of nodes to be countedCopyright (c) 2004-2020 Saxonica Limited. All rights reserved.