Class StandardQuotaStrategy

  • All Implemented Interfaces:
    QuotaManagerStrategy, UsageTracker

    public class StandardQuotaStrategy
    extends java.lang.Object
    implements QuotaManagerStrategy, UsageTracker
    Quota manager for the CachingContentStore that has the following characteristics:

    When a cache file has been written that results in cleanThresholdPct (default 80%) of maxUsageBytes being exceeded then the cached content cleaner is invoked (if not already running) in a new thread.

    When the CachingContentStore is about to write a cache file but the disk usage is in excess of panicThresholdPct (default 90%) then the cache file is not written and the cleaner is started (if not already running) in a new thread.

    This quota manager works in conjunction with the cleaner to update disk usage levels in memory. When the quota manager shuts down the current disk usage is saved to disk in {ContentCacheImpl.cacheRoot}/cache-usage.ser

    Upon startup, if the cache-usage.ser file exists then the current usage is seeded with that value and the cleaner is invoked in a new thread so that the value can be updated more accurately (perhaps some files were deleted manually after shutdown for example).

    Author:
    Matt Ward
    • Constructor Detail

      • StandardQuotaStrategy

        public StandardQuotaStrategy()
    • Method Detail

      • init

        public void init()
        Lifecycle method. Should be called immediately after constructing objects of this type (e.g. by the Spring framework's application context).
      • shutdown

        public void shutdown()
        Lifecycle method. Should be called when finished using an object of this type and before the application container is shutdown (e.g. using a Spring framework destroy method).
      • beforeWritingCacheFile

        public boolean beforeWritingCacheFile​(long contentSizeBytes)
        Description copied from interface: QuotaManagerStrategy
        Called immediately before writing a cache file or (when cacheOnInBound is set to true for the CachingContentStore) before handing a ContentWriter to a content producer.

        In the latter case, the contentSize will be unknown (0), since the content length hasn't been established yet.

        Specified by:
        beforeWritingCacheFile in interface QuotaManagerStrategy
        Parameters:
        contentSizeBytes - The size of the content that will be written or 0 if not known.
        Returns:
        true to allow the cache file to be written, false to veto.
      • afterWritingCacheFile

        public boolean afterWritingCacheFile​(long contentSizeBytes)
        Description copied from interface: QuotaManagerStrategy
        Called immediately after writing a cache file - specifying the size of the file that was written. The return value allows implementations control over whether the new cache file is kept (true) or immediately removed (false).
        Specified by:
        afterWritingCacheFile in interface QuotaManagerStrategy
        Parameters:
        contentSizeBytes - The size of the content that was written.
        Returns:
        true to allow the cache file to remain, false to immediately delete.
      • setMaxUsageMB

        public void setMaxUsageMB​(long maxUsageMB)
      • setMaxUsageBytes

        public void setMaxUsageBytes​(long maxUsageBytes)
      • setPanicThresholdPct

        public void setPanicThresholdPct​(int panicThresholdPct)
      • setCleanThresholdPct

        public void setCleanThresholdPct​(int cleanThresholdPct)
      • setTargetUsagePct

        public void setTargetUsagePct​(int targetUsagePct)
      • setNormalCleanThresholdSec

        public void setNormalCleanThresholdSec​(long normalCleanThresholdSec)
      • getCurrentUsageMB

        public double getCurrentUsageMB()
      • getMaxUsageBytes

        public long getMaxUsageBytes()
      • getMaxUsageMB

        public long getMaxUsageMB()
      • getMaxFileSizeMB

        public int getMaxFileSizeMB()
      • getMaxFileSizeBytes

        protected long getMaxFileSizeBytes()
      • setMaxFileSizeMB

        public void setMaxFileSizeMB​(int maxFileSizeMB)