Class StorageServiceReplayCache

All Implemented Interfaces:
Component, DestructableComponent, IdentifiableComponent, IdentifiedComponent, InitializableComponent, ReplayCache

@ThreadSafeAfterInit public class StorageServiceReplayCache extends AbstractIdentifiableInitializableComponent implements ReplayCache
ReplayCache implementation backed by a StorageService.

This class is thread-safe and uses a synchronized method to prevent race conditions within the underlying store (lacking an atomic "check and insert" operation).

Since:
5.0.0
  • Field Details

    • log

      @Nonnull private final org.slf4j.Logger log
      Logger.
    • storage

      Backing storage for the replay cache.
    • digester

      Digester if key is too long.
    • strict

      private boolean strict
      Flag controlling behavior on storage failure.
  • Constructor Details

    • StorageServiceReplayCache

      public StorageServiceReplayCache()
  • Method Details

    • getStorage

      @NonnullAfterInit public StorageService getStorage()
      Get the backing store for the cache.
      Returns:
      the backing store.
    • setStorage

      public void setStorage(@Nonnull StorageService storageService)
      Set the backing store for the cache.
      Parameters:
      storageService - backing store to use
    • isStrict

      public boolean isStrict()
      Get the strictness flag.
      Returns:
      true iff we should treat storage failures as a replay
    • setStrict

      public void setStrict(boolean flag)
      Set the strictness flag.
      Parameters:
      flag - true iff we should treat storage failures as a replay
    • doInitialize

      public void doInitialize() throws ComponentInitializationException
      Overrides:
      doInitialize in class AbstractIdentifiedInitializableComponent
      Throws:
      ComponentInitializationException
    • check

      public boolean check(@Nonnull @NotEmpty String context, @Nonnull @NotEmpty String s, @Nonnull Instant expires)
      Returns true iff the check value is not found in the cache, and stores it.
      Specified by:
      check in interface ReplayCache
      Parameters:
      context - a context label to subdivide the cache
      s - key to check
      expires - time for disposal of value from cache
      Returns:
      true iff the check value is not found in the cache