Package org.opensaml.storage.impl
Class FilesystemStorageService
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.impl.FilesystemStorageService
- All Implemented Interfaces:
Component,DestructableComponent,IdentifiableComponent,IdentifiedComponent,InitializableComponent,StorageCapabilities,StorageService
Partial implementation of storage backed by filessystem.
Updates are not supported, but creation/deletion are.
- Since:
- 5.3.0
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate booleanTracks use of a shared file system for capability method.private booleanWhether to treat data as binary, using base64 to encoder/decode across String boundary.private booleanWhether service is read only.private StringBase location of storage tree in filesystem. -
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.booleandeleteWithVersion(long version, String context, String key) Deletes an existing record from the store if it currently has a specified version.protected voidbooleanReturns true iff the storage implementation manages data independent of a single server node.booleanReturns true iff the storage implementation manages data independent of the client.<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.voidManually trigger a cleanup of expired records.voidsetClustered(boolean flag) Sets whether the file system is clustered.voidsetEncodeData(boolean flag) Sets whether the service should operate on binary data, encoding to base64 after reads and decoding from base64 on writes.voidsetReadOnly(boolean flag) Sets whether the service should operate read-only.voidsetStorageBase(String base) Sets the base/root directory under which objects will be created and deleted.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.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, getCapabilities, getCleanupInterval, getCleanupTask, getCleanupTaskTimer, getContextSize, getKeySize, getValueSize, read, setCleanupInterval, setCleanupTaskTimer, setContextSize, setKeySize, setValueSize, teardownAbstractStorageService, 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, doDestroy, 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
getId
-
Field Details
-
clustered
private boolean clusteredTracks use of a shared file system for capability method. -
readOnly
private boolean readOnlyWhether service is read only. -
encodeData
private boolean encodeDataWhether to treat data as binary, using base64 to encoder/decode across String boundary. -
storageBase
Base location of storage tree in filesystem.
-
-
Constructor Details
-
FilesystemStorageService
public FilesystemStorageService()Constructor.
-
-
Method Details
-
setClustered
public void setClustered(boolean flag) Sets whether the file system is clustered.Defaults to false.
- Parameters:
flag- flag to set
-
setReadOnly
public void setReadOnly(boolean flag) Sets whether the service should operate read-only.Defaults to true.
- Parameters:
flag- flag to set
-
setEncodeData
public void setEncodeData(boolean flag) Sets whether the service should operate on binary data, encoding to base64 after reads and decoding from base64 on writes.Defaults to false.
- Parameters:
flag- flag to set
-
setStorageBase
Sets the base/root directory under which objects will be created and deleted.Must be an absolute path.
- Parameters:
base- storage root location
-
doInitialize
- Overrides:
doInitializein classAbstractStorageService- Throws:
ComponentInitializationException
-
create
public boolean create(@Nonnull @NotEmpty String context, @Nonnull @NotEmpty String key, @Nonnull @NotEmpty String value, @Nullable @Positive Long expiration) throws IOException Creates a new record in the store with an expiration.- 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.- 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.
- 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 @Positive Long expiration) throws IOException Updates an existing record in the store.- 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
public Long updateWithVersion(long version, @Nonnull @NotEmpty String context, @Nonnull @NotEmpty String key, @Nonnull @NotEmpty String value, @Nullable @Positive Long expiration) throws IOException, VersionMismatchException Updates an existing record in the store, if a version matches.- 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 @Positive Long expiration) throws IOException Updates expiration of an existing record in the store.- 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
-
delete
public boolean delete(@Nonnull @NotEmpty String context, @Nonnull @NotEmpty String key) throws IOException Deletes an existing record from the store.- 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
-
deleteWithVersion
public boolean deleteWithVersion(long version, @Nonnull @NotEmpty String context, @Nonnull @NotEmpty String key) throws IOException, VersionMismatchException Deletes an existing record from the store if it currently has a specified version.- 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
-
reap
Manually trigger a cleanup of expired records. The method MAY return without guaranteeing that cleanup has already occurred.- Parameters:
context- a storage context label- Throws:
IOException- if errors occur in the cleanup process
-
updateContextExpiration
public void updateContextExpiration(@Nonnull @NotEmpty String context, @Nullable @Positive Long expiration) throws IOException Updates the expiration time of all records in the context.- 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.- Parameters:
context- a storage context label- Throws:
IOException- if errors occur in the cleanup process
-
isServerSide
public boolean isServerSide()Returns true iff the storage implementation manages data independent of the client.- Returns:
- true iff the storage implementation manages data independent of the client
-
isClustered
public boolean isClustered()Returns true iff the storage implementation manages data independent of a single server node.- Returns:
- true iff the storage implementation manages data independent of a single server node
-