public abstract class AbstractMapBackedStorageService extends AbstractStorageService
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.
| Modifier and Type | Field and Description |
|---|---|
private org.slf4j.Logger |
log
Class logger.
|
| Constructor and Description |
|---|
AbstractMapBackedStorageService()
Constructor.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
create(java.lang.String context,
java.lang.String key,
java.lang.String value,
java.lang.Long expiration)
Creates a new record in the store with an expiration.
|
boolean |
delete(java.lang.String context,
java.lang.String key)
Deletes an existing record from the store.
|
void |
deleteContext(java.lang.String context)
Forcibly removes all records in a given context along with any
associated resources devoted to maintaining the context.
|
protected boolean |
deleteImpl(java.lang.Long version,
java.lang.String context,
java.lang.String key)
Internal method to implement delete functions.
|
boolean |
deleteWithVersion(long version,
java.lang.String context,
java.lang.String key)
Deletes an existing record from the store if it currently has a specified version.
|
protected abstract java.util.Map<java.lang.String,java.util.Map<java.lang.String,MutableStorageRecord>> |
getContextMap()
Get the map of contexts to manipulate during operations.
|
protected abstract java.util.concurrent.locks.ReadWriteLock |
getLock()
Get the shared lock to synchronize access.
|
StorageRecord |
read(java.lang.String context,
java.lang.String key)
Returns an existing record from the store, if one exists.
|
net.shibboleth.utilities.java.support.collection.Pair<java.lang.Long,StorageRecord> |
read(java.lang.String context,
java.lang.String key,
long version)
Returns an existing record from the store, along with its version.
|
protected net.shibboleth.utilities.java.support.collection.Pair<java.lang.Long,StorageRecord> |
readImpl(java.lang.String context,
java.lang.String key,
java.lang.Long version)
Internal method to implement read functions.
|
void |
reap(java.lang.String context)
Manually trigger a cleanup of expired records.
|
protected boolean |
reapWithLock(java.util.Map<java.lang.String,MutableStorageRecord> dataMap,
long expiration)
Locates and removes expired records from the input map.
|
boolean |
update(java.lang.String context,
java.lang.String key,
java.lang.String value,
java.lang.Long expiration)
Updates an existing record in the store.
|
void |
updateContextExpiration(java.lang.String context,
java.lang.Long expiration)
Updates the expiration time of all records in the context.
|
boolean |
updateExpiration(java.lang.String context,
java.lang.String key,
java.lang.Long expiration)
Updates expiration of an existing record in the store.
|
protected java.lang.Long |
updateImpl(java.lang.Long version,
java.lang.String context,
java.lang.String key,
java.lang.String value,
java.lang.Long expiration)
Internal method to implement update functions.
|
java.lang.Long |
updateWithVersion(long version,
java.lang.String context,
java.lang.String key,
java.lang.String value,
java.lang.Long expiration)
Updates an existing record in the store, if a version matches.
|
create, create, delete, deleteWithVersion, doDestroy, doInitialize, getCapabilities, getCleanupInterval, getCleanupTask, getCleanupTaskTimer, getContextSize, getKeySize, getValueSize, read, setCleanupInterval, setCleanupTaskTimer, setContextSize, setKeySize, setValueSize, update, update, updateExpiration, updateWithVersion, updateWithVersionsetIdgetIddestroy, initialize, isDestroyed, isInitializedpublic AbstractMapBackedStorageService()
public boolean create(@Nonnull @NotEmpty
java.lang.String context,
@Nonnull @NotEmpty
java.lang.String key,
@Nonnull @NotEmpty
java.lang.String value,
@Nullable
java.lang.Long expiration)
throws java.io.IOException
context - a storage context labelkey - a key unique to contextvalue - value to storeexpiration - expiration for record, or nulljava.io.IOException - if fatal errors occur in the insertion process@Nullable public StorageRecord read(@Nonnull @NotEmpty java.lang.String context, @Nonnull @NotEmpty java.lang.String key) throws java.io.IOException
context - a storage context labelkey - a key unique to contextjava.io.IOException - if errors occur in the read process@Nonnull public net.shibboleth.utilities.java.support.collection.Pair<java.lang.Long,StorageRecord> read(@Nonnull @NotEmpty java.lang.String context, @Nonnull @NotEmpty java.lang.String key, long version) throws java.io.IOException
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.
context - a storage context labelkey - a key unique to contextversion - only return record if newer than supplied versionjava.io.IOException - if errors occur in the read processpublic boolean update(@Nonnull @NotEmpty
java.lang.String context,
@Nonnull @NotEmpty
java.lang.String key,
@Nonnull @NotEmpty
java.lang.String value,
@Nullable
java.lang.Long expiration)
throws java.io.IOException
context - a storage context labelkey - a key unique to contextvalue - updated valueexpiration - expiration for record, or nulljava.io.IOException - if errors occur in the update process@Nullable
public java.lang.Long updateWithVersion(long version,
@Nonnull @NotEmpty
java.lang.String context,
@Nonnull @NotEmpty
java.lang.String key,
@Nonnull @NotEmpty
java.lang.String value,
@Nullable
java.lang.Long expiration)
throws java.io.IOException,
VersionMismatchException
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 nulljava.io.IOException - if errors occur in the update processVersionMismatchException - if the record has already been updated to a newer versionpublic boolean updateExpiration(@Nonnull @NotEmpty
java.lang.String context,
@Nonnull @NotEmpty
java.lang.String key,
@Nullable
java.lang.Long expiration)
throws java.io.IOException
context - a storage context labelkey - a key unique to contextexpiration - expiration for record, or nulljava.io.IOException - if errors occur in the update processpublic boolean deleteWithVersion(long version,
java.lang.String context,
java.lang.String key)
throws java.io.IOException,
VersionMismatchException
version - record version to deletecontext - a storage context labelkey - a key unique to contextjava.io.IOException - if errors occur in the deletion processVersionMismatchException - if the record has already been updated to a newer versionpublic boolean delete(@Nonnull @NotEmpty
java.lang.String context,
@Nonnull @NotEmpty
java.lang.String key)
throws java.io.IOException
context - a storage context labelkey - a key unique to contextjava.io.IOException - if errors occur in the deletion processpublic void updateContextExpiration(@Nonnull @NotEmpty
java.lang.String context,
@Nullable
java.lang.Long expiration)
throws java.io.IOException
context - a storage context labelexpiration - a new expiration timestamp, or nulljava.io.IOException - if errors occur in the cleanup processpublic void deleteContext(@Nonnull @NotEmpty
java.lang.String context)
throws java.io.IOException
context - a storage context labeljava.io.IOException - if errors occur in the cleanup processpublic void reap(@Nonnull @NotEmpty
java.lang.String context)
throws java.io.IOException
context - a storage context labeljava.io.IOException - if errors occur in the cleanup process@Nonnull @NonnullElements @Live protected abstract java.util.Map<java.lang.String,java.util.Map<java.lang.String,MutableStorageRecord>> getContextMap()
@Nonnull protected abstract java.util.concurrent.locks.ReadWriteLock getLock()
@Nonnull protected net.shibboleth.utilities.java.support.collection.Pair<java.lang.Long,StorageRecord> readImpl(@Nonnull @NotEmpty java.lang.String context, @Nonnull @NotEmpty java.lang.String key, @Nullable java.lang.Long version) throws java.io.IOException
context - a storage context labelkey - a key unique to contextversion - only return record if newer than optionally supplied versionjava.io.IOException - if errors occur in the read process@Nullable
protected java.lang.Long updateImpl(@Nullable
java.lang.Long version,
@Nonnull @NotEmpty
java.lang.String context,
@Nonnull @NotEmpty
java.lang.String key,
@Nullable
java.lang.String value,
@Nullable
java.lang.Long expiration)
throws java.io.IOException,
VersionMismatchException
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 nulljava.io.IOException - if errors occur in the update processVersionMismatchException - if the record has already been updated to a newer versionprotected boolean deleteImpl(@Nullable @Positive
java.lang.Long version,
@Nonnull @NotEmpty
java.lang.String context,
@Nonnull @NotEmpty
java.lang.String key)
throws java.io.IOException,
VersionMismatchException
version - only update if the current version matches this valuecontext - a storage context labelkey - a key unique to contextjava.io.IOException - if errors occur in the update processVersionMismatchException - if the record has already been updated to a newer versionprotected boolean reapWithLock(@Nonnull @NonnullElements
java.util.Map<java.lang.String,MutableStorageRecord> dataMap,
long expiration)
This method MUST be called while holding a write lock, if locking is required.
dataMap - the map to reapexpiration - time at which to consider records expired