S - This typeK - The location key typepublic abstract class SaveSection<S extends SaveSection<S,K>,K extends IKey<K>>
extends java.lang.Object
implements java.io.Flushable, java.io.Closeable
| Constructor and Description |
|---|
SaveSection(IRegionProvider<K> regionProvider)
Creates a SaveSection with a customized IRegionProvider
|
SaveSection(java.util.List<IRegionProvider<K>> regionProviders)
Creates a SaveSection with a customized IRegionProviders, with each next RegionProvider used as a fallback
in case reading/writing is unsuccessful
|
| Modifier and Type | Method and Description |
|---|---|
java.util.stream.Stream<java.util.Map.Entry<K,java.nio.ByteBuffer>> |
allEntries(boolean ensureUnique)
Gets a
Stream over all the already saved entries. |
java.util.stream.Stream<K> |
allKeys(boolean ensureUnique)
Gets a
Stream over all the already saved keys. |
void |
close() |
void |
flush() |
void |
forAllKeys(CheckedConsumer<? super K,java.io.IOException> cons)
Deprecated.
see
allKeys(boolean) |
boolean |
hasEntry(K key) |
java.util.Optional<java.nio.ByteBuffer> |
load(K key,
boolean createRegion)
Loads/gets a value at a key
This Method is thread safe.
|
void |
save(K key,
java.nio.ByteBuffer value)
Saves/puts a value at a key
This method is thread safe.
|
void |
save(java.util.Map<K,java.nio.ByteBuffer> entries)
Saves/puts multiple values at multiple keys
This method is thread safe.
|
public SaveSection(IRegionProvider<K> regionProvider)
regionProvider - The region providerpublic SaveSection(java.util.List<IRegionProvider<K>> regionProviders)
regionProviders - The region providerspublic void save(K key, java.nio.ByteBuffer value) throws java.io.IOException
key - The keyvalue - The value to savejava.io.IOException - when an unexpected IO error occurspublic void save(java.util.Map<K,java.nio.ByteBuffer> entries) throws java.io.IOException
entries - the keys and values to savejava.io.IOException - when an unexpected IO error occurspublic java.util.Optional<java.nio.ByteBuffer> load(K key, boolean createRegion) throws java.io.IOException
key - The keycreateRegion - if true, a new region file will be created and cached. This is the preferred option.java.io.IOException - when an unexpected IO error occurspublic java.util.stream.Stream<K> allKeys(boolean ensureUnique) throws java.io.IOException
Stream over all the already saved keys.
Keys added while the Stream is being evaluated may be skipped. Keys modified or removed while the Stream
is being evaluated may be skipped or duplicated.
The returned Stream should be closed (using BaseStream.close()) once no longer needed to avoid potential
resource leaks. If not closed, any resources allocated by the Stream may not be freed until the Stream
instance is garbage-collected.
ensureUnique - if false and this SaveSection was created with multiple IRegionProviders,
some keys may be duplicated even if no keys are saved while the Stream is being
evaluated. Setting this parameter to true will prevent duplicate keys as long as no
keys are saved while the Stream is being evaluated, but comes at a substantial performance
cost. It is therefore strongly recommended to set it to false unless your application
cannot deal with duplicate keys.Stream over all already saved keysjava.io.IOException - when an unexpected IO error occurspublic java.util.stream.Stream<java.util.Map.Entry<K,java.nio.ByteBuffer>> allEntries(boolean ensureUnique) throws java.io.IOException
Stream over all the already saved entries.
Keys added while the Stream is being evaluated may be skipped. Keys modified or removed while the Stream
is being evaluated may be skipped or duplicated.
The returned Stream should be closed (using BaseStream.close()) once no longer needed to avoid potential
resource leaks. If not closed, any resources allocated by the Stream may not be freed until the Stream
instance is garbage-collected.
ensureUnique - if false and this SaveSection was created with multiple IRegionProviders,
some keys may be duplicated even if no keys are saved while the Stream is being
evaluated. Setting this parameter to true will prevent duplicate keys as long as no
keys are saved while the Stream is being evaluated, but comes at a substantial performance
cost. It is therefore strongly recommended to set it to false unless your application
cannot deal with duplicate keys.Stream over all already saved entriesjava.io.IOException - when an unexpected IO error occurs@Deprecated public void forAllKeys(CheckedConsumer<? super K,java.io.IOException> cons) throws java.io.IOException
allKeys(boolean)Implementation note: this implementation will sacrifice overall performance for O(1) memory usage in case of many fallback region provider
cons - Consumer that will accept all the existing regionsjava.io.IOException - when an unexpected IO error occurspublic boolean hasEntry(K key) throws java.io.IOException
java.io.IOExceptionpublic void flush()
throws java.io.IOException
flush in interface java.io.Flushablejava.io.IOExceptionpublic void close()
throws java.io.IOException
close in interface java.io.Closeableclose in interface java.lang.AutoCloseablejava.io.IOException