Package org.openrefine.model.changes
Class FileChangeDataStore
- java.lang.Object
-
- org.openrefine.model.changes.FileChangeDataStore
-
- All Implemented Interfaces:
ChangeDataStore
public class FileChangeDataStore extends Object implements ChangeDataStore
AChangeDataStore
which stores change data on disk. This is the default one used in OpenRefine.
It makes use of two directories:- The base directory, where changes are stored;
- The incomplete directory, which is used as a temporary location when resuming the fetching of some change data after an interruption.
retrieveOrCompute(ChangeDataId, ChangeDataSerializer, Function, String)
finds an incomplete change data is found in the base directory, it is moved to the incomplete directory. A new version of the change data, completed using the completion process, is then saved again in the base directory.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static class
FileChangeDataStore.ChangeDataStoringProcess<T>
-
Constructor Summary
Constructors Constructor Description FileChangeDataStore(Runner runner, File baseDirectory, File incompleteDirectory)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
discardAll(long historyEntryId)
Discards all change data objects which belong to a given history entry id.void
dispose()
Stops all the processes and shuts down the thread pool.List<ChangeDataId>
getChangeDataIds(long historyEntryId)
Retrieve the list of change data ids associated with a given history entry.ProcessManager
getProcessManager()
boolean
needsRefreshing(long historyEntryId)
Returns true when a change data object is being fetched by a process and should therefore be refreshed as the process may have refreshed the contents on disk.protected void
registerId(ChangeDataId id)
<T> ChangeData<T>
retrieve(ChangeDataId changeDataId, ChangeDataSerializer<T> serializer)
Loads back aChangeData
that has been persisted before.<T> ChangeData<T>
retrieveOrCompute(ChangeDataId changeDataId, ChangeDataSerializer<T> serializer, Function<Optional<ChangeData<T>>,ChangeData<T>> completionProcess, String description)
Retrieves a change data if it exists already, and if it does not (or is incomplete), start a process to finish computing it.<T> void
store(ChangeData<T> data, ChangeDataId changeDataId, ChangeDataSerializer<T> serializer, Optional<ProgressReporter> progressReporter)
Stores aChangeData
, which might imply explicitly computing all its values (if the store persists its changes).<T> ProgressingFuture<Void>
storeAsync(ChangeData<T> data, ChangeDataId changeDataId, ChangeDataSerializer<T> serializer)
Asynchronously stores aChangeData
, which might imply explicitly computing all its values (if the store persists its changes).
-
-
-
Method Detail
-
getProcessManager
public ProcessManager getProcessManager()
- Specified by:
getProcessManager
in interfaceChangeDataStore
-
store
public <T> void store(ChangeData<T> data, ChangeDataId changeDataId, ChangeDataSerializer<T> serializer, Optional<ProgressReporter> progressReporter) throws IOException
Description copied from interface:ChangeDataStore
Stores aChangeData
, which might imply explicitly computing all its values (if the store persists its changes).- Specified by:
store
in interfaceChangeDataStore
- Parameters:
data
- the data to storechangeDataId
- the id of the change data to storeserializer
- to serialize the data to a file, for instanceprogressReporter
- reports the progress of the change data computation and serialization- Throws:
IOException
- if serialization failed
-
storeAsync
public <T> ProgressingFuture<Void> storeAsync(ChangeData<T> data, ChangeDataId changeDataId, ChangeDataSerializer<T> serializer)
Description copied from interface:ChangeDataStore
Asynchronously stores aChangeData
, which might imply explicitly computing all its values (if the store persists its changes).- Specified by:
storeAsync
in interfaceChangeDataStore
- Parameters:
data
- the data to storechangeDataId
- the id of the change data to storeserializer
- to serialize the data to a file, for instance
-
retrieve
public <T> ChangeData<T> retrieve(ChangeDataId changeDataId, ChangeDataSerializer<T> serializer) throws IOException
Description copied from interface:ChangeDataStore
Loads back aChangeData
that has been persisted before.- Specified by:
retrieve
in interfaceChangeDataStore
- Parameters:
changeDataId
- the id of the change data to retrieveserializer
- the deserializer to read it back from a file- Throws:
IOException
-
retrieveOrCompute
public <T> ChangeData<T> retrieveOrCompute(ChangeDataId changeDataId, ChangeDataSerializer<T> serializer, Function<Optional<ChangeData<T>>,ChangeData<T>> completionProcess, String description) throws IOException
Description copied from interface:ChangeDataStore
Retrieves a change data if it exists already, and if it does not (or is incomplete), start a process to finish computing it.- Specified by:
retrieveOrCompute
in interfaceChangeDataStore
- Parameters:
changeDataId
- the id of the change data to retrieveserializer
- the serializer to read it back from a file and to write its completion if it is incompletecompletionProcess
- a function taking the existing state of the change data and returning the complete versiondescription
- a description of the completion process, to be reported to the user- Throws:
IOException
-
registerId
protected void registerId(ChangeDataId id)
-
needsRefreshing
public boolean needsRefreshing(long historyEntryId)
Description copied from interface:ChangeDataStore
Returns true when a change data object is being fetched by a process and should therefore be refreshed as the process may have refreshed the contents on disk.- Specified by:
needsRefreshing
in interfaceChangeDataStore
-
getChangeDataIds
public List<ChangeDataId> getChangeDataIds(long historyEntryId)
Description copied from interface:ChangeDataStore
Retrieve the list of change data ids associated with a given history entry.- Specified by:
getChangeDataIds
in interfaceChangeDataStore
-
discardAll
public void discardAll(long historyEntryId)
Description copied from interface:ChangeDataStore
Discards all change data objects which belong to a given history entry id.- Specified by:
discardAll
in interfaceChangeDataStore
-
dispose
public void dispose()
Description copied from interface:ChangeDataStore
Stops all the processes and shuts down the thread pool.- Specified by:
dispose
in interfaceChangeDataStore
-
-