Class CachingOcflStorage
- java.lang.Object
-
- edu.wisc.library.ocfl.core.storage.AbstractOcflStorage
-
- edu.wisc.library.ocfl.core.storage.CachingOcflStorage
-
- All Implemented Interfaces:
OcflStorage
public class CachingOcflStorage extends AbstractOcflStorage
Adds an Inventory caching layer on top of an OcflStorage implementation.
-
-
Field Summary
-
Fields inherited from class edu.wisc.library.ocfl.core.storage.AbstractOcflStorage
inventoryMapper, ocflVersion, supportEvaluator
-
-
Constructor Summary
Constructors Constructor Description CachingOcflStorage(Cache<String,Inventory> inventoryCache, OcflStorage delegate)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Shutsdown any resources the OclfStorage may have open, such as ExecutorServices.voidcommitMutableHead(Inventory oldInventory, Inventory newInventory, Path stagingDir)Moves the mutable HEAD of any object into the object root and into an immutable version.booleancontainsObject(String objectId)Returns true if an object with the specified id exists in the repository.protected voiddoInitialize(OcflExtensionConfig layoutConfig)Does whatever is necessary to initialize OCFL repository storage.voidexportObject(String objectId, Path outputPath)Copies a raw OCFL object to the specified directory.voidexportVersion(ObjectVersionId objectVersionId, Path outputPath)Copies a raw OCFL object version to the specified directory.byte[]getInventoryBytes(String objectId, VersionNum versionNum)Returns the raw inventory bytes for the specified object versionMap<String,OcflFileRetriever>getObjectStreams(Inventory inventory, VersionNum versionNum)Returns a map ofOcflFileRetrieverobjects that are used to lazy-load object files.voidimportObject(String objectId, Path objectPath)Moves an entire OCFL object into the repository.voidinvalidateCache()If the OcflStorage is using an inventory cache, then this method invalidates all entries in the cache.voidinvalidateCache(String objectId)If the OcflStorage is using an inventory cache, then this method invalidates the cache entry for the specified object.Stream<String>listObjectIds()Returns a stream of object ids for all of the OCFL objects stored in a repository.InventoryloadInventory(String objectId)If the inventory is cached, it's returned immediately.StringobjectRootPath(String objectId)Returns the path from the storage root to the object root.voidpurgeMutableHead(String objectId)Permanently removes the mutable HEAD of an object.voidpurgeObject(String objectId)Permanently removes an object from the repository.voidreconstructObjectVersion(Inventory inventory, VersionNum versionNum, Path stagingDir)Reconstructs a complete object at the specified version in the stagingDir.voidrollbackToVersion(Inventory inventory, VersionNum versionNum)Sets the head object version to the specified version by reinstating that version's inventory into the object root, and purging all intermediary versions.voidstoreNewVersion(Inventory inventory, Path stagingDir)Stores a new version of an object and writes the inventory to the cache.ValidationResultsvalidateObject(String objectId, boolean contentFixityCheck)Validates the specified object against the OCFL 1.0 spec.-
Methods inherited from class edu.wisc.library.ocfl.core.storage.AbstractOcflStorage
ensureOpen, initializeStorage
-
-
-
-
Constructor Detail
-
CachingOcflStorage
public CachingOcflStorage(Cache<String,Inventory> inventoryCache, OcflStorage delegate)
-
-
Method Detail
-
doInitialize
protected void doInitialize(OcflExtensionConfig layoutConfig)
Does whatever is necessary to initialize OCFL repository storage.- Specified by:
doInitializein classAbstractOcflStorage- Parameters:
layoutConfig- the storage layout configuration, may be null to auto-detect existing configuration
-
loadInventory
public Inventory loadInventory(String objectId)
If the inventory is cached, it's returned immediately. Otherwise, it's fetched from the delegate storage.- Parameters:
objectId- the id of the object to load- Returns:
- inventory
-
getInventoryBytes
public byte[] getInventoryBytes(String objectId, VersionNum versionNum)
Returns the raw inventory bytes for the specified object version- Parameters:
objectId- the id of the objectversionNum- the version number- Returns:
- the raw inventory bytes
-
storeNewVersion
public void storeNewVersion(Inventory inventory, Path stagingDir)
Stores a new version of an object and writes the inventory to the cache.- Parameters:
inventory- the updated object inventorystagingDir- the directory that contains the composed contents of the new object version
-
getObjectStreams
public Map<String,OcflFileRetriever> getObjectStreams(Inventory inventory, VersionNum versionNum)
Returns a map ofOcflFileRetrieverobjects that are used to lazy-load object files. The map keys are the object relative file paths of all of the files in the specified version of the object.- Parameters:
inventory- the object's inventoryversionNum- the id of the version to load- Returns:
- a map of
OcflFileRetrieverobjects keyed off the object relative file paths of all of the files in the object
-
reconstructObjectVersion
public void reconstructObjectVersion(Inventory inventory, VersionNum versionNum, Path stagingDir)
Reconstructs a complete object at the specified version in the stagingDir.The fixity of every file must be checked after copying it to the stagingDir.
- Parameters:
inventory- the deserialized object inventoryversionNum- the id of the version to reconstructstagingDir- the location the reconstructed object should be assembled in
-
purgeObject
public void purgeObject(String objectId)
Permanently removes an object from the repository. Objects that have been purged are NOT recoverable. If an object with the specified id cannot be found it is considered purged and no exception is thrown.DefaultOcflRepository calls this method from a write lock.
- Parameters:
objectId- the id of the object to purge
-
commitMutableHead
public void commitMutableHead(Inventory oldInventory, Inventory newInventory, Path stagingDir)
Moves the mutable HEAD of any object into the object root and into an immutable version. The mutable HEAD does not exist at the end of the operation.DefaultOcflRepository calls this method from a write lock.
- Parameters:
oldInventory- the deserialized inventory of the object BEFORE it was rewritten for the commitnewInventory- the deserialized inventory of the object AFTER it was rewritten for the commitstagingDir- the path to the staging directory that contains the inventory files
-
purgeMutableHead
public void purgeMutableHead(String objectId)
Permanently removes the mutable HEAD of an object. If the object does not have a mutable HEAD nothing happens.DefaultOcflRepository calls this method from a write lock.
- Parameters:
objectId- the id of the object to purge the mutable HEAD of
-
rollbackToVersion
public void rollbackToVersion(Inventory inventory, VersionNum versionNum)
Sets the head object version to the specified version by reinstating that version's inventory into the object root, and purging all intermediary versions.- Parameters:
inventory- the deserialized object inventoryversionNum- the id of the version to rollback to
-
containsObject
public boolean containsObject(String objectId)
Returns true if an object with the specified id exists in the repository.- Parameters:
objectId- the id of the object- Returns:
- true if the object exists and false otherwise
-
objectRootPath
public String objectRootPath(String objectId)
Returns the path from the storage root to the object root.- Parameters:
objectId- the id of the object- Returns:
- the relative path from the storage root to the object root
-
listObjectIds
public Stream<String> listObjectIds()
Returns a stream of object ids for all of the OCFL objects stored in a repository. This stream is populated on demand, and it may be quite slow. Remember to close the stream when you are done with it.- Returns:
- stream of object ids
-
exportVersion
public void exportVersion(ObjectVersionId objectVersionId, Path outputPath)
Copies a raw OCFL object version to the specified directory. For example, if you export version 2 of an object, then the entire contents of the object's v2 directory will be exported the output directory. This is primarily useful for backing up OCFL versions, as an isolated OCFL object version is not usable in and of itself.The outputPath MUST NOT exist, but its parent MUST exist.
Mutable HEAD versions cannot be exported
- Parameters:
objectVersionId- the id of the object and version to exportoutputPath- the directory to write the exported version to, must NOT exist
-
exportObject
public void exportObject(String objectId, Path outputPath)
Copies a raw OCFL object to the specified directory. The output is a complete copy of everything that's contained in the object's root directory.The outputPath MUST NOT exist, but its parent MUST exist.
- Parameters:
objectId- the id of the object to exportoutputPath- the directory to write the exported object to, must NOT exist
-
importObject
public void importObject(String objectId, Path objectPath)
Moves an entire OCFL object into the repository. This object cannot already exist.- Parameters:
objectId- the id of the object to importobjectPath- the directory that contains the object to import
-
validateObject
public ValidationResults validateObject(String objectId, boolean contentFixityCheck)
Validates the specified object against the OCFL 1.0 spec.- Parameters:
objectId- the id of the object to validatecontentFixityCheck- true if the fixity of the content files should be verified- Returns:
- the validation results
-
close
public void close()
Shutsdown any resources the OclfStorage may have open, such as ExecutorServices. Once closed, additional requests will be rejected. Calling this method is optional, and it is more efficient to just let the shutdown hooks take care of closing the resources.- Specified by:
closein interfaceOcflStorage- Overrides:
closein classAbstractOcflStorage
-
invalidateCache
public void invalidateCache(String objectId)
If the OcflStorage is using an inventory cache, then this method invalidates the cache entry for the specified object. Otherwise, nothing happens.- Specified by:
invalidateCachein interfaceOcflStorage- Overrides:
invalidateCachein classAbstractOcflStorage- Parameters:
objectId- the ID of the object to invalidate in the cache
-
invalidateCache
public void invalidateCache()
If the OcflStorage is using an inventory cache, then this method invalidates all entries in the cache. Otherwise, nothing happens.- Specified by:
invalidateCachein interfaceOcflStorage- Overrides:
invalidateCachein classAbstractOcflStorage
-
-