public class SingleProducerCursor extends Object implements Cursor
Pointer that is consuming entries.
If the cursor needs to advance but cannot due to a slow Pointer, then the supplied strategy will
be used. As new positions are published, the supplied WaitStrategy (used by consumers waiting
for this cursor to advance) will be signalled.| Modifier and Type | Field and Description |
|---|---|
protected Pointer |
current |
protected long |
finalPosition |
protected Pointer[] |
stayBehinds |
protected WaitStrategy |
waitStrategy |
| Constructor and Description |
|---|
SingleProducerCursor(int bufferSize,
WaitStrategy waitStrategy) |
| Modifier and Type | Method and Description |
|---|---|
long |
claim()
Claim the next position for writing and publishing.
|
long |
claim(int number)
Claim a batch of positions for writing and publishing.
|
protected long |
claimUpTo(int number)
Claim up to the supplied number of positions.
|
void |
complete()
Signal that no more entries will be written and that the
barriers will not block on this cursor and
should return a negative number from PointerBarrier.waitFor(long). |
GarbageCollectingConsumer |
createGarbageCollectingConsumer(GarbageCollectingConsumer.Collectable collectable) |
int |
getBufferSize()
Get the size of the buffer that this cursor operates against.
|
long |
getCurrent()
Get the current position that can be read.
|
long |
getHighestPublishedPosition(long lowerPosition,
long upperPosition)
Get the highest published position that is equal to or between the supplied lower and upper positions.
|
boolean |
ignore(Pointer pointer)
Ignore the specified pointer that cursor had previously
stayed behind. |
boolean |
isComplete()
Return whether this cursor has
completed normally. |
PointerBarrier |
newBarrier()
Add a new barrier that a consumer can use the wait for the next available positions.
|
Pointer |
newPointer()
Return a new pointer that starts at this cursor's current position, ensuring that this cursor always
stays behind it on the ring buffer. |
protected long |
positionOfSlowestPointer(long minimumPosition) |
boolean |
publish(long position)
Publish the supplied position, making it available for consumers.
|
void |
signalConsumers()
Signal that the consumers should wake up if they are blocked on the barrier.
|
void |
stayBehind(Pointer... pointers)
Ensure that this cursor always remains behind the specified pointer.
|
protected final Pointer current
protected final WaitStrategy waitStrategy
protected volatile long finalPosition
protected volatile Pointer[] stayBehinds
public SingleProducerCursor(int bufferSize,
WaitStrategy waitStrategy)
public long getCurrent()
CursorgetCurrent in interface Cursorpublic int getBufferSize()
CursorgetBufferSize in interface Cursorpublic long claim()
Cursorpublic long claim(int number)
Cursorprotected long claimUpTo(int number)
number - the maximum number of positions to claim for writing; must be positiveprotected long positionOfSlowestPointer(long minimumPosition)
public boolean publish(long position)
Cursorpublic long getHighestPublishedPosition(long lowerPosition,
long upperPosition)
CursorgetHighestPublishedPosition in interface CursorlowerPosition - the lowest potential positionupperPosition - the highest potential positionpublic PointerBarrier newBarrier()
CursornewBarrier in interface Cursorpublic void signalConsumers()
CursorsignalConsumers in interface Cursorpublic void complete()
Cursorbarriers will not block on this cursor and
should return a negative number from PointerBarrier.waitFor(long).public boolean isComplete()
Cursorcompleted normally.isComplete in interface Cursorpublic Pointer newPointer()
Cursorstays behind it on the ring buffer.newPointer in interface Cursorpublic void stayBehind(Pointer... pointers)
DependentOnPointersstayBehind in interface DependentOnPointerspointers - the pointers that this cursor may not run past in the ring bufferpublic boolean ignore(Pointer pointer)
DependentOnPointersstayed behind. This should be called
when the supplied pointer is removed from the ring buffer.ignore in interface DependentOnPointerspointer - the pointer that this cursor may no longer depend uponpublic GarbageCollectingConsumer createGarbageCollectingConsumer(GarbageCollectingConsumer.Collectable collectable)
createGarbageCollectingConsumer in interface CursorCopyright © 2008-2014 JBoss, a division of Red Hat. All Rights Reserved.