Package org.opensaml.storage.impl
Class ResourceBackedMemoryStorageService
java.lang.Object
net.shibboleth.shared.component.AbstractInitializableComponent
net.shibboleth.shared.component.AbstractIdentifiedInitializableComponent
net.shibboleth.shared.component.AbstractIdentifiableInitializableComponent
org.opensaml.storage.AbstractStorageService
org.opensaml.storage.AbstractMapBackedStorageService
org.opensaml.storage.impl.ResourceBackedMemoryStorageService
- All Implemented Interfaces:
Component,DestructableComponent,IdentifiableComponent,IdentifiedComponent,InitializableComponent,EnumeratableStorageService,StorageCapabilities,StorageService
public class ResourceBackedMemoryStorageService
extends AbstractMapBackedStorageService
implements StorageCapabilities
Implementation of
AbstractMapBackedStorageService that stores data in-memory in a shared data structure
after loading it from a resource containing a simple one-line per record, delimited format.
Records do not carry expirations.
The implementation is read-only and throws exceptions for any methods that would mutate the data. The "cleanup" task is instead used to periodically check the source file for updates and reloads the in-memory data under an exclusive lock.
Lines starting with a '#' character are ignored as comments.
- Since:
- 5.3.0
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate Map<String,Map<String, MutableStorageRecord<?>>> Map of contexts.private DataSealerOptional encryption support.private StringField delimiter in resource.private longFile timestamp.private ReadWriteLockA shared lock to synchronize access.private final org.slf4j.LoggerClass logger.private ResourceSource of information. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanCreates a new record in the store with an expiration.voiddeleteContext(String context) Forcibly removes all records in a given context along with any associated resources devoted to maintaining the context.protected booleandeleteImpl(Long version, String context, String key) Internal method to implement delete functions.protected voidprotected TimerTaskReturns a cleanup task function to schedule for background cleanup.protected Map<String,Map<String, MutableStorageRecord<?>>> Get the map of contexts to manipulate during operations.protected ReadWriteLockgetLock()Get the shared lock to synchronize access.booleanReturns true iff the storage implementation manages data independent of a single server node.booleanReturns true iff the storage implementation manages data independent of the client.private Map<String,Map<String, MutableStorageRecord<?>>> load(InputStream is) Loads data from the supplied input stream.voidsetDataSealer(DataSealer sealer) Sets theDataSealerto use, which enables decryption of the record values (but not the rest).voidsetDelimiter(String delim) Set the field delimiter to use to split the records.voidsetReloadInterval(Duration interval) Sets the time between checks for changes to the resource and reload of the records.voidsetResource(Resource resource) Set the resource to use.voidupdateContextExpiration(String context, Long expiration) Updates the expiration time of all records in the context.protected LongInternal method to implement update functions.Methods inherited from class org.opensaml.storage.AbstractMapBackedStorageService
delete, deleteWithVersion, getContextKeys, read, read, readImpl, reap, reapWithLock, setDirty, update, updateExpiration, updateWithVersionMethods inherited from class org.opensaml.storage.AbstractStorageService
create, create, delete, deleteWithVersion, getCapabilities, getCleanupInterval, getCleanupTaskTimer, getContextSize, getKeySize, getValueSize, read, setCleanupInterval, setCleanupTaskTimer, setContextSize, setKeySize, setValueSize, teardownAbstractStorageService, update, update, updateExpiration, updateWithVersion, updateWithVersionMethods inherited from class net.shibboleth.shared.component.AbstractIdentifiableInitializableComponent
setIdMethods inherited from class net.shibboleth.shared.component.AbstractIdentifiedInitializableComponent
ensureId, getId, ifDestroyedThrowDestroyedComponentException, ifInitializedThrowUnmodifiabledComponentException, ifNotInitializedThrowUninitializedComponentExceptionMethods inherited from class net.shibboleth.shared.component.AbstractInitializableComponent
checkComponentActive, checkSetterPreconditions, destroy, doDestroy, initialize, isDestroyed, isInitializedMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface net.shibboleth.shared.component.IdentifiedComponent
getIdMethods inherited from interface org.opensaml.storage.StorageCapabilities
getContextSize, getKeySize, getValueSizeMethods inherited from interface org.opensaml.storage.StorageService
create, create, delete, deleteWithVersion, getCapabilities, read, update, update, updateExpiration, updateWithVersion, updateWithVersion
-
Field Details
-
log
@Nonnull private final org.slf4j.Logger logClass logger. -
contextMap
Map of contexts. -
lock
A shared lock to synchronize access. -
dataSealer
Optional encryption support. -
storageResource
Source of information. -
delimiter
Field delimiter in resource. -
lastModified
private long lastModifiedFile timestamp.
-
-
Constructor Details
-
ResourceBackedMemoryStorageService
public ResourceBackedMemoryStorageService()Constructor.
-
-
Method Details
-
isServerSide
public boolean isServerSide()Returns true iff the storage implementation manages data independent of the client.- Specified by:
isServerSidein interfaceStorageCapabilities- Returns:
- true iff the storage implementation manages data independent of the client
-
isClustered
public boolean isClustered()Returns true iff the storage implementation manages data independent of a single server node.- Specified by:
isClusteredin interfaceStorageCapabilities- Returns:
- true iff the storage implementation manages data independent of a single server node
-
setReloadInterval
Sets the time between checks for changes to the resource and reload of the records.A value of 0 (the default) indicates that no reloading will be performed.
Non-file resources are detected and reload is skipped, though the task may still run and log warnings.
- Parameters:
interval- time between reload checking
-
setDelimiter
Set the field delimiter to use to split the records.Defaults to "," (comma).
- Parameters:
delim- delimiter string
-
doInitialize
- Overrides:
doInitializein classAbstractStorageService- Throws:
ComponentInitializationException
-
getContextMap
Get the map of contexts to manipulate during operations.This method is guaranteed to be called under cover the lock returned by {
AbstractMapBackedStorageService.getLock().- Specified by:
getContextMapin classAbstractMapBackedStorageService- Returns:
- map of contexts to manipulate
-
getLock
Get the shared lock to synchronize access.- Specified by:
getLockin classAbstractMapBackedStorageService- Returns:
- shared lock
-
create
Creates a new record in the store with an expiration.- Specified by:
createin interfaceStorageService- Overrides:
createin classAbstractMapBackedStorageService- Parameters:
context- a storage context labelkey- a key unique to contextvalue- value to storeexpiration- expiration for record, or null- Returns:
- true iff record was inserted, false iff a duplicate was found
- Throws:
IOException- if fatal errors occur in the insertion process
-
updateImpl
protected Long updateImpl(Long version, String context, String key, String value, Long expiration) throws IOException, VersionMismatchException Internal method to implement update functions.- Overrides:
updateImplin classAbstractMapBackedStorageService- Parameters:
version- only update if the current version matches this valuecontext- a storage context labelkey- a key unique to contextvalue- updated valueexpiration- expiration for record. or null- Returns:
- the version of the record after update, null if no record exists
- Throws:
IOException- if errors occur in the update processVersionMismatchException- if the record has already been updated to a newer version
-
updateContextExpiration
Updates the expiration time of all records in the context.- Specified by:
updateContextExpirationin interfaceStorageService- Overrides:
updateContextExpirationin classAbstractMapBackedStorageService- Parameters:
context- a storage context labelexpiration- a new expiration timestamp, or null
-
deleteImpl
protected boolean deleteImpl(Long version, String context, String key) throws IOException, VersionMismatchException Internal method to implement delete functions.- Overrides:
deleteImplin classAbstractMapBackedStorageService- Parameters:
version- only update if the current version matches this valuecontext- a storage context labelkey- a key unique to context- Returns:
- true iff the record existed and was deleted
- Throws:
IOException- if errors occur in the update processVersionMismatchException- if the record has already been updated to a newer version
-
deleteContext
Forcibly removes all records in a given context along with any associated resources devoted to maintaining the context.- Specified by:
deleteContextin interfaceStorageService- Overrides:
deleteContextin classAbstractMapBackedStorageService- Parameters:
context- a storage context label- Throws:
IOException- if errors occur in the cleanup process
-
getCleanupTask
Returns a cleanup task function to schedule for background cleanup.The default implementation does not supply one.
- Overrides:
getCleanupTaskin classAbstractStorageService- Returns:
- a task object, or null
-
load
@Nonnull @Unmodifiable @NotLive private Map<String,Map<String, loadMutableStorageRecord<?>>> (@Nonnull InputStream is) throws IOException Loads data from the supplied input stream.Must be called while holding the write lock.
- Parameters:
is-- Returns:
- the constructed map of records
- Throws:
IOException- on error
-