public interface ChronicleQueue
extends net.openhft.chronicle.core.io.Closeable
Using non-heap storage options Chronicle provides a processing environment where applications does not suffer from GarbageCollection. GarbageCollection (GC) may slow down your critical operations non-deterministically at any time.. In order to avoid non-determinism and escape from GC delays off-heap memory solutions are addressed. The main idea is to manage your memory manually so does not suffer from GC. Chronicle behaves like a management interface over off-heap memory so you can build your own solutions over it.
Chronicle uses RandomAccessFiles while managing memory and this choice brings lots of possibility. Random access files permit non-sequential, or random, access to a file's contents. To access a file randomly, you open the file, seek a particular location, and read from or writeBytes to that file. RandomAccessFiles can be seen as "large" C-type byte arrays that you can access any random index "directly" using pointers. File portions can be used as ByteBuffers if the portion is mapped into memory.
ChronicleQueue
(now in the specific sense) is the main interface for management and
can be seen as the "Collection class" of the Chronicle environment. You will reserve a
portion of memory and then put/fetch/update records using the ChronicleQueue
interface.
ExcerptCommon
is the main data container in a ChronicleQueue
, each Chronicle
is composed of Excerpts. Putting data to a queue means starting a new Excerpt, writing data into
it and finishing the Excerpt at the upper.
While ExcerptCommon
is a generic purpose container allowing for remote access, it also
has more specialized counterparts for sequential operations. See ExcerptTailer
and ExcerptAppender
Modifier and Type | Method and Description |
---|---|
@NotNull ExcerptAppender |
acquireAppender()
Returns a ExcerptAppender for this ChronicleQueue that is local to the current Thread.
|
void |
clear()
Removes all the excerpts in the current ChronicleQueue.
|
@NotNull ExcerptTailer |
createTailer()
Creates and returns a new ExcerptTailer for this ChronicleQueue.
|
default @NotNull ExcerptTailer |
createTailer(String id)
Creates and returns a new ExcerptTailer for this ChronicleQueue with the given unique
id . |
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.
|
default void |
dump(@NotNull OutputStream stream,
long fromIndex,
long toIndex)
Dumps a representation of this ChronicleQueue to the provided
stream in YAML-format. |
void |
dump(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.
|
@NotNull File |
file()
Returns the base directory where ChronicleQueue stores its data.
|
default @NotNull String |
fileAbsolutePath()
Returns the absolute path of the base directory where ChronicleQueue stores its data.
|
long |
firstIndex()
Returns the lowest valid index available for this ChronicleQueue, or
Long.MAX_VALUE
if no such index exists. |
default net.openhft.chronicle.core.values.LongValue |
indexForId(String id) |
long |
lastAcknowledgedIndexReplicated()
Returns the last index that was replicated and acknowledged by all remote hosts.
|
void |
lastAcknowledgedIndexReplicated(long lastAcknowledgedIndexReplicated)
Sets the last index that has been sent to a remote host.
|
long |
lastIndex()
Returns the index of the last non-metadata excerpt written to this ChronicleQueue,
or -1 if the queue is empty.
|
long |
lastIndexReplicated()
Returns the last index that was replicated to a remote host.
|
void |
lastIndexReplicated(long lastIndex)
Sets the last index that has been sent to a remote host.
|
default <T> T |
methodWriter(@NotNull Class<T> tClass,
Class... additional)
Creates and returns a new writer proxy for the given interface
tclass and the given additional
interfaces. |
default <T> @NotNull net.openhft.chronicle.wire.VanillaMethodWriterBuilder<T> |
methodWriterBuilder(@NotNull Class<T> tClass)
Creates and returns a new writer proxy for the given interface
tclass . |
void |
refreshDirectoryListing()
Refreshes this ChronicleQueue's view of the directory used for storing files.
|
@NotNull RollCycle |
rollCycle()
Returns the
RollCycle for this ChronicleQueue. |
static @NotNull ChronicleQueue |
single(@NotNull String pathName)
Creates and returns a new
ChronicleQueue that will be backed by
files located in the directory named by the provided pathName . |
static @NotNull SingleChronicleQueueBuilder |
singleBuilder()
Creates and returns a new
SingleChronicleQueueBuilder . |
static @NotNull SingleChronicleQueueBuilder |
singleBuilder(@NotNull File path)
Creates and returns a new
SingleChronicleQueueBuilder that will
be pre-configured to use files located in the directory of the
provided path . |
static @NotNull SingleChronicleQueueBuilder |
singleBuilder(@NotNull Path path)
Creates and returns a new
SingleChronicleQueueBuilder that will
be pre-configured to use files located in the directory of the
provided path . |
static @NotNull SingleChronicleQueueBuilder |
singleBuilder(@NotNull String pathName)
Creates and returns a new
SingleChronicleQueueBuilder that will
be pre-configured to use files located in the directory named by the
provided pathName . |
int |
sourceId()
Returns the source id.
|
net.openhft.chronicle.core.time.TimeProvider |
time()
Returns the
TimeProvider for this ChronicleQueue. |
@NotNull net.openhft.chronicle.wire.WireType |
wireType()
Returns the
WireType used for this ChronicleQueue. |
@NotNull static @NotNull ChronicleQueue single(@NotNull @NotNull String pathName)
ChronicleQueue
that will be backed by
files located in the directory named by the provided pathName
.pathName
- of the directory to use for storing the queueChronicleQueue
that will be stored
in the directory given by the provided pathName
NullPointerException
- if the provided pathName
is null
.@NotNull static @NotNull SingleChronicleQueueBuilder singleBuilder()
SingleChronicleQueueBuilder
.
The builder can be used to build a ChronicleQueue.
SingleChronicleQueueBuilder
@NotNull static @NotNull SingleChronicleQueueBuilder singleBuilder(@NotNull @NotNull String pathName)
SingleChronicleQueueBuilder
that will
be pre-configured to use files located in the directory named by the
provided pathName
.pathName
- of the directory to pre-configure for storing the queueSingleChronicleQueueBuilder
that will
be pre-configured to use files located in the directory named by the
provided pathName
NullPointerException
- if the provided pathName
is null
.@NotNull static @NotNull SingleChronicleQueueBuilder singleBuilder(@NotNull @NotNull File path)
SingleChronicleQueueBuilder
that will
be pre-configured to use files located in the directory of the
provided path
.path
- of the directory to pre-configure for storing the queueSingleChronicleQueueBuilder
that will
be pre-configured to use files located in the directory named by the
provided pathName
NullPointerException
- if the provided path
is null
.@NotNull static @NotNull SingleChronicleQueueBuilder singleBuilder(@NotNull @NotNull Path path)
SingleChronicleQueueBuilder
that will
be pre-configured to use files located in the directory of the
provided path
.path
- of the directory to pre-configure for storing the queueSingleChronicleQueueBuilder
that will
be pre-configured to use files located in the directory named by the
provided pathName
NullPointerException
- if the provided path
is null
.@NotNull @NotNull ExcerptTailer createTailer()
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(String)
@NotNull default @NotNull ExcerptTailer createTailer(String id)
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 createTailer()
.
id
- unique id for a tailer which uses to track where it was up toid
createTailer()
default net.openhft.chronicle.core.values.LongValue indexForId(String id)
@NotNull @NotNull ExcerptAppender acquireAppender()
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.
long firstIndex()
Long.MAX_VALUE
if no such index exists.Long.MAX_VALUE
if no such index existslong lastIndex()
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.
@NotNull @NotNull net.openhft.chronicle.wire.WireType wireType()
WireType
used for this ChronicleQueue.
For example, the WireType could be WireTypes.TEXT or WireTypes.BINARY.
WireType
void clear()
@NotNull @NotNull File file()
@NotNull default @NotNull String fileAbsolutePath()
This value might be cached, as getAbsolutePath is expensive
@NotNull @NotNull String dump()
void dump(Writer writer, long fromIndex, long toIndex)
writer
in YAML-format.
Dumping will be made from the provided (@code fromIndex) (inclusive) to the provided
toIndex
(inclusive).writer
- to write tofromIndex
- first index (inclusive)toIndex
- last index (inclusive)NullPointerException
- if the provided writer
is null
default void dump(@NotNull @NotNull OutputStream stream, long fromIndex, long toIndex)
stream
in YAML-format.
Dumping will be made from the provided (@code fromIndex) (inclusive) to the provided
toIndex
(inclusive).stream
- to write tofromIndex
- first index (inclusive)toIndex
- last index (inclusive)NullPointerException
- if the provided writer
is null
int sourceId()
MessageHistory
The source id is non-negative.
@NotNull default <T> T methodWriter(@NotNull @NotNull Class<T> tClass, Class... additional)
tclass
and the given additional
interfaces.
When methods are invoked on the returned T object, messages will be put in the queue. A method writer is NOT thread-safe and, in addition to that, confined to be used by the creating thread only.. Sharing a method writer across threads is unsafe and will inevitably lead to errors and unspecified behaviour.
T
- type parameter of the main interfacetClass
- of the main interface to be implementedadditional
- interfaces to be implementedtclass
and the given additional
interfacesNullPointerException
- if any of the provided parameters are null
.@NotNull default <T> @NotNull net.openhft.chronicle.wire.VanillaMethodWriterBuilder<T> methodWriterBuilder(@NotNull @NotNull Class<T> tClass)
tclass
.
When methods are invoked on the returned T object, messages will be put in the queue.
A method writer is NOT thread-safe and, in addition to that, confined to be used by the creating thread only.. Sharing a method writer across threads is unsafe and will inevitably lead to errors and unspecified behaviour.
T
- type parameter of the main interfacetClass
- of the main interface to be implementedtclass
NullPointerException
- if the provided parameter is null
.net.openhft.chronicle.core.time.TimeProvider time()
TimeProvider
for this ChronicleQueue.TimeProvider
for this ChronicleQueueTimeProvider
int deltaCheckpointInterval()
The value returned is always a power of two.
long lastIndexReplicated()
This method is only applicable for replicating queues.
long lastAcknowledgedIndexReplicated()
This method is only applicable for replicating queues.
void lastIndexReplicated(long lastIndex)
lastIndex
- last index that has been sent to the remote host.lastIndexReplicated()
void lastAcknowledgedIndexReplicated(long lastAcknowledgedIndexReplicated)
lastAcknowledgedIndexReplicated
- last acknowledged index that has been sent to the remote host(s).lastAcknowledgedIndexReplicated()
void refreshDirectoryListing()
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,
@NotNull @NotNull String dumpLastHeader()
Copyright © 2022. All rights reserved.