public class RingBufferControlMulticaster extends Object
This is a helper class for managing a set of RingBufferControl
s for use in a "single-publisher to multi-consumer" thread configuration
where everything published is "multicast" to all consumers.
Constructor and Description |
---|
RingBufferControlMulticaster(int numberOfSubscribers,
int sizePowerOfTwo) |
Modifier and Type | Method and Description |
---|---|
long |
claim(int requestedNumberOfSlots)
This is used by the publishing thread to claim the given number of entries
in the buffer all of the underlying
RingBufferControl s. |
RingBufferConsumerControl |
get(int index)
This will retrieve the
RingBufferControl that corresponds to the
index given. |
int |
index(long sequence)
This method will convert the sequence to an index of a ring buffer.
|
boolean |
isShutdown()
Once the publisher calls
RingBufferControl.publishStop() and the
consumer acquires it this method will return true . |
void |
publish(long sequence)
Once the publisher has readied the buffer entries that were claimed, this method
allows the subscribers to be notified that they are ready.
|
long |
publishStop()
The
RingBufferControl can ONLY be stopped from the publish side. |
public RingBufferControlMulticaster(int numberOfSubscribers, int sizePowerOfTwo) throws IllegalArgumentException
IllegalArgumentException
public RingBufferConsumerControl get(int index)
RingBufferControl
that corresponds to the
index given. This is the way a particular subscriber should retrieve its
corresponding RingBufferControl
.public long claim(int requestedNumberOfSlots)
RingBufferControl
s. The sequence
returned should be supplied to the publish(long)
command once the publisher thread has prepared the
entries.requestedNumberOfSlots
- is the number of entries in the buffer we need
to wait for to be open.RingBufferControl.publish(long)
or the RingBufferConsumerControl.index(long)
methods.public void publish(long sequence)
sequence
- is the sequence returned from the claim(int)
call.public long publishStop()
The RingBufferControl
can ONLY be stopped from the publish side. The publisher needs to call publishStop to stop the consumer. Once the
consumer reaches this point in the sequence, the consumer will receive a RingBufferConsumerControl.ACQUIRE_STOP_REQUEST
returned from either
RingBufferConsumerControl.availableTo()
or RingBufferConsumerControl.tryAvailableTo()
.
Once that happens the RingBufferConsumerControl.isShutdown()
will return true
on both the publisher and consumer sides.
public int index(long sequence)
public boolean isShutdown()
RingBufferControl.publishStop()
and the
consumer acquires it this method will return true
. It will
also return true
up until the first sequence is retrieved
by a consumer. It will return false
at all other times.Copyright © 2018. All rights reserved.