Class FilesystemStorageService

All Implemented Interfaces:
Component, DestructableComponent, IdentifiableComponent, IdentifiedComponent, InitializableComponent, StorageCapabilities, StorageService

public class FilesystemStorageService extends AbstractStorageService
Partial implementation of storage backed by filessystem.

Updates are not supported, but creation/deletion are.

Since:
5.3.0
  • Field Details

    • clustered

      private boolean clustered
      Tracks use of a shared file system for capability method.
    • readOnly

      private boolean readOnly
      Whether service is read only.
    • encodeData

      private boolean encodeData
      Whether to treat data as binary, using base64 to encoder/decode across String boundary.
    • storageBase

      @NonnullAfterInit private String 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

      public void setStorageBase(@Nonnull @NotEmpty String base)
      Sets the base/root directory under which objects will be created and deleted.

      Must be an absolute path.

      Parameters:
      base - storage root location
    • doInitialize

      protected void doInitialize() throws ComponentInitializationException
      Overrides:
      doInitialize in class AbstractStorageService
      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 label
      key - a key unique to context
      value - value to store
      expiration - 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 label
      key - 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 label
      key - a key unique to context
      version - 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 label
      key - a key unique to context
      value - updated value
      expiration - 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 value
      context - a storage context label
      key - a key unique to context
      value - updated value
      expiration - 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 process
      VersionMismatchException - 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 label
      key - a key unique to context
      expiration - 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 label
      key - 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 delete
      context - a storage context label
      key - a key unique to context
      Returns:
      true iff the record existed and was deleted
      Throws:
      IOException - if errors occur in the deletion process
      VersionMismatchException - if the record has already been updated to a newer version
    • reap

      public void reap(@Nonnull @NotEmpty String context) throws IOException
      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 label
      expiration - a new expiration timestamp, or null
      Throws:
      IOException - if errors occur in the cleanup process
    • deleteContext

      public void deleteContext(@Nonnull @NotEmpty String context) throws IOException
      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