Class AbstractMassCache<T extends AtlanObject>

java.lang.Object
com.atlan.cache.AbstractMassCache<T>
Direct Known Subclasses:
AtlanTagCache, CustomMetadataCache, GroupCache, RoleCache, UserCache

public abstract class AbstractMassCache<T extends AtlanObject> extends Object
Base class for reusable components that are common to all caches, where a cache is populated en-masse through batch refreshing.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected AtomicBoolean
    Whether to refresh the cache by retrieving all objects up-front (true) or lazily, on-demand (false).
    protected final ReadWriteLock
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected void
    cache(String id, String name, T object)
    Add an entry to the cache.
    void
    Wraps a single object lookup for the cache with necessary concurrency controls.
    void
    Wraps a single object lookup for the cache with necessary concurrency controls.
    protected Set<Map.Entry<String,T>>
    Retrieve an iterable set of entries for the object-storing portion of the cache.
    Whether to refresh the cache by retrieving all objects up-front (true) or lazily, on-demand (false).
    Retrieve the actual object by Atlan-internal ID string.
    getById(String id, boolean allowRefresh)
    Retrieve the actual object by Atlan-internal ID string.
    Retrieve the actual object by human-readable name.
    getByName(String name, boolean allowRefresh)
    Retrieve the actual object by human-readable name.
    Translate the provided human-readable name to its Atlan-internal ID string.
    getIdForName(String name, boolean allowRefresh)
    Translate the provided human-readable name to its Atlan-internal ID string.
    protected String
    Thread-safe cache retrieval of the ID of an object by its name.
    Translate the provided Atlan-internal ID string to the human-readable name for the object.
    getNameForId(String id, boolean allowRefresh)
    Translate the provided Atlan-internal ID string to the human-readable name for the object.
    protected String
    Thread-safe cache retrieval of the name of an object by its ID.
    protected T
    Thread-safe cache retrieval of the object itself, by its ID.
    protected boolean
    Whether the object-storing portion of the cache is empty (true) or not (false).
    boolean
    Checks whether the provided Atlan-internal ID string is known.
    boolean
    Checks whether the provided human-readable name is known.
    protected abstract void
    Logic to look up a single object for the cache.
    protected abstract void
    Logic to look up a single object for the cache.
    void
    Wraps the cache refresh with necessary concurrency controls.
    protected abstract void
    Logic to refresh a specific cache en-masse (must be implemented).

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • lock

      protected final ReadWriteLock lock
    • bulkRefresh

      protected AtomicBoolean bulkRefresh
      Whether to refresh the cache by retrieving all objects up-front (true) or lazily, on-demand (false).
  • Constructor Details

    • AbstractMassCache

      public AbstractMassCache()
  • Method Details

    • refresh

      public void refresh() throws AtlanException
      Wraps the cache refresh with necessary concurrency controls. Always call this method to actually update a cache, not the directly-implemented, cache-specific refreshCache.
      Throws:
      AtlanException - on any error communicating with Atlan to refresh the cache of objects
    • cacheById

      public void cacheById(String id) throws AtlanException
      Wraps a single object lookup for the cache with necessary concurrency controls.
      Parameters:
      id - unique internal identifier for the object
      Throws:
      AtlanException - on any error communicating with Atlan
    • cacheByName

      public void cacheByName(String name) throws AtlanException
      Wraps a single object lookup for the cache with necessary concurrency controls.
      Parameters:
      name - unique name for the object
      Throws:
      AtlanException - on any error communicating with Atlan
    • refreshCache

      protected abstract void refreshCache() throws AtlanException
      Logic to refresh a specific cache en-masse (must be implemented).
      Throws:
      AtlanException - on any error communicating with Atlan to refresh the cache of objects
    • lookupById

      protected abstract void lookupById(String id) throws AtlanException
      Logic to look up a single object for the cache.
      Parameters:
      id - unique internal identifier for the object
      Throws:
      AtlanException - on any error communicating with Atlan
    • lookupByName

      protected abstract void lookupByName(String name) throws AtlanException
      Logic to look up a single object for the cache.
      Parameters:
      name - unique name for the object
      Throws:
      AtlanException - on any error communicating with Atlan
    • cache

      protected void cache(String id, String name, T object)
      Add an entry to the cache. This should only be called by the lookup methods, which themselves should never directly be invoked.
      Parameters:
      id - Atlan-internal ID
      name - human-readable name
      object - the object to cache (if any)
    • isEmpty

      protected boolean isEmpty()
      Whether the object-storing portion of the cache is empty (true) or not (false).
      Returns:
      true if no objects are cached, otherwise false
    • entrySet

      protected Set<Map.Entry<String,T>> entrySet()
      Retrieve an iterable set of entries for the object-storing portion of the cache.
      Returns:
      an iterable set of entries of objects that are cached
    • isNameKnown

      public boolean isNameKnown(String name)
      Checks whether the provided human-readable name is known. (Note: will not refresh the cache itself to determine this.)
      Parameters:
      name - human-readable name of the object
      Returns:
      true if the object is known, false otherwise
    • isIdKnown

      public boolean isIdKnown(String id)
      Checks whether the provided Atlan-internal ID string is known. (Note: will not refresh the cache itself to determine this.)
      Parameters:
      id - Atlan-internal ID string of the object
      Returns:
      true if the object is known, false otherwise
    • getIdFromName

      protected String getIdFromName(String name)
      Thread-safe cache retrieval of the ID of an object by its name.
      Parameters:
      name - of the object
      Returns:
      the ID of the object (if cached), or null
    • getNameFromId

      protected String getNameFromId(String id)
      Thread-safe cache retrieval of the name of an object by its ID.
      Parameters:
      id - of the object
      Returns:
      the name of the object (if cached), or null
    • getObjectById

      protected T getObjectById(String id)
      Thread-safe cache retrieval of the object itself, by its ID.
      Parameters:
      id - of the object
      Returns:
      the object itself (if cached), or null
    • getIdForName

      public String getIdForName(String name) throws AtlanException
      Translate the provided human-readable name to its Atlan-internal ID string.
      Parameters:
      name - human-readable name of the object
      Returns:
      unique Atlan-internal ID string for the object
      Throws:
      AtlanException - on any API communication problem if the cache needs to be refreshed
      NotFoundException - if the object cannot be found (does not exist) in Atlan
      InvalidRequestException - if no name was provided for the object to retrieve
    • getIdForName

      public String getIdForName(String name, boolean allowRefresh) throws AtlanException
      Translate the provided human-readable name to its Atlan-internal ID string.
      Parameters:
      name - human-readable name of the object
      allowRefresh - whether to allow a refresh of the cache (true) or not (false)
      Returns:
      unique Atlan-internal ID string for the object
      Throws:
      AtlanException - on any API communication problem if the cache needs to be refreshed
      NotFoundException - if the object cannot be found (does not exist) in Atlan
      InvalidRequestException - if no name was provided for the object to retrieve
    • getNameForId

      public String getNameForId(String id) throws AtlanException
      Translate the provided Atlan-internal ID string to the human-readable name for the object.
      Parameters:
      id - Atlan-internal ID string
      Returns:
      human-readable name of the object
      Throws:
      AtlanException - on any API communication problem if the cache needs to be refreshed
      NotFoundException - if the object cannot be found (does not exist) in Atlan
      InvalidRequestException - if no name was provided for the object to retrieve
    • getNameForId

      public String getNameForId(String id, boolean allowRefresh) throws AtlanException
      Translate the provided Atlan-internal ID string to the human-readable name for the object.
      Parameters:
      id - Atlan-internal ID string
      allowRefresh - whether to allow a refresh of the cache (true) or not (false)
      Returns:
      human-readable name of the object
      Throws:
      AtlanException - on any API communication problem if the cache needs to be refreshed
      NotFoundException - if the object cannot be found (does not exist) in Atlan
      InvalidRequestException - if no name was provided for the object to retrieve
    • getById

      public T getById(String id) throws AtlanException
      Retrieve the actual object by Atlan-internal ID string.
      Parameters:
      id - Atlan-internal ID string
      Returns:
      the object with that ID
      Throws:
      AtlanException - on any API communication problem if the cache needs to be refreshed
      NotFoundException - if the object cannot be found (does not exist) in Atlan
      InvalidRequestException - if no ID was provided for the object to retrieve
    • getById

      public T getById(String id, boolean allowRefresh) throws AtlanException
      Retrieve the actual object by Atlan-internal ID string.
      Parameters:
      id - Atlan-internal ID string
      allowRefresh - whether to allow a refresh of the cache (true) or not (false)
      Returns:
      the object with that ID
      Throws:
      AtlanException - on any API communication problem if the cache needs to be refreshed
      NotFoundException - if the object cannot be found (does not exist) in Atlan
      InvalidRequestException - if no ID was provided for the object to retrieve
    • getByName

      public T getByName(String name) throws AtlanException
      Retrieve the actual object by human-readable name.
      Parameters:
      name - human-readable name of the object
      Returns:
      the object with that name
      Throws:
      AtlanException - on any API communication problem if the cache needs to be refreshed
      NotFoundException - if the object cannot be found (does not exist) in Atlan
      InvalidRequestException - if no name was provided for the object to retrieve
    • getByName

      public T getByName(String name, boolean allowRefresh) throws AtlanException
      Retrieve the actual object by human-readable name.
      Parameters:
      name - human-readable name of the object
      allowRefresh - whether to allow a refresh of the cache (true) or not (false)
      Returns:
      the object with that name
      Throws:
      AtlanException - on any API communication problem if the cache needs to be refreshed
      NotFoundException - if the object cannot be found (does not exist) in Atlan
      InvalidRequestException - if no name was provided for the object to retrieve
    • getBulkRefresh

      public AtomicBoolean getBulkRefresh()
      Whether to refresh the cache by retrieving all objects up-front (true) or lazily, on-demand (false).