Class AsymmetricKeyCache

java.lang.Object
net.messagevortex.asn1.AsymmetricKeyCache
All Implemented Interfaces:
Serializable

public class AsymmetricKeyCache extends Object implements Serializable

The key cache supporting AsymmetricKey.

See Also:
  • Field Details

  • Constructor Details

    • AsymmetricKeyCache

      public AsymmetricKeyCache()
  • Method Details

    • store

      public void store(String filename) throws IOException

      Stores the cache to the specified filename for later usage.

      Parameters:
      filename - the filename to store to (will replace an existing file)
      Throws:
      IOException - if writing of file fails
    • load

      public void load(String filename) throws IOException

      Loads the cache from the specified filename.

      Parameters:
      filename - the filename to read from
      Throws:
      IOException - if reading of file fails
    • merge

      public void merge(String filename) throws IOException

      Adds the keys in the specified file to the cache.

      Parameters:
      filename - the filename of the cache to merge
      Throws:
      IOException - if reading of the file fails
    • setCalcTime

      public void setCalcTime(AlgorithmParameter ap, long millis)

      Sets the time for a calculation with the specified parameter.

      Parameters:
      ap - parameter set
      millis - the time in milliseconds it takes on average to calculate the key
    • pull

      public AsymmetricKey pull(AlgorithmParameter parameter)

      Gets a precalculated key from the cache.

      Parameters:
      parameter - the parameter set requested
      Returns:
      the key or null if no such key is available in the cache
    • peek

      public AsymmetricKey peek(AlgorithmParameter parameter)

      Gets a precalculated key from the cache without removing it.

      Parameters:
      parameter - the parameter set requested
      Returns:
      the key or null if no such key is available in the cache
    • push

      public void push(AsymmetricKey key)

      store a precalculated key into the cache.

      Parameters:
      key - the key to be stored
    • requestCacheIncrease

      public void requestCacheIncrease(AlgorithmParameter parameter)

      Increase the cache size for the specified parameter set.

      Parameters:
      parameter - the parameter set to be increased
    • getSpeculativeParameter

      public AlgorithmParameter getSpeculativeParameter()

      Gets a set of parameter which should be calculated next.

      Returns:
      the parameter set
    • getLowestCacheSize

      public double getLowestCacheSize()

      Get the size of the lowest cache in fraction of percent.

      Returns:
      the fill state of the lowest cache (bounds 0..1)
    • getCacheFillGrade

      public double getCacheFillGrade()

      Get the total cache fill grade in percent.

      Returns:
      the fill state of cache (bounds 0..1)
    • clear

      public void clear()

      Remove all elements from the cache.

    • isEmpty

      public boolean isEmpty()

      Check if the cache is empty.

      Returns:
      true if the cache is empty
    • setCacheSize

      public void setCacheSize(int index, int value) throws IOException

      Set the expected size of the cache.

      Parameters:
      index - index of the cache to be set
      value - the new size of the specified cache
      Throws:
      IOException - if the index is not known to the cache
    • removeCacheElement

      public void removeCacheElement(int index) throws IOException

      Remove the specified key type from cache.

      Parameters:
      index - the index of the cache to be removed
      Throws:
      IOException - if the index does not belong to a known element
    • showStats

      public void showStats()

      Dumps cache stats to the logger.