public class MemoryDataStore extends Object implements DataStore
DataStore
implementations that keeps all data in memory, with persistence provided by
loading / saving data to file.
This class realizes a low-performance, functional implementation of the DataStore
component. Record data is loaded at startup from a configurable file and then indexed in
memory; data is written back at shutdown. Each (read-write) transaction works on its copy of
data, and changes are merged back in the component upon successful commit, although data is
written back to disk only at shutdown.
SUPPORTED_TYPES
Constructor and Description |
---|
MemoryDataStore(FileSystem fileSystem,
String path)
Creates a new
MemoryDataStore instance loading/storing data in the file at the path
and file system specified. |
Modifier and Type | Method and Description |
---|---|
DataTransaction |
begin(boolean readOnly)
Begins a new read-only / read-write
DataStore transaction. |
void |
close()
Closes this
Component object. |
void |
init()
Initializes the
Component with the supplied Runtime object. |
String |
toString() |
public MemoryDataStore(FileSystem fileSystem, @Nullable String path)
MemoryDataStore
instance loading/storing data in the file at the path
and file system specified.fileSystem
- the filesystem containing the file where to read/write datapath
- the path of the file where to read/write data, possibly relative to the file
system working directory; if null defaults to datastore.ttl
public void init() throws IOException, IllegalStateException
Component
Component
with the supplied Runtime
object. This method is
called after the instantiation of a Component
and before any other instance method
is called. It provides a Runtime
that can be used to access runtime services such
as locking, serialization and filesystem access. The Component
is allowed to
perform any initialization operation that is necessary in order to become functional; on
failure, these operations may result in a IOException
being thrown.init
in interface Component
IOException
- in case initialization failsIllegalStateException
- in case the component has already been initialized or closedpublic DataTransaction begin(boolean readOnly) throws IOException, IllegalStateException
DataStore
DataStore
transaction. All the accesses to a
DataStore
must occur in the scope of a transaction, that must be ended (possibly
committing the modifications done) as soon as possible to allow improving throughput.begin
in interface DataStore
readOnly
- true if the transaction is not allowed to modify the contents of the
DataStore
(this allows for optimizing accesses).DataCorruptedException
- in case a transaction cannot be started due to the DataStore
persistent
data being damaged or non-existing (this may trigger some external recovery
procedure)IOException
- if another IO error occurs while starting the transactionIllegalStateException
- if the DataStore
object has been already closedpublic void close()
Component
Component
object. If the component has been initialized, closing a it
causes any allocated resource to be freed and any operation or transaction ongoing within
the component being aborted; in case the component has not been initialized yet, or
close()
has already being called, calling this method has no effect. Note that the
operation affects only the local Component
object and not any remote service this
object may rely on to implement its functionalities; in particular, such a remote service
is not shutdown by the operation, so that it can be accessed by other Component
instances possibly running in other (virtual) machines. Similarly, closing a
Component
object has no impact on stored data, that continues to be persisted and
will be accessed unchanged (provided no external modification occurs) the next time a
similarly configured Component
is created.Copyright © 2015–2016 FBK-irst. All rights reserved.