public interface ChronicleHash<K,E extends HashEntry<K>,SC extends HashSegmentContext<K,?>,EQC extends ExternalHashQueryContext<K>> extends MapClosable
ChronicleMap and ChronicleSet.| Modifier and Type | Method and Description |
|---|---|
void |
close()
Releases the off-heap memory, used by this hash container and resources, used by replication, if any.
|
File |
file()
Returns the file this hash container mapped to, i.
|
void |
forEachEntry(Consumer<? super E> action)
Performs the given action for each entry in this
ChronicleHash until all entries have been processed or the action throws an Exception. |
boolean |
forEachEntryWhile(Predicate<? super E> predicate)
Checks the given predicate on each entry in this
ChronicleHash until all entries have been processed or the predicate returns false for some entry, or throws an Exception. |
default boolean |
isOpen()
Tells whether or not this
ChronicleHash (on-heap instance) is open. |
Class<K> |
keyClass() |
Type |
keyType() |
long |
longSize()
Returns the number of entries in this store.
|
String |
name()
Returns the name of this
ChronicleHash, configured by ChronicleHashBuilder.name(String), or null, if not configured. |
long |
offHeapMemoryUsed()
Returns the amount of off-heap memory (in bytes), allocated by this
ChronicleHash or shared with with other ChronicleHashes, persisting
to the same file(). |
EQC |
queryContext(net.openhft.chronicle.bytes.BytesStore<?,?> keyBytes,
long offset,
long size)
Returns a context to perform arbitrary operations with the given key, provided in the serialized form.
|
EQC |
queryContext(Data<K> key)
Returns a context to perform arbitrary operations with the given key, provided in
Data form. |
EQC |
queryContext(K key)
Returns a context to perform arbitrary operations with the given key in this store.
|
SC |
segmentContext(int segmentIndex)
Returns a context of the segment with the given index.
|
int |
segments()
Returns the number of segments in this
ChronicleHash. |
String |
toIdentityString()
Returns a
String, useful for identifying this ChronicleHash in debugging, logging, and error reporting. |
isClosed@Nullable File file()
ChronicleHashBuilder.create() call, or null if it
is purely in-memory, i. e. if it is created by ChronicleHashBuilder.create() call.ChronicleMap or ChronicleSet is mapped to, or null if it is not mapped to any fileChronicleHashBuilder.createPersistedTo(File)@Nullable String name()
ChronicleHash, configured by ChronicleHashBuilder.name(String), or null, if not configured.ChronicleMap or ChronicleSet@NotNull String toIdentityString()
String, useful for identifying this ChronicleHash in debugging, logging, and error reporting. Object.toString() of
concrete ChronicleHash subinterfaces, ChronicleMap and ChronicleSet, has to follow Map.toString() and Set.toString() contracts respectively, making it not always useful (or even impossible to use, if this ChronicleHash contains a lot of
entries) for the purposes listed above.
This method return a string of the form:
[ChronicleMap|ChronicleSet]{name=name(), file=file(), identityHashCode=System.identityHashCode(thisChronicleHash)}
This form could be changed in any subsequent Chronicle Map library release (including patch release). The user code shouldn't depend on this
form.
String, useful for identifying this ChronicleHash in debugging, logging, and error reportinglong longSize()
long offHeapMemoryUsed()
ChronicleHash or shared with with other ChronicleHashes, persisting
to the same file().
After close() this method returns 0.
ChronicleHash (in bytes)Type keyType()
@NotNull EQC queryContext(K key)
try (ExternalHashQueryContext<K> q = hash.queryContext(key)) {
// ... do something
}
See documentation to HashQueryContext interface and methods in MapMethods
interface for examples of using contexts. Also see
Working with an entry within a context section in the Chronicle Map tutorial.
key - the queried keyHashQueryContext,
MapQueryContext,
ExternalHashQueryContext,
MapMethods@NotNull EQC queryContext(Data<K> key)
Data form. Equivalent to queryContext(Object), but accepts Data instead of object key. This method is useful, when you already have Data, calling this
method instead of queryContext(Object) might help to avoid unnecessary deserialization.
See documentation to HashQueryContext interface and methods in MapMethods
interface for examples of using contexts. Also see
Working with an entry within a context section in the Chronicle Map tutorial.
key - the queried key as Data@NotNull EQC queryContext(net.openhft.chronicle.bytes.BytesStore<?,?> keyBytes, long offset, long size)
queryContext(Object) and
queryContext(Data) for more information on contexts semantics and usage patterns.keyBytes - the bytes store with the key bytes to queryoffset - actual offset of the key bytes within the given BytesStoresize - length of the key bytes sequence within the given BytesStoreSC segmentContext(int segmentIndex)
segments()- 1.HashSegmentContextint segments()
ChronicleHash.boolean forEachEntryWhile(Predicate<? super E> predicate)
ChronicleHash until all entries have been processed or the predicate returns false for some entry, or throws an Exception. Exceptions thrown by the predicate are relayed to the caller.
The order in which the entries will be processed is unspecified. It might differ from
the order of iteration via Iterator returned by any method of this ChronicleHash or it's collection view.
If the ChronicleHash is empty, this method returns true immediately.
predicate - the predicate to be checked for each entrytrue if the predicate returned true for all entries of the ChronicleHash, false if it returned false for the entryvoid forEachEntry(Consumer<? super E> action)
ChronicleHash until all entries have been processed or the action throws an Exception. Exceptions thrown by the action are relayed to the caller.
The order in which the entries will be processed is unspecified. It might differ from
the order of iteration via Iterator returned by any method of this ChronicleHash or it's collection view.
action - the action to be performed for each entryvoid close()
ChronicleMap or ChronicleSet
instances mapping the same data.
If you won't call this method, memory would be held at least until next garbage
collection. This could be a problem if, for example, you target rare garbage collections, but load and drop ChronicleHashes regularly.
After this method call, all methods, querying the ChronicleHash's entries, longSize() and size()), throw ChronicleHashClosedException. isOpen() returns false, close() itself
returns immediately without effects (i. e. repetitive close(), even from concurrent threads, are safe).
close in interface AutoCloseableclose in interface Closeabledefault boolean isOpen()
ChronicleHash (on-heap instance) is open.true is close() is not yet calledCopyright © 2024. All rights reserved.