Class AbstractStorageService
- All Implemented Interfaces:
Component,DestructableComponent,IdentifiableComponent,IdentifiedComponent,InitializableComponent,StorageCapabilities,StorageService
- Direct Known Subclasses:
AbstractMapBackedStorageService
StorageService implementations.
The base class handles support for a background cleanup task, and handles calling of custom object serializers.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate DurationTime between cleanup checks.private TimerTaskTask that cleans up expired records.private TimerTimer used to schedule cleanup tasks.private intConfigurable context size limit.private TimerTimer used to schedule cleanup tasks if no external one set.private intConfigurable key size limit.private intConfigurable value size limit. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanCreates a new record in the store using an annotated object as the source.<T> booleancreate(String context, String key, T value, StorageSerializer<T> serializer, Long expiration) Creates a new record in the store with an expiration, using a custom serialization process for an arbitrary object.booleanDeletes an existing record from the store, using an annotated object as the source.booleandeleteWithVersion(long version, Object value) Deletes an existing record from the store, using an annotated object as the source, if it currently has a specified version.protected voidprotected voidReturns the capabilities of the underlying store.Gets the time between one cleanup and another.protected TimerTaskReturns a cleanup task function to schedule for background cleanup.Gets the timer used to schedule cleanup tasks.intGets max size of context labels in characters.intGets max size of keys in characters.longGets max size of values in characters.Returns an existing record from the store, if one exists, and uses it to update the annotated fields of a target object.voidsetCleanupInterval(Duration interval) Sets the time between one cleanup and another.voidsetCleanupTaskTimer(Timer timer) Sets the timer used to schedule cleanup tasks.voidsetContextSize(int size) Set the context size limit.voidsetKeySize(int size) Set the key size limit.voidsetValueSize(int size) Set the value size limit.booleanUpdates an existing record in the store, using an annotated object as the source.<T> booleanupdate(String context, String key, T value, StorageSerializer<T> serializer, Long expiration) Updates an existing record in the store using a custom serialization strategy.booleanupdateExpiration(Object value) Updates expiration of an existing record in the store, using an annotated object as the source.updateWithVersion(long version, Object value) Updates an existing record in the store, if a version matches, using an annotated object as the source.<T> LongupdateWithVersion(long version, String context, String key, T value, StorageSerializer<T> serializer, Long expiration) Updates an existing record in the store, if a version matches, using a custom serialization strategy.Methods 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, delete, deleteContext, deleteWithVersion, read, read, reap, update, updateContextExpiration, updateExpiration, updateWithVersion
-
Field Details
-
cleanupInterval
Time between cleanup checks. Default value: (0) -
cleanupTaskTimer
Timer used to schedule cleanup tasks. -
internalTaskTimer
Timer used to schedule cleanup tasks if no external one set. -
cleanupTask
Task that cleans up expired records. -
contextSize
Configurable context size limit. -
keySize
Configurable key size limit. -
valueSize
Configurable value size limit.
-
-
Constructor Details
-
AbstractStorageService
public AbstractStorageService()Constructor.
-
-
Method Details
-
getCleanupInterval
Gets the time between one cleanup and another. A value of 0 indicates that no cleanup will be performed.- Returns:
- time between one cleanup and another
-
setCleanupInterval
Sets the time between one cleanup and another. A value of 0 indicates that no cleanup will be performed. This setting cannot be changed after the service has been initialized.- Parameters:
interval- time between one cleanup and another
-
getCleanupTaskTimer
Gets the timer used to schedule cleanup tasks.- Returns:
- timer used to schedule cleanup tasks
-
setCleanupTaskTimer
Sets the timer used to schedule cleanup tasks. This setting can not be changed after the service has been initialized.- Parameters:
timer- timer used to schedule configuration reload tasks
-
getCleanupTask
Returns a cleanup task function to schedule for background cleanup.The default implementation does not supply one.
- Returns:
- a task object, or null
-
setContextSize
Set the context size limit.- Parameters:
size- limit on context size in characters
-
setKeySize
Set the key size limit.- Parameters:
size- size limit on key size in characters
-
setValueSize
Set the value size limit.- Parameters:
size- size limit on value size in characters
-
doInitialize
- Overrides:
doInitializein classAbstractIdentifiedInitializableComponent- Throws:
ComponentInitializationException
-
doDestroy
protected void doDestroy()- Overrides:
doDestroyin classAbstractInitializableComponent
-
getCapabilities
Returns the capabilities of the underlying store.- Specified by:
getCapabilitiesin interfaceStorageService- Returns:
- interface to access the service's capabilities
-
getContextSize
public int getContextSize()Gets max size of context labels in characters.- Specified by:
getContextSizein interfaceStorageCapabilities- Returns:
- max size of context labels in characters
-
getKeySize
public int getKeySize()Gets max size of keys in characters.- Specified by:
getKeySizein interfaceStorageCapabilities- Returns:
- max size of keys in characters
-
getValueSize
public long getValueSize()Gets max size of values in characters.- Specified by:
getValueSizein interfaceStorageCapabilities- Returns:
- max size of values in characters
-
create
public <T> boolean create(@Nonnull @NotEmpty String context, @Nonnull @NotEmpty String key, @Nonnull T value, @Nonnull StorageSerializer<T> serializer, @Nullable @Positive Long expiration) throws IOException Creates a new record in the store with an expiration, using a custom serialization process for an arbitrary object.- Specified by:
createin interfaceStorageService- Type Parameters:
T- type of record- Parameters:
context- a storage context labelkey- a key unique to contextvalue- object to storeserializer- custom serializer for the objectexpiration- 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
-
create
Creates a new record in the store using an annotated object as the source.The individual parameters for the creation are extracted from the object using the annotations in the org.opensaml.storage.annotation package. If any are missing, or a field inaccessible, a runtime exception of some kind will occur.
- Specified by:
createin interfaceStorageService- Parameters:
value- object to store- Returns:
- true iff record was inserted, false iff a duplicate was found
- Throws:
IOException- if fatal errors occur in the insertion process
-
read
Returns an existing record from the store, if one exists, and uses it to update the annotated fields of a target object.The context and key to look up are obtained from the target object, and the value and expiration are written back, using the annotations in the org.opensaml.storage.annotation package. If any are missing, or a field inaccessible, a runtime exception of some kind will occur.
- Specified by:
readin interfaceStorageService- Parameters:
value- object to look up and populate- Returns:
- the updated object passed into the method, or null if no record was found
- Throws:
IOException- if errors occur in the read process
-
update
public <T> boolean update(@Nonnull @NotEmpty String context, @Nonnull @NotEmpty String key, @Nonnull T value, @Nonnull StorageSerializer<T> serializer, @Nullable @Positive Long expiration) throws IOException Updates an existing record in the store using a custom serialization strategy.- Specified by:
updatein interfaceStorageService- Type Parameters:
T- type of record- Parameters:
context- a storage context labelkey- a key unique to contextvalue- updated valueserializer- custom serializerexpiration- 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 <T> Long updateWithVersion(@Positive long version, @Nonnull @NotEmpty String context, @Nonnull @NotEmpty String key, @Nonnull T value, @Nonnull StorageSerializer<T> serializer, @Nullable @Positive Long expiration) throws IOException, VersionMismatchException Updates an existing record in the store, if a version matches, using a custom serialization strategy.- Specified by:
updateWithVersionin interfaceStorageService- Type Parameters:
T- type of record- Parameters:
version- only update if the current version matches this valuecontext- a storage context labelkey- a key unique to contextvalue- updated valueserializer- custom serializerexpiration- 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
-
update
Updates an existing record in the store, using an annotated object as the source.The individual parameters for the update are extracted from the object using the annotations in the org.opensaml.storage.annotation package. If any are missing, or a field inaccessible, a runtime exception of some kind will occur.
- Specified by:
updatein interfaceStorageService- Parameters:
value- object to update from- 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(@Positive long version, @Nonnull Object value) throws IOException, VersionMismatchException Updates an existing record in the store, if a version matches, using an annotated object as the source.The individual parameters for the update are extracted from the object using the annotations in the org.opensaml.storage.annotation package. If any are missing, or a field inaccessible, a runtime exception of some kind will occur.
- Specified by:
updateWithVersionin interfaceStorageService- Parameters:
version- only update if the current version matches this valuevalue- object to update from- 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
Updates expiration of an existing record in the store, using an annotated object as the source.The individual parameters for the update are extracted from the object using the annotations in the org.opensaml.storage.annotation package. If any are missing, or a field inaccessible, a runtime exception of some kind will occur.
- Specified by:
updateExpirationin interfaceStorageService- Parameters:
value- object to update from- Returns:
- true if the update succeeded, false if the record does not exist
- Throws:
IOException- if errors occur in the update process
-
delete
Deletes an existing record from the store, using an annotated object as the source.The individual parameters for the deletion are extracted from the object using the annotations in the org.opensaml.storage.annotation package. If any are missing, or a field inaccessible, a runtime exception of some kind will occur.
- Specified by:
deletein interfaceStorageService- Parameters:
value- object to delete- Returns:
- true iff the record existed and was deleted
- Throws:
IOException- if errors occur in the deletion process
-
deleteWithVersion
public boolean deleteWithVersion(@Positive long version, @Nonnull Object value) throws IOException, VersionMismatchException Deletes an existing record from the store, using an annotated object as the source, if it currently has a specified version.The individual parameters for the deletion are extracted from the object using the annotations in the org.opensaml.storage.annotation package. If any are missing, or a field inaccessible, a runtime exception of some kind will occur.
- Specified by:
deleteWithVersionin interfaceStorageService- Parameters:
version- record version to deletevalue- object to delete- 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
-