Package org.opensaml.storage
Class AbstractMapBackedStorageService
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
- All Implemented Interfaces:
Component,DestructableComponent,IdentifiableComponent,IdentifiedComponent,InitializableComponent,EnumeratableStorageService,StorageCapabilities,StorageService
public abstract class AbstractMapBackedStorageService
extends AbstractStorageService
implements EnumeratableStorageService
Partial implementation of
StorageService that stores data in-memory with no persistence
using a simple map.
Abstract methods supply the map of data to manipulate and the lock to use, which allows optimizations in cases where locking isn't required or data isn't shared.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanCreates a new record in the store with an expiration.booleanDeletes an existing record from the store.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.booleandeleteWithVersion(long version, String context, String key) Deletes an existing record from the store if it currently has a specified version.getContextKeys(String context, String prefix) Return an iterable collection of the keys stored in a context.protected abstract Map<String,Map<String, MutableStorageRecord<?>>> Get the map of contexts to manipulate during operations.protected abstract ReadWriteLockgetLock()Get the shared lock to synchronize access.<T> StorageRecord<T>Returns an existing record from the store, if one exists.<T> Pair<Long,StorageRecord<T>> Returns an existing record from the store, along with its version.protected <T> Pair<Long,StorageRecord<T>> Internal method to implement read functions.voidManually trigger a cleanup of expired records.protected booleanreapWithLock(Map<String, MutableStorageRecord<?>> dataMap, long expiration) Locates and removes expired records from the input map.protected voidsetDirty()A callback to indicate that data has been modified.booleanUpdates an existing record in the store.voidupdateContextExpiration(String context, Long expiration) Updates the expiration time of all records in the context.booleanupdateExpiration(String context, String key, Long expiration) Updates expiration of an existing record in the store.protected LongInternal method to implement update functions.updateWithVersion(long version, String context, String key, String value, Long expiration) Updates an existing record in the store, if a version matches.Methods inherited from class org.opensaml.storage.AbstractStorageService
create, create, delete, deleteWithVersion, doDestroy, doInitialize, getCapabilities, getCleanupInterval, getCleanupTask, 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
isClustered, isServerSideMethods 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.
-
-
Constructor Details
-
AbstractMapBackedStorageService
public AbstractMapBackedStorageService()Constructor.
-
-
Method Details
-
create
public boolean create(@Nonnull @NotEmpty String context, @Nonnull @NotEmpty String key, @Nonnull @NotEmpty String value, @Nullable Long expiration) throws IOException Creates a new record in the store with an expiration.- Specified by:
createin interfaceStorageService- 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
-
read
@Nullable public <T> StorageRecord<T> read(@Nonnull @NotEmpty String context, @Nonnull @NotEmpty String key) throws IOException Returns an existing record from the store, if one exists.- Specified by:
readin interfaceStorageService- Type Parameters:
T- type of record- Parameters:
context- a storage context labelkey- a key unique to context- Returns:
- the record read back, if present, or null
- Throws:
IOException- if errors occur in the read process
-
read
@Nonnull public <T> Pair<Long,StorageRecord<T>> read(@Nonnull @NotEmpty String context, @Nonnull @NotEmpty String key, long version) throws IOException Returns an existing record from the store, along with its version.The first member of the pair returned will contain the version of the record in the store, or will be null if no record exists. The second member will contain the record read back. If null, the record either didn't exist (if the first member was also null) or the record was the same version as that supplied by the caller.
- Specified by:
readin interfaceStorageService- Type Parameters:
T- type of record- Parameters:
context- a storage context labelkey- a key unique to contextversion- only return record if newer than supplied version- Returns:
- a pair consisting of the version of the record read back, if any, and the record itself
- Throws:
IOException- if errors occur in the read process
-
update
public boolean update(@Nonnull @NotEmpty String context, @Nonnull @NotEmpty String key, @Nonnull @NotEmpty String value, @Nullable Long expiration) throws IOException Updates an existing record in the store.- Specified by:
updatein interfaceStorageService- Parameters:
context- a storage context labelkey- a key unique to contextvalue- updated valueexpiration- expiration for record, or null- Returns:
- true if the update succeeded, false if the record does not exist
- Throws:
IOException- if errors occur in the update process
-
updateWithVersion
@Nullable public Long updateWithVersion(long version, @Nonnull @NotEmpty String context, @Nonnull @NotEmpty String key, @Nonnull @NotEmpty String value, @Nullable Long expiration) throws IOException, VersionMismatchException Updates an existing record in the store, if a version matches.- Specified by:
updateWithVersionin interfaceStorageService- 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
-
updateExpiration
public boolean updateExpiration(@Nonnull @NotEmpty String context, @Nonnull @NotEmpty String key, @Nullable Long expiration) throws IOException Updates expiration of an existing record in the store.- Specified by:
updateExpirationin interfaceStorageService- Parameters:
context- a storage context labelkey- a key unique to contextexpiration- expiration for record, or null- Returns:
- true if the update succeeded, false if the record does not exist
- Throws:
IOException- if errors occur in the update process
-
deleteWithVersion
public boolean deleteWithVersion(long version, @Nonnull String context, @Nonnull String key) throws IOException, VersionMismatchException Deletes an existing record from the store if it currently has a specified version.- Specified by:
deleteWithVersionin interfaceStorageService- Parameters:
version- record version to deletecontext- 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 deletion processVersionMismatchException- if the record has already been updated to a newer version
-
delete
public boolean delete(@Nonnull @NotEmpty String context, @Nonnull @NotEmpty String key) throws IOException Deletes an existing record from the store.- Specified by:
deletein interfaceStorageService- Parameters:
context- 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 deletion process
-
updateContextExpiration
public void updateContextExpiration(@Nonnull @NotEmpty String context, @Nullable Long expiration) throws IOException Updates the expiration time of all records in the context.- Specified by:
updateContextExpirationin interfaceStorageService- Parameters:
context- a storage context labelexpiration- a new expiration timestamp, or null- Throws:
IOException- if errors occur in the cleanup process
-
deleteContext
Forcibly removes all records in a given context along with any associated resources devoted to maintaining the context.- Specified by:
deleteContextin interfaceStorageService- Parameters:
context- a storage context label- Throws:
IOException- if errors occur in the cleanup process
-
reap
Manually trigger a cleanup of expired records. The method MAY return without guaranteeing that cleanup has already occurred.- Specified by:
reapin interfaceStorageService- Parameters:
context- a storage context label- Throws:
IOException- if errors occur in the cleanup process
-
getContextKeys
@Nonnull public Iterable<String> getContextKeys(@Nonnull @NotEmpty String context, @Nullable String prefix) throws IOException Return an iterable collection of the keys stored in a context.- Specified by:
getContextKeysin interfaceEnumeratableStorageService- Parameters:
context- the context to enumerateprefix- optional prefix to filter keys- Returns:
- keys stored in a context
- Throws:
IOException- on error
-
getLock
Get the shared lock to synchronize access.- Returns:
- shared lock
-
getContextMap
@Nonnull @Live protected abstract Map<String,Map<String, getContextMap() throws IOExceptionMutableStorageRecord<?>>> Get the map of contexts to manipulate during operations.This method is guaranteed to be called under cover the lock returned by {
getLock().- Returns:
- map of contexts to manipulate
- Throws:
IOException- to signal errors
-
setDirty
A callback to indicate that data has been modified.This method is guaranteed to be called under cover the lock returned by {
getLock().- Throws:
IOException- to signal an error
-
readImpl
@Nonnull protected <T> Pair<Long,StorageRecord<T>> readImpl(@Nonnull @NotEmpty String context, @Nonnull @NotEmpty String key, @Nullable Long version) throws IOException Internal method to implement read functions.- Type Parameters:
T- type of object- Parameters:
context- a storage context labelkey- a key unique to contextversion- only return record if newer than optionally supplied version- Returns:
- a pair consisting of the version of the record read back, if any, and the record itself
- Throws:
IOException- if errors occur in the read process
-
updateImpl
@Nullable protected Long updateImpl(@Nullable Long version, @Nonnull @NotEmpty String context, @Nonnull @NotEmpty String key, @Nullable String value, @Nullable Long expiration) throws IOException, VersionMismatchException Internal method to implement update functions.- 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
-
deleteImpl
protected boolean deleteImpl(@Nullable @Positive Long version, @Nonnull @NotEmpty String context, @Nonnull @NotEmpty String key) throws IOException, VersionMismatchException Internal method to implement delete functions.- 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
-
reapWithLock
protected boolean reapWithLock(@Nonnull Map<String, MutableStorageRecord<?>> dataMap, long expiration) Locates and removes expired records from the input map.This method MUST be called while holding a write lock, if locking is required.
- Parameters:
dataMap- the map to reapexpiration- time at which to consider records expired- Returns:
- true iff anything was purged
-