public interface ChronicleHash<K,E extends HashEntry<K>,SC extends HashSegmentContext<K,?>,EQC extends ExternalHashQueryContext<K>> extends Closeable
ChronicleMap and ChronicleSet, related to off-heap
memory management and file-mapping. Not usable by itself.| 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. |
boolean |
isOpen()
Tells whether or not this
ChronicleHash (on-heap instance) is open. |
Class<K> |
keyClass() |
long |
longSize() |
EQC |
queryContext(BytesStore keyBytes,
long offset,
long size)
Returns the context to perform arbitrary operations with the given key, provided in the
serialized form.
|
EQC |
queryContext(Data<K> key)
Equivalent to
queryContext(Object), but accepts Data instead of key as
an object. |
EQC |
queryContext(K key)
Returns the context to perform arbitrary operations with the given key in this map.
|
SC |
segmentContext(int segmentIndex)
Returns the context of the segment with the given index.
|
int |
segments()
Returns the number of segments in this
ChronicleHash. |
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)long longSize()
@NotNull EQC queryContext(K key)
try (ExternalHashQueryContext<K> q = hash.queryContext(key)) {
// ... do something
}
See HashQueryContext and MapMethods for a lot of inspiration about using this
functionality.key - the queried keyHashQueryContext,
MapQueryContext,
ExternalHashQueryContext,
MapMethods@NotNull EQC queryContext(Data<K> key)
queryContext(Object), but accepts Data instead of key as
an object. Useful, when you already have Data, calling this method instead of queryContext(Object) might help to avoid unnecessary deserialization.key - the queried key as Data@NotNull EQC queryContext(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 sequenceSC 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.
TODO what about commit guarantees, when ChronicleMap is used with memory-mapped files, if
ChronicleMap/ChronicleSet closed/not?
After this method call behaviour of all methods of ChronicleMap
or ChronicleSet is undefined. Any method call on the map might throw
any exception, or even JVM crash. Shortly speaking, don't call use map closing.
close in interface AutoCloseableclose in interface Closeableboolean isOpen()
ChronicleHash (on-heap instance) is open.true is close() is not yet calledCopyright © 2016. All rights reserved.