Package com.atlan.cache
Class AbstractMassCache<T extends AtlanObject>
java.lang.Object
com.atlan.cache.AbstractMassCache<T>
- All Implemented Interfaces:
Closeable
,AutoCloseable
- Direct Known Subclasses:
AtlanTagCache
,CustomMetadataCache
,GroupCache
,RoleCache
,UserCache
Base class for reusable components that are common to all caches, where
a cache is populated en-masse through batch refreshing.
-
Field Summary
Modifier and TypeFieldDescriptionprotected AtomicBoolean
Whether to refresh the cache by retrieving all objects up-front (true) or lazily, on-demand (false).protected final ReadWriteLock
-
Constructor Summary
ConstructorDescriptionAbstractMassCache
(AtlanClient client, String cacheName) Define a new mass cache with the provided details. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
Add an entry to the cache.protected void
Add an entry to the cache.void
Wraps a single object lookup for the cache with necessary concurrency controls.void
cacheByName
(String name) Wraps a single object lookup for the cache with necessary concurrency controls.void
cacheBySid
(String sid) Wraps a single object lookup for the cache with necessary concurrency controls.void
close()
entrySet()
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.Retrieve the actual object by Atlan-internal ID string.Retrieve the actual object by human-readable name.Retrieve the actual object by human-readable name.Retrieve the actual object by Atlan-internal secondary ID string.Retrieve the actual object by Atlan-internal secondary ID string.getIdForName
(String 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.getIdForSid
(String sid) Translate the provided Atlan-internal secondary ID to its Atlan-internal ID string.getIdForSid
(String sid, boolean allowRefresh) Translate the provided Atlan-internal secondary ID to its Atlan-internal ID string.protected String
getIdFromName
(String name) Thread-safe cache retrieval of the ID of an object by its name.protected String
getIdFromSid
(String sid) Thread-safe cache retrieval of the ID of an object by its secondary ID.getNameForId
(String id) 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.getNameForSid
(String sid) Translate the provided Atlan-internal secondary ID string to the human-readable name for the object.getNameForSid
(String sid, boolean allowRefresh) Translate the provided Atlan-internal secondary ID string to the human-readable name for the object.protected String
getNameFromId
(String id) Thread-safe cache retrieval of the name of an object by its ID.protected String
getNameFromId
(String id, boolean bypassReadLock) Thread-safe cache retrieval of the name of an object by its ID, when not bypassing the read lock.protected String
getNameFromSid
(String sid) Thread-safe cache retrieval of the name of an object by its secondary ID.protected T
getObjectById
(String id) Thread-safe cache retrieval of the object itself, by its ID.getSidForName
(String name) Translate the provided human-readable name to its Atlan-internal secondary ID string.getSidForName
(String name, boolean allowRefresh) Translate the provided human-readable name to its Atlan-internal secondary ID string.protected String
getSidFromId
(String id) Thread-safe cache retrieval of the secondary ID of an object by its ID.protected String
getSidFromName
(String name) Thread-safe cache retrieval of the secondary ID of an object by its name.protected boolean
isEmpty()
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
isNameKnown
(String name) Checks whether the provided human-readable name is known.protected abstract void
lookupById
(String id) Logic to look up a single object for the cache.protected abstract void
lookupByName
(String name) Logic to look up a single object for the cache.protected void
lookupBySid
(String sid) Logic to look up a single object for the cache.void
refresh()
Wraps the cache refresh with necessary concurrency controls.protected abstract void
Logic to refresh a specific cache en-masse (must be implemented).
-
Field Details
-
lock
-
bulkRefresh
Whether to refresh the cache by retrieving all objects up-front (true) or lazily, on-demand (false).
-
-
Constructor Details
-
AbstractMassCache
Define a new mass cache with the provided details. Note: ideally, before using, also set the total capacity.- Parameters:
cacheName
- name of the cache
-
-
Method Details
-
refresh
Wraps the cache refresh with necessary concurrency controls. Always call this method to actually update a cache, not the directly-implemented, cache-specificrefreshCache
.- Throws:
AtlanException
- on any error communicating with Atlan to refresh the cache of objects
-
cacheById
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
-
cacheBySid
Wraps a single object lookup for the cache with necessary concurrency controls.- Parameters:
sid
- unique secondary internal identifier for the object- Throws:
AtlanException
- on any error communicating with Atlan
-
cacheByName
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
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
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
-
lookupBySid
Logic to look up a single object for the cache. Note: by default this is not implemented (and will immediately error), so override it if you intend the cache to be populated by secondary ID lookups.- Parameters:
sid
- unique secondary internal identifier for the object- Throws:
AtlanException
- on any error communicating with AtlanInvalidRequestException
- if not overridden with logic to update cache by secondary ID lookups
-
lookupByName
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
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 (UUID)name
- human-readable nameobject
- the object to cache (if any)
-
cache
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 (UUID)sid
- secondary Atlan-internal ID (hashed-string / nanoID)name
- human-readable nameobject
- 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
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
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
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
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
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
-
getNameFromId
Thread-safe cache retrieval of the name of an object by its ID, when not bypassing the read lock. Note: this allows you to bypass the read lock, in order to avoid potential deadlock situations, however you should ONLY do this if you know PRECISELY that you are still controlling the ordering of reads and writes (as concurrency safety will be bypassed when the read lock is bypassed) -- if you are not careful you may get a cache miss which would otherwise have been a cache hit.- Parameters:
id
- of the objectbypassReadLock
- whether to bypass the read lock (necessary if we're reading while inside a write lock)- Returns:
- the name of the object (if cached), or null
-
getIdFromSid
Thread-safe cache retrieval of the ID of an object by its secondary ID.- Parameters:
sid
- of the object- Returns:
- the ID of the object (if cached), or null
-
getSidFromId
Thread-safe cache retrieval of the secondary ID of an object by its ID.- Parameters:
id
- of the object- Returns:
- the secondary ID of the object (if cached), or null
-
getSidFromName
Thread-safe cache retrieval of the secondary ID of an object by its name.- Parameters:
name
- of the object- Returns:
- the secondary ID of the object (if cached), or null
-
getNameFromSid
Thread-safe cache retrieval of the name of an object by its secondary ID.- Parameters:
sid
- of the object- Returns:
- the name of the object (if cached), or null
-
getObjectById
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
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 refreshedNotFoundException
- if the object cannot be found (does not exist) in AtlanInvalidRequestException
- if no name was provided for the object to retrieve
-
getIdForName
Translate the provided human-readable name to its Atlan-internal ID string.- Parameters:
name
- human-readable name of the objectallowRefresh
- 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 refreshedNotFoundException
- if the object cannot be found (does not exist) in AtlanInvalidRequestException
- if no name was provided for the object to retrieve
-
getIdForSid
Translate the provided Atlan-internal secondary ID to its Atlan-internal ID string.- Parameters:
sid
- Atlan-internal secondary ID- Returns:
- unique Atlan-internal ID string for the object
- Throws:
AtlanException
- on any API communication problem if the cache needs to be refreshedNotFoundException
- if the object cannot be found (does not exist) in AtlanInvalidRequestException
- if no name was provided for the object to retrieve
-
getIdForSid
Translate the provided Atlan-internal secondary ID to its Atlan-internal ID string.- Parameters:
sid
- Atlan-internal secondary IDallowRefresh
- 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 refreshedNotFoundException
- if the object cannot be found (does not exist) in AtlanInvalidRequestException
- if no name was provided for the object to retrieve
-
getSidForName
Translate the provided human-readable name to its Atlan-internal secondary ID string.- Parameters:
name
- human-readable name of the object- Returns:
- unique Atlan-internal secondary ID string for the object
- Throws:
AtlanException
- on any API communication problem if the cache needs to be refreshedNotFoundException
- if the object cannot be found (does not exist) in AtlanInvalidRequestException
- if no name was provided for the object to retrieve
-
getSidForName
Translate the provided human-readable name to its Atlan-internal secondary ID string.- Parameters:
name
- human-readable name of the objectallowRefresh
- whether to allow a refresh of the cache (true) or not (false)- Returns:
- unique Atlan-internal secondary ID string for the object
- Throws:
AtlanException
- on any API communication problem if the cache needs to be refreshedNotFoundException
- if the object cannot be found (does not exist) in AtlanInvalidRequestException
- if no name was provided for the object to retrieve
-
getNameForId
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 refreshedNotFoundException
- if the object cannot be found (does not exist) in AtlanInvalidRequestException
- if no name was provided for the object to retrieve
-
getNameForId
Translate the provided Atlan-internal ID string to the human-readable name for the object.- Parameters:
id
- Atlan-internal ID stringallowRefresh
- 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 refreshedNotFoundException
- if the object cannot be found (does not exist) in AtlanInvalidRequestException
- if no name was provided for the object to retrieve
-
getNameForSid
Translate the provided Atlan-internal secondary ID string to the human-readable name for the object.- Parameters:
sid
- Atlan-internal secondary ID string- Returns:
- human-readable name of the object
- Throws:
AtlanException
- on any API communication problem if the cache needs to be refreshedNotFoundException
- if the object cannot be found (does not exist) in AtlanInvalidRequestException
- if no name was provided for the object to retrieve
-
getNameForSid
Translate the provided Atlan-internal secondary ID string to the human-readable name for the object.- Parameters:
sid
- Atlan-internal secondary ID stringallowRefresh
- 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 refreshedNotFoundException
- if the object cannot be found (does not exist) in AtlanInvalidRequestException
- if no name was provided for the object to retrieve
-
getById
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 refreshedNotFoundException
- if the object cannot be found (does not exist) in AtlanInvalidRequestException
- if no ID was provided for the object to retrieve
-
getById
Retrieve the actual object by Atlan-internal ID string.- Parameters:
id
- Atlan-internal ID stringallowRefresh
- 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 refreshedNotFoundException
- if the object cannot be found (does not exist) in AtlanInvalidRequestException
- if no ID was provided for the object to retrieve
-
getBySid
Retrieve the actual object by Atlan-internal secondary ID string.- Parameters:
sid
- Atlan-internal secondary ID string- Returns:
- the object with that secondary ID
- Throws:
AtlanException
- on any API communication problem if the cache needs to be refreshedNotFoundException
- if the object cannot be found (does not exist) in AtlanInvalidRequestException
- if no ID was provided for the object to retrieve
-
getBySid
Retrieve the actual object by Atlan-internal secondary ID string.- Parameters:
sid
- Atlan-internal secondary ID stringallowRefresh
- whether to allow a refresh of the cache (true) or not (false)- Returns:
- the object with that secondary ID
- Throws:
AtlanException
- on any API communication problem if the cache needs to be refreshedNotFoundException
- if the object cannot be found (does not exist) in AtlanInvalidRequestException
- if no ID was provided for the object to retrieve
-
getByName
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 refreshedNotFoundException
- if the object cannot be found (does not exist) in AtlanInvalidRequestException
- if no name was provided for the object to retrieve
-
getByName
Retrieve the actual object by human-readable name.- Parameters:
name
- human-readable name of the objectallowRefresh
- 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 refreshedNotFoundException
- if the object cannot be found (does not exist) in AtlanInvalidRequestException
- if no name was provided for the object to retrieve
-
close
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Throws:
IOException
-
getBulkRefresh
Whether to refresh the cache by retrieving all objects up-front (true) or lazily, on-demand (false).
-