Class OffHeapAssetCache

java.lang.Object
com.atlan.cache.OffHeapAssetCache
All Implemented Interfaces:
Closeable, AutoCloseable

public class OffHeapAssetCache extends Object
Generic class through which to cache any assets efficiently, off-heap, to avoid risking extreme memory usage.
  • Constructor Details

    • OffHeapAssetCache

      public OffHeapAssetCache(AtlanClient client, String name)
      Construct new asset cache.
      Parameters:
      client - connectivity to the Atlan tenant
      name - must be unique across the running code
  • Method Details

    • add

      public void add(Asset asset)
      Add an asset into the cache. Note: the object MUST have a real (not a placeholder) UUID to be cached.
      Parameters:
      asset - to add to the cache
    • extendedWith

      public void extendedWith(OffHeapAssetCache other, boolean closeOriginal) throws IOException
      Extend this cache with all the entries from the provided cache.
      Parameters:
      closeOriginal - if true, close the provided cache after the extension is complete
      other - other cache with which to extend this one
      Throws:
      IOException - on any error closing the provided cache
    • extendedWith

      public void extendedWith(OffHeapAssetCache other, boolean closeOriginal, Predicate<Asset> isValid) throws IOException
      Extend this cache with all the entries from the provided cache.
      Parameters:
      other - other cache with which to extend this one
      closeOriginal - if true, close the provided cache after the extension is complete
      isValid - boolean method that takes a single asset as an argument, and only when evaluated to true for an asset in the other cache will that entry from the other cache be included in this one
      Throws:
      IOException - on any error closing the provided cache
    • get

      public Asset get(String id)
      Retrieve an object from the cache by its ID.
      Parameters:
      id - of the object to retrieve
      Returns:
      the object with that UUID, or null if it is not in the cache
    • put

      protected void put(String id, Asset object)
      Put an object into the cache by its ID.
      Parameters:
      id - of the object to put into the cache
      object - to put into the cache
    • putAll

      protected void putAll(com.atlan.cache.AbstractOffHeapCache<Asset> other)
      Put all the provided entries into the cache.
      Parameters:
      other - cache of entries to add to the cache
    • containsKey

      public boolean containsKey(String id)
      Check whether the cache has an object in it with the provided UUID.
      Parameters:
      id - of the object to check exists in the cache
      Returns:
      true if and only if the cache has an object with this UUID in it
    • size

      public long size()
      Retrieve the number of objects currently held in the cache.
      Returns:
      the number of objects currently in the cache
    • getSize

      public long getSize()
      Retrieve the number of objects currently held in the cache.
      Returns:
      the number of objects currently in the cache
    • isEmpty

      public boolean isEmpty()
      Indicates whether the cache has no entries.
      Returns:
      true if the cache has no entries, otherwise false
    • isNotEmpty

      public boolean isNotEmpty()
      Indicates whether the cache has any entries.
      Returns:
      true if the cache has at least one entry, otherwise false
    • values

      public Stream<Asset> values()
      Retrieve all the objects held in the cache.
      Returns:
      a collection of all objects held in the cache
    • entrySet

      public Stream<Map.Entry<String,Asset>> entrySet()
      Retrieve all entries held in the cache.
      Returns:
      an entry set of all objects (and keys) held in the cache
    • isNotClosed

      public boolean isNotClosed()
      Indicates whether the cache has already been closed.
      Returns:
      true if the cache has been closed, otherwise false
    • close

      public void close() throws IOException
      Clean up the cache, once it is no longer needed.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Throws:
      IOException - if unable to remove the temporary file holding the cache
    • getName

      public String getName()