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(String context,
String key,
String value,
Long expiration)
Creates a new record in the store with an expiration.
|
boolean |
delete(String context,
String key)
Deletes an existing record from the store.
|
void |
deleteContext(String context)
Forcibly removes all records in a given context along with any
associated resources devoted to maintaining the context.
|
protected boolean |
deleteImpl(Long version,
String context,
String key)
Internal method to implement delete functions.
|
boolean |
deleteWithVersion(long version,
String context,
String key)
Deletes an existing record from the store if it currently has a specified version.
|
protected abstract Map<String,Map<String,MutableStorageRecord>> |
getContextMap()
Get the map of contexts to manipulate during operations.
|
protected abstract ReadWriteLock |
getLock()
Get the shared lock to synchronize access.
|
StorageRecord |
read(String context,
String key)
Returns an existing record from the store, if one exists.
|
Pair<Long,StorageRecord> |
read(String context,
String key,
long version)
Returns an existing record from the store, along with its version.
|
protected Pair<Long,StorageRecord> |
readImpl(String context,
String key,
Long version)
Internal method to implement read functions.
|
void |
reap(String context)
Manually trigger a cleanup of expired records.
|
protected boolean |
reapWithLock(Map<String,MutableStorageRecord> dataMap,
long expiration)
Locates and removes expired records from the input map.
|
protected void |
setDirty()
A callback to indicate that data has been modified.
|
boolean |
update(String context,
String key,
String value,
Long expiration)
Updates an existing record in the store.
|
void |
updateContextExpiration(String context,
Long expiration)
Updates the expiration time of all records in the context.
|
boolean |
updateExpiration(String context,
String key,
Long expiration)
Updates expiration of an existing record in the store.
|
protected Long |
updateImpl(Long version,
String context,
String key,
String value,
Long expiration)
Internal method to implement update functions.
|
Long |
updateWithVersion(long version,
String context,
String key,
String value,
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, updateWithVersion
setId
getId
destroy, initialize, isDestroyed, isInitialized
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getId
@Nonnull private final org.slf4j.Logger log
public AbstractMapBackedStorageService()
public boolean create(@Nonnull @NotEmpty String context, @Nonnull @NotEmpty String key, @Nonnull @NotEmpty String value, @Nullable Long expiration) throws IOException
context
- a storage context labelkey
- a key unique to contextvalue
- value to storeexpiration
- expiration for record, or nullIOException
- if fatal errors occur in the insertion process@Nullable public StorageRecord read(@Nonnull @NotEmpty String context, @Nonnull @NotEmpty String key) throws IOException
context
- a storage context labelkey
- a key unique to contextIOException
- if errors occur in the read process@Nonnull public Pair<Long,StorageRecord> read(@Nonnull @NotEmpty String context, @Nonnull @NotEmpty String key, long version) throws 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 versionIOException
- if errors occur in the read processpublic boolean update(@Nonnull @NotEmpty String context, @Nonnull @NotEmpty String key, @Nonnull @NotEmpty String value, @Nullable Long expiration) throws IOException
context
- a storage context labelkey
- a key unique to contextvalue
- updated valueexpiration
- expiration for record, or nullIOException
- if errors occur in the update process@Nullable public Long updateWithVersion(long version, @Nonnull @NotEmpty String context, @Nonnull @NotEmpty String key, @Nonnull @NotEmpty String value, @Nullable Long expiration) throws 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 nullIOException
- if errors occur in the update processVersionMismatchException
- if the record has already been updated to a newer versionpublic boolean updateExpiration(@Nonnull @NotEmpty String context, @Nonnull @NotEmpty String key, @Nullable Long expiration) throws IOException
context
- a storage context labelkey
- a key unique to contextexpiration
- expiration for record, or nullIOException
- if errors occur in the update processpublic boolean deleteWithVersion(long version, String context, String key) throws IOException, VersionMismatchException
version
- record version to deletecontext
- a storage context labelkey
- a key unique to contextIOException
- if errors occur in the deletion processVersionMismatchException
- if the record has already been updated to a newer versionpublic boolean delete(@Nonnull @NotEmpty String context, @Nonnull @NotEmpty String key) throws IOException
context
- a storage context labelkey
- a key unique to contextIOException
- if errors occur in the deletion processpublic void updateContextExpiration(@Nonnull @NotEmpty String context, @Nullable Long expiration) throws IOException
context
- a storage context labelexpiration
- a new expiration timestamp, or nullIOException
- if errors occur in the cleanup processpublic void deleteContext(@Nonnull @NotEmpty String context) throws IOException
context
- a storage context labelIOException
- if errors occur in the cleanup processpublic void reap(@Nonnull @NotEmpty String context) throws IOException
context
- a storage context labelIOException
- if errors occur in the cleanup process@Nonnull protected abstract ReadWriteLock getLock()
@Nonnull @NonnullElements @Live protected abstract Map<String,Map<String,MutableStorageRecord>> getContextMap()
This method is guaranteed to be called under cover the lock returned by {getLock()
.
protected void setDirty()
This method is guaranteed to be called under cover the lock returned by {getLock()
.
@Nonnull protected Pair<Long,StorageRecord> readImpl(@Nonnull @NotEmpty String context, @Nonnull @NotEmpty String key, @Nullable Long version) throws IOException
context
- a storage context labelkey
- a key unique to contextversion
- only return record if newer than optionally supplied versionIOException
- if errors occur in the read process@Nullable protected Long updateImpl(@Nullable Long version, @Nonnull @NotEmpty String context, @Nonnull @NotEmpty String key, @Nullable String value, @Nullable Long expiration) throws 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 nullIOException
- if errors occur in the update processVersionMismatchException
- if the record has already been updated to a newer versionprotected boolean deleteImpl(@Nullable @Positive Long version, @Nonnull @NotEmpty String context, @Nonnull @NotEmpty String key) throws IOException, VersionMismatchException
version
- only update if the current version matches this valuecontext
- a storage context labelkey
- a key unique to contextIOException
- if errors occur in the update processVersionMismatchException
- if the record has already been updated to a newer versionprotected boolean reapWithLock(@Nonnull @NonnullElements Map<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 expiredCopyright © 1999–2018 Shibboleth Consortium. All rights reserved.