-
- All Superinterfaces:
java.lang.AutoCloseable,java.io.Closeable,java.io.Flushable
- All Known Implementing Classes:
DiskStore,MemoryStore
public interface Store extends java.io.Closeable, java.io.FlushableA repository of binary data entries each identified by a string key. Each entry has a metadata block and a data stream. An entry's metadata block and data stream can be accessed by aStore.Viewerand modified by anStore.Editor. An entry can have at most one active editor but can have multiple concurrent viewers. No data written through an editor is visible to subsequently opened viewers unlesscommitted. A viewer sees a consistent snapshot of the entry as perceived at the time it was opened at.A store may bound its size by automatic eviction of entries, possibly in background. The size bound is not strict. A store's
size()might temporarily exceed its bound in case the store is being actively expanded while eviction is in progress. Additionally, a store's size doesn't include the overhead of the underlying filesystem or any metadata the store itself uses for indexing purposes. Thus, a store'smaxSize()is not exact and might be slightly exceeded as necessary.Entries on a store are volatile. It is not guaranteed that an entry can be
viewedany time, even if immediately, after it has beencommitted.Functions that are expected to be called frequently have two variants: one synchronous, and another asynchronous variant that takes an additional
Executorparameter. The former has a default implementation that calls the latter and waits for the result. The executor parameter only expresses caller's preferred asynchronous execution strategy, and may be ignored by the store if seen fit. The executor parameter can beRunnable::runif same-thread execution is preferred.Storeis thread-safe and is suitable for concurrent use.
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static interfaceStore.EditorWrites an entry's metadata block and data stream.static interfaceStore.EntryReaderA reader for an entry's data stream.static interfaceStore.EntryWriterA writer for an entry's data stream.static interfaceStore.ViewerReads an entry's metadata block and data stream.
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description voidclear()Removes all entries from this store.voidclose()Closes this store.voiddispose()Atomically clears and closes this store.default java.util.Optional<Store.Editor>edit(java.lang.String key)Synchronous variant ofedit(String, Executor).java.util.concurrent.CompletableFuture<java.util.Optional<Store.Editor>>edit(java.lang.String key, java.util.concurrent.Executor executor)Opens an editor for the entry associated with the given key.voidflush()Flushes any indexing data buffered by this store.java.util.Iterator<Store.Viewer>iterator()Returns an iterator ofViewersover the entries in this store.longmaxSize()Returns this store's max size in bytes.booleanremove(java.lang.String key)Removes the entry associated with the given key.default booleanremoveAll(java.util.List<java.lang.String> keys)Removes all the entries associated with the given keys.longsize()Returns the size in bytes of all entries in this store.default java.util.Optional<Store.Viewer>view(java.lang.String key)Synchronous variant ofview(String, Executor).java.util.concurrent.CompletableFuture<java.util.Optional<Store.Viewer>>view(java.lang.String key, java.util.concurrent.Executor executor)Opens a viewer for the entry associated with the given key.
-
-
-
Method Detail
-
maxSize
long maxSize()
Returns this store's max size in bytes.
-
view
default java.util.Optional<Store.Viewer> view(java.lang.String key) throws java.io.IOException
Synchronous variant ofview(String, Executor).- Throws:
java.lang.IllegalStateException- if closedjava.io.IOException
-
view
java.util.concurrent.CompletableFuture<java.util.Optional<Store.Viewer>> view(java.lang.String key, java.util.concurrent.Executor executor)
Opens a viewer for the entry associated with the given key. An empty optional is returned if there's no such entry.- Throws:
java.lang.IllegalStateException- if closed
-
edit
default java.util.Optional<Store.Editor> edit(java.lang.String key) throws java.io.IOException
Synchronous variant ofedit(String, Executor).- Throws:
java.lang.IllegalStateException- if closedjava.io.IOException
-
edit
java.util.concurrent.CompletableFuture<java.util.Optional<Store.Editor>> edit(java.lang.String key, java.util.concurrent.Executor executor)
Opens an editor for the entry associated with the given key. An empty optional is returned either if there's no such entry, or such entry cannot be edited at the moment.- Throws:
java.lang.IllegalStateException- if closed
-
iterator
java.util.Iterator<Store.Viewer> iterator() throws java.io.IOException
Returns an iterator ofViewersover the entries in this store. The iterator doesn't throwConcurrentModificationExceptionwhen the store is asynchronously modified, but there's no guarantee such changes are reflected.- Throws:
java.io.IOException
-
remove
@CanIgnoreReturnValue boolean remove(java.lang.String key) throws java.io.IOExceptionRemoves the entry associated with the given key.- Throws:
java.lang.IllegalStateException- if closedjava.io.IOException
-
removeAll
@CanIgnoreReturnValue default boolean removeAll(java.util.List<java.lang.String> keys) throws java.io.IOExceptionRemoves all the entries associated with the given keys.- Throws:
java.lang.IllegalStateException- if closedjava.io.IOException
-
clear
void clear() throws java.io.IOExceptionRemoves all entries from this store.- Throws:
java.lang.IllegalStateException- if closedjava.io.IOException
-
size
long size() throws java.io.IOException
Returns the size in bytes of all entries in this store.- Throws:
java.io.IOException
-
dispose
void dispose() throws java.io.IOExceptionAtomically clears and closes this store.- Throws:
java.io.IOException
-
close
void close() throws java.io.IOExceptionCloses this store. Once the store is closed, all ongoing edits fail, either silently or by throwing an exception, to write or commit anything.- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Throws:
java.io.IOException
-
flush
void flush() throws java.io.IOExceptionFlushes any indexing data buffered by this store.- Specified by:
flushin interfacejava.io.Flushable- Throws:
java.lang.IllegalStateException- if the store is closedjava.io.IOException
-
-