Interface Store
- All Superinterfaces:
AutoCloseable, Closeable, Flushable
- All Known Implementing Classes:
DiskStore, MemoryStore
Store.Viewer and modified by an Store.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 unless committed. 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's maxSize() 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 viewed any time, even if immediately, after it has been committed.
Functions that are expected to be called frequently have two variants: one synchronous, and
another asynchronous variant that takes an additional Executor parameter. 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 be Runnable::run if same-thread execution
is preferred.
Store is thread-safe and is suitable for concurrent use.
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceWrites an entry's metadata block and data stream.static interfaceA reader for an entry's data stream.static interfaceA writer for an entry's data stream.static interfaceReads an entry's metadata block and data stream. -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Removes all entries from this store.voidclose()Closes this store.voiddispose()Atomically clears and closes this store.default Optional<Store.Editor> Synchronous variant ofedit(String, Executor).Opens an editor for the entry associated with the given key.voidflush()Flushes any indexing data buffered by this store.iterator()Returns an iterator ofViewersover the entries in this store.longmaxSize()Returns this store's max size in bytes.booleanRemoves the entry associated with the given key.default booleanRemoves all the entries associated with the given keys.longsize()Returns the size in bytes of all entries in this store.default Optional<Store.Viewer> Synchronous variant ofview(String, Executor).Opens a viewer for the entry associated with the given key.
-
Method Details
-
maxSize
long maxSize()Returns this store's max size in bytes. -
view
Synchronous variant ofview(String, Executor).- Throws:
IllegalStateException- if closedIOException
-
view
Opens a viewer for the entry associated with the given key. An empty optional is returned if there's no such entry.- Throws:
IllegalStateException- if closed
-
edit
Synchronous variant ofedit(String, Executor).- Throws:
IllegalStateException- if closedIOException
-
edit
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:
IllegalStateException- if closed
-
iterator
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:
IOException
-
remove
Removes the entry associated with the given key.- Throws:
IllegalStateException- if closedIOException
-
removeAll
Removes all the entries associated with the given keys.- Throws:
IllegalStateException- if closedIOException
-
clear
Removes all entries from this store.- Throws:
IllegalStateException- if closedIOException
-
size
Returns the size in bytes of all entries in this store.- Throws:
IOException
-
dispose
-
close
Closes 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 interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-
flush
Flushes any indexing data buffered by this store.- Specified by:
flushin interfaceFlushable- Throws:
IllegalStateException- if the store is closedIOException
-