public class SingleChronicleQueue extends net.openhft.chronicle.core.io.AbstractCloseable implements RollingChronicleQueue
Modifier and Type | Field and Description |
---|---|
static String |
DISK_SPACE_CHECKER_NAME |
protected boolean |
doubleBuffer |
protected @NotNull net.openhft.chronicle.core.threads.EventLoop |
eventLoop |
protected @NotNull TableStore<SCQMeta> |
metaStore |
protected @NotNull WireStorePool |
pool |
static String |
QUEUE_METADATA_FILE |
protected int |
sourceId |
protected ThreadLocal<ExcerptAppender> |
strongExcerptAppenderThreadLocal |
static String |
SUFFIX |
Modifier | Constructor and Description |
---|---|
protected |
SingleChronicleQueue(@NotNull SingleChronicleQueueBuilder builder) |
Modifier and Type | Method and Description |
---|---|
@NotNull ExcerptAppender |
acquireAppender()
Returns a ExcerptAppender for this ChronicleQueue that is local to the current Thread.
|
<T> void |
addCloseListener(net.openhft.chronicle.core.io.Closeable key) |
WriteLock |
appendLock() |
long |
approximateExcerptsInCycle(int cycle)
Returns a number of excerpts in a cycle.
|
long |
blockSize() |
long |
bufferCapacity() |
boolean |
buffered() |
long |
chunkCount() |
void |
clear()
Removes all the excerpts in the current ChronicleQueue.
|
void |
closeStore(@Nullable SingleChronicleQueueStore store) |
protected @NotNull ExcerptAppender |
constructAppender()
Construct a new
ExcerptAppender . |
long |
countExcerpts(long fromIndex,
long toIndex)
Will give you the number of excerpts between 2 index?s ( as exists on the current file system ).
|
protected void |
createAppenderCondition(@NotNull Condition createAppenderCondition) |
protected @NotNull ExcerptAppender |
createNewAppenderOnceConditionIsMet()
Construct a new
ExcerptAppender once the createAppenderCondition is met. |
@NotNull ExcerptTailer |
createTailer()
Creates and returns a new ExcerptTailer for this ChronicleQueue.
|
@NotNull ExcerptTailer |
createTailer(String id)
Creates and returns a new ExcerptTailer for this ChronicleQueue with the given unique
id . |
int |
cycle() |
int |
cycle(net.openhft.chronicle.core.time.TimeProvider timeProvider) |
protected CycleCalculator |
cycleCalculator(ZoneId zoneId) |
int |
deltaCheckpointInterval()
Returns the Delta Checkpoint Interval for this ChronicleQueue.
|
@NotNull String |
dump()
Creates and returns a new String representation of this ChronicleQueue in YAML-format.
|
void |
dump(@NotNull Writer writer,
long fromIndex,
long toIndex)
Dumps a representation of this ChronicleQueue to the provided
writer in YAML-format. |
@NotNull String |
dumpLastHeader()
Creates and returns a new String representation of this ChronicleQueue's last header in YAML-format.
|
long |
entryCount()
This method creates a tailer and count the number of messages between the start of the queue ( see @link firstIndex() ) and the end.
|
long |
epoch() |
@NotNull net.openhft.chronicle.core.threads.EventLoop |
eventLoop() |
long |
exactExcerptsInCycle(int cycle)
Returns an exact number of excerpts in a cycle available for reading.
|
long |
exceptsPerCycle(int cycle)
Deprecated.
|
@NotNull File |
file()
Returns the base directory where ChronicleQueue stores its data.
|
@NotNull String |
fileAbsolutePath()
Returns the absolute path of the base directory where ChronicleQueue stores its data.
|
protected int |
fileToCycle(File queueFile)
Deprecated.
|
protected void |
finalize() |
int |
firstCycle() |
long |
firstIndex()
Returns the lowest valid index available for this ChronicleQueue, or
Long.MAX_VALUE
if no such index exists. |
int |
indexCount() |
@NotNull net.openhft.chronicle.core.values.LongValue |
indexForId(@NotNull String id) |
int |
indexSpacing() |
long |
lastAcknowledgedIndexReplicated()
when using replication to another host, this is the highest last index that has been confirmed to have been read by all of the remote host(s).
|
void |
lastAcknowledgedIndexReplicated(long newValue)
Sets the last index that has been sent to a remote host.
|
int |
lastCycle() |
long |
lastIndex()
Returns the index of the last non-metadata excerpt written to this ChronicleQueue,
or -1 if the queue is empty.
|
long |
lastIndexReplicated()
when using replication to another host, this is the maximum last index that has been sent to any of the remote host(s).
|
void |
lastIndexReplicated(long indexReplicated)
Sets the last index that has been sent to a remote host.
|
NavigableSet<Long> |
listCyclesBetween(int lowerCycle,
int upperCycle) |
TableStore |
metaStore() |
int |
nextCycle(int cycle,
@NotNull TailerDirection direction)
the next available cycle, no cycle will be created by this method, this method is typically
used by a tailer to jump to the next cycle when the cycles are not adjacent.
|
@NotNull Consumer<net.openhft.chronicle.bytes.BytesRingBufferStats> |
onRingBufferStats() |
long |
overlapSize() |
protected void |
performClose() |
@NotNull QueueLock |
queueLock() |
void |
refreshDirectoryListing()
Refreshes this ChronicleQueue's view of the directory used for storing files.
|
@NotNull RollCycle |
rollCycle()
Returns the
RollCycle for this ChronicleQueue. |
int |
sourceId()
Returns the source id.
|
protected StoreFileListener |
storeFileListener() |
@Nullable SingleChronicleQueueStore |
storeForCycle(int cycle,
long epoch,
boolean createIfAbsent,
SingleChronicleQueueStore oldStore) |
protected @Nullable net.openhft.chronicle.core.values.LongValue |
tableStoreAcquire(CharSequence key,
long index) |
long |
tableStoreGet(CharSequence key) |
void |
tableStorePut(CharSequence key,
long index) |
@NotNull net.openhft.chronicle.core.time.TimeProvider |
time()
Returns the
TimeProvider for this ChronicleQueue. |
@NotNull String |
toString() |
@NotNull net.openhft.chronicle.wire.WireType |
wireType()
Returns the
WireType used for this ChronicleQueue. |
assertCloseable, assertCloseablesClosed, clearUsedByThread, close, createdHere, disableCloseableTracing, disableThreadSafetyCheck, disableThreadSafetyCheck, enableCloseableTracing, gcAndWaitForCloseablesToClose, isClosed, isClosing, isInUserThread, referenceId, resetUsedByThread, shouldPerformCloseInBackground, shouldWaitForClosed, threadSafetyCheck, throwExceptionIfClosed, throwExceptionIfClosedInSetter, unmonitor, waitForCloseablesToClose, waitForClosed, warnAndCloseIfNotClosed
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
dump, methodWriter, methodWriterBuilder, single, singleBuilder, singleBuilder, singleBuilder, singleBuilder
public static final String SUFFIX
public static final String QUEUE_METADATA_FILE
public static final String DISK_SPACE_CHECKER_NAME
@NotNull protected final @NotNull net.openhft.chronicle.core.threads.EventLoop eventLoop
@NotNull protected final @NotNull TableStore<SCQMeta> metaStore
@NotNull protected final @NotNull WireStorePool pool
protected final boolean doubleBuffer
protected int sourceId
protected final ThreadLocal<ExcerptAppender> strongExcerptAppenderThreadLocal
protected SingleChronicleQueue(@NotNull @NotNull SingleChronicleQueueBuilder builder)
protected void createAppenderCondition(@NotNull @NotNull Condition createAppenderCondition)
protected CycleCalculator cycleCalculator(ZoneId zoneId)
public int sourceId()
ChronicleQueue
MessageHistory
The source id is non-negative.
sourceId
in interface ChronicleQueue
public long lastAcknowledgedIndexReplicated()
lastAcknowledgedIndexReplicated
in interface ChronicleQueue
public void lastAcknowledgedIndexReplicated(long newValue)
ChronicleQueue
lastAcknowledgedIndexReplicated
in interface ChronicleQueue
newValue
- last acknowledged index that has been sent to the remote host(s).ChronicleQueue.lastAcknowledgedIndexReplicated()
public void refreshDirectoryListing()
ChronicleQueue
Invoke this method if you delete file from a chronicle-queue directory
The problem solved by this is that we cache the structure of the queue directory in order to reduce file system adds latency. Calling this method, after deleting .cq4 files, will update the internal caches accordingly,
refreshDirectoryListing
in interface ChronicleQueue
public long lastIndexReplicated()
lastIndexReplicated
in interface ChronicleQueue
public void lastIndexReplicated(long indexReplicated)
ChronicleQueue
lastIndexReplicated
in interface ChronicleQueue
indexReplicated
- last index that has been sent to the remote host.ChronicleQueue.lastIndexReplicated()
public void clear()
ChronicleQueue
clear
in interface ChronicleQueue
@NotNull public @NotNull File file()
ChronicleQueue
file
in interface ChronicleQueue
@NotNull public @NotNull String fileAbsolutePath()
ChronicleQueue
This value might be cached, as getAbsolutePath is expensive
fileAbsolutePath
in interface ChronicleQueue
@NotNull public @NotNull String dumpLastHeader()
ChronicleQueue
dumpLastHeader
in interface ChronicleQueue
@NotNull public @NotNull String dump()
ChronicleQueue
dump
in interface ChronicleQueue
public void dump(@NotNull @NotNull Writer writer, long fromIndex, long toIndex)
ChronicleQueue
writer
in YAML-format.
Dumping will be made from the provided (@code fromIndex) (inclusive) to the provided
toIndex
(inclusive).dump
in interface ChronicleQueue
writer
- to write tofromIndex
- first index (inclusive)toIndex
- last index (inclusive)public long chunkCount()
public int indexCount()
indexCount
in interface RollingChronicleQueue
public int indexSpacing()
indexSpacing
in interface RollingChronicleQueue
public long epoch()
epoch
in interface RollingChronicleQueue
@NotNull public @NotNull RollCycle rollCycle()
ChronicleQueue
RollCycle
for this ChronicleQueue.rollCycle
in interface ChronicleQueue
rollCycle
in interface RollingChronicleQueue
RollCycle
for this ChronicleQueueRollCycle
public int deltaCheckpointInterval()
ChronicleQueue
The value returned is always a power of two.
deltaCheckpointInterval
in interface ChronicleQueue
deltaCheckpointInterval
in interface RollingChronicleQueue
public boolean buffered()
@NotNull public @NotNull net.openhft.chronicle.core.threads.EventLoop eventLoop()
@NotNull protected @NotNull ExcerptAppender createNewAppenderOnceConditionIsMet()
ExcerptAppender
once the createAppenderCondition
is met.
This should be called by any sub-classes that require an appender but don't want to use
the thread-local one that can be acquired via acquireAppender()
@NotNull protected @NotNull ExcerptAppender constructAppender()
ExcerptAppender
.
This is protected so sub-classes can override the creation of an appender,
to create a new appender, sub-classes should call createNewAppenderOnceConditionIsMet()
protected StoreFileListener storeFileListener()
@NotNull public @NotNull ExcerptAppender acquireAppender()
ChronicleQueue
An Appender can be used to store new excerpts sequentially to the queue.
An Appender is NOT thread-safe and, in addition to that, confined to be used by the creating thread only.. Sharing an Appender across threads is unsafe and will inevitably lead to errors and unspecified behaviour.
This method returns a ThreadLocal
appender, so does not produce any garbage, hence it's safe to simply call
this method every time an appender is needed.
acquireAppender
in interface ChronicleQueue
@NotNull public @NotNull QueueLock queueLock()
QueueLock
This lock is held while the queue replication cluster is back-filling.
By Back-filling we mean that, as part of the fail-over process a sink, may actually have more data than a source,
hence we need to back copy data from the sinks to the source upon startup.
While we are doing this we lock the queue so that new appenders can not be created.
Queue locks have no impact if you are not using queue replication because the are implemented as a no-op.
public WriteLock appendLock()
WriteLock
that is used to lock appends. This is only used by Queue Enterprise
sink replication handlers. See Queue Enterprise docs for more details.@NotNull public @NotNull ExcerptTailer createTailer(String id)
ChronicleQueue
id
.
The id is used to persistently store the latest index for the Tailer. Any new Tailer with a previously used id will continue where the old one left off. A Tailer is NOT thread-safe. A Tailer can be created by one Thread and might be used by at most one other Thread.. Sharing a Tailer across threads is unsafe and will inevitably lead to errors and unspecified behaviour.
If the provided id
is null
, the Tailer will be unnamed and this is
equivalent to invoking ChronicleQueue.createTailer()
.
createTailer
in interface ChronicleQueue
id
- unique id for a tailer which uses to track where it was up toid
ChronicleQueue.createTailer()
@NotNull public @NotNull net.openhft.chronicle.core.values.LongValue indexForId(@NotNull @NotNull String id)
indexForId
in interface ChronicleQueue
@NotNull public @NotNull ExcerptTailer createTailer()
ChronicleQueue
The tailor is created at the start, so unless you are using named tailors, this method is the same as calling `net.openhft.chronicle.queue.ChronicleQueue#createTailer(java.lang.String).toStart()`
createTailer
in interface ChronicleQueue
ChronicleQueue.createTailer(String)
@Nullable public final @Nullable SingleChronicleQueueStore storeForCycle(int cycle, long epoch, boolean createIfAbsent, SingleChronicleQueueStore oldStore)
storeForCycle
in interface RollingChronicleQueue
cycle
- the cycleepoch
- an epoch offset as the number of number of milliseconds since January
1, 1970, 00:00:00 GMTcreateIfAbsent
- create missing stores if true, or return null if missingWireStore
associated with this cycle
, or null if !createIfAbsent
is false
and absentpublic int nextCycle(int cycle, @NotNull @NotNull TailerDirection direction) throws ParseException
RollingChronicleQueue
nextCycle
in interface RollingChronicleQueue
cycle
- the current cycledirection
- the directionParseException
@Deprecated public long exceptsPerCycle(int cycle)
approximateExcerptsInCycle(int)
or exactExcerptsInCycle(int)
should be called.public long approximateExcerptsInCycle(int cycle)
public long exactExcerptsInCycle(int cycle)
public long countExcerpts(long fromIndex, long toIndex)
countExcerpts
in interface RollingChronicleQueue
fromIndex
- the lower indextoIndex
- the higher indexIllegalStateException
- if we are not able to read the chronicle filespublic NavigableSet<Long> listCyclesBetween(int lowerCycle, int upperCycle) throws ParseException
ParseException
public <T> void addCloseListener(net.openhft.chronicle.core.io.Closeable key)
protected void performClose()
performClose
in class net.openhft.chronicle.core.io.AbstractCloseable
protected void finalize() throws Throwable
public final void closeStore(@Nullable @Nullable SingleChronicleQueueStore store)
public final int cycle()
cycle
in interface RollingChronicleQueue
public final int cycle(net.openhft.chronicle.core.time.TimeProvider timeProvider)
public long firstIndex()
ChronicleQueue
Long.MAX_VALUE
if no such index exists.firstIndex
in interface ChronicleQueue
Long.MAX_VALUE
if no such index existspublic long lastIndex()
ChronicleQueue
The value returned by this method will not be reliable in the event the queue is being written to concurrently, as subsequent excerpts may have been written by the time it is returned.
lastIndex
in interface ChronicleQueue
public long entryCount()
entryCount
in interface RollingChronicleQueue
public int firstCycle()
firstCycle
in interface RollingChronicleQueue
public int lastCycle()
lastCycle
in interface RollingChronicleQueue
@Deprecated protected int fileToCycle(File queueFile)
@NotNull public @NotNull Consumer<net.openhft.chronicle.bytes.BytesRingBufferStats> onRingBufferStats()
public long blockSize()
public long overlapSize()
@NotNull public @NotNull net.openhft.chronicle.wire.WireType wireType()
ChronicleQueue
WireType
used for this ChronicleQueue.
For example, the WireType could be WireTypes.TEXT or WireTypes.BINARY.
wireType
in interface ChronicleQueue
WireType
public long bufferCapacity()
@NotNull public @NotNull String toString()
toString
in class net.openhft.chronicle.core.io.AbstractCloseable
@NotNull public @NotNull net.openhft.chronicle.core.time.TimeProvider time()
ChronicleQueue
TimeProvider
for this ChronicleQueue.time
in interface ChronicleQueue
TimeProvider
for this ChronicleQueueTimeProvider
public TableStore metaStore()
public void tableStorePut(CharSequence key, long index)
@Nullable protected @Nullable net.openhft.chronicle.core.values.LongValue tableStoreAcquire(CharSequence key, long index)
public long tableStoreGet(CharSequence key)
Copyright © 2022. All rights reserved.