Package net.shibboleth.sp.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
net.shibboleth.sp.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.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate Map<String,Map<String, MutableStorageRecord<?>>> Map of contexts.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 TypeMethodDescriptionbooleanvoiddeleteContext(String context) protected booleandeleteImpl(Long version, String context, String key) protected voidprotected TimerTaskprotected Map<String,Map<String, MutableStorageRecord<?>>> protected ReadWriteLockgetLock()booleanbooleanprivate Map<String,Map<String, MutableStorageRecord<?>>> load(InputStream is) Loads data from the supplied input stream.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) protected LongMethods 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, doDestroy, getCapabilities, getCleanupInterval, getCleanupTaskTimer, getContextSize, getKeySize, getValueSize, read, setCleanupInterval, setCleanupTaskTimer, setContextSize, setKeySize, setValueSize, 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, 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. -
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()- Specified by:
isServerSidein interfaceStorageCapabilities
-
isClustered
public boolean isClustered()- Specified by:
isClusteredin interfaceStorageCapabilities
-
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
- Specified by:
getContextMapin classAbstractMapBackedStorageService
-
getLock
- Specified by:
getLockin classAbstractMapBackedStorageService
-
create
- Specified by:
createin interfaceStorageService- Overrides:
createin classAbstractMapBackedStorageService- Throws:
IOException
-
updateImpl
protected Long updateImpl(Long version, String context, String key, String value, Long expiration) throws IOException, VersionMismatchException - Overrides:
updateImplin classAbstractMapBackedStorageService- Throws:
IOExceptionVersionMismatchException
-
updateContextExpiration
- Specified by:
updateContextExpirationin interfaceStorageService- Overrides:
updateContextExpirationin classAbstractMapBackedStorageService
-
deleteImpl
protected boolean deleteImpl(Long version, String context, String key) throws IOException, VersionMismatchException - Overrides:
deleteImplin classAbstractMapBackedStorageService- Throws:
IOExceptionVersionMismatchException
-
deleteContext
- Specified by:
deleteContextin interfaceStorageService- Overrides:
deleteContextin classAbstractMapBackedStorageService- Throws:
IOException
-
getCleanupTask
- Overrides:
getCleanupTaskin classAbstractStorageService
-
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
-