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 |
positionOfSlowestConsumer() |
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()
Cursor
getCurrent
in interface Cursor
public int getBufferSize()
Cursor
getBufferSize
in interface Cursor
public long claim()
Cursor
public long claim(int number)
Cursor
protected long claimUpTo(int number)
number
- the maximum number of positions to claim for writing; must be positiveprotected long positionOfSlowestPointer(long minimumPosition)
protected long positionOfSlowestConsumer()
public boolean publish(long position)
Cursor
public long getHighestPublishedPosition(long lowerPosition, long upperPosition)
Cursor
getHighestPublishedPosition
in interface Cursor
lowerPosition
- the lowest potential positionupperPosition
- the highest potential positionpublic PointerBarrier newBarrier()
Cursor
newBarrier
in interface Cursor
public void signalConsumers()
Cursor
signalConsumers
in interface Cursor
public void complete()
Cursor
barriers
will not block on this cursor and
should return a negative number from PointerBarrier.waitFor(long)
.public boolean isComplete()
Cursor
completed
normally.isComplete
in interface Cursor
public Pointer newPointer()
Cursor
stays behind
it on the ring buffer.newPointer
in interface Cursor
public void stayBehind(Pointer... pointers)
DependentOnPointers
stayBehind
in interface DependentOnPointers
pointers
- the pointers that this cursor may not run past in the ring bufferpublic boolean ignore(Pointer pointer)
DependentOnPointers
stayed behind
. This should be called
when the supplied pointer is removed from the ring buffer.ignore
in interface DependentOnPointers
pointer
- the pointer that this cursor may no longer depend uponpublic GarbageCollectingConsumer createGarbageCollectingConsumer(GarbageCollectingConsumer.Collectable collectable)
createGarbageCollectingConsumer
in interface Cursor
Copyright © 2008–2016 JBoss, a division of Red Hat. All rights reserved.