Interface ILspGLResourceCache
- All Superinterfaces:
ILcdMultiKeyMap<Object,
,ALspGLResource> Map<Object,
ALspGLResource>
Cache that stores OpenGL resource objects. When storing a resource
object, the cache becomes its owner and can freely destroy and
remove the resource when needed.
Storing a new entry in the cache can result in the removal and destruction of one
or more existing entries due to size limitations (getMaxBytes()
).
Bound ALspGLResource
are never removed. Since using the cache can
result in a call to destroy
,
this cache can only be accessed from the painting thread.
ILcdMultiKeyMap
that
allows storage and retrieval of OpenGL resource objects by a sequence of keys.
This facilitates removal of multiple resources at once by removing an entire
branch of the cache tree for example. See ILcdMultiKeyMap
for a detailed description
of the workings of a multi-key map.
The resource cache is not thread-safe and should only be accessed from
the painting thread.- Since:
- 2012.0
- See Also:
-
Nested Class Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addCacheListener
(ILspGLResourceCacheListener aListener) Adds the given listener so that it gets notified of key resource events (addition, usage, removal).Set
<? extends Map.Entry<Object, ? extends ILspGLResourceCache>> Gets the entries of this branch's branch map.Collection
<? extends ILspGLResourceCache> Gets the values of this branch's leaf map.void
destroy
(ILcdGLDrawable aGLDrawable) Frees all resources stored in the cache.Returns the branch that is associated with the given key, ornull
if the branch does not exist.long
getBytes()
Gets the sum of the total number of bytes allocated by the resources stored in the cache.long
Gets the sum of the total number of bytes allocated by the resources stored in the cache for the given identifier.long
Gets the maximal number of bytes that can be stored in this cache.getOrCreateBranch
(Object[] aKeys) Creates and returns a new branch for the given key.int
Gets the number of resources stored in the cache.Gets the resources' source strings sorted in decreasing bytes usage orders.void
removeCacheListener
(ILspGLResourceCacheListener aListener) Removes the given listener so that it stops being notified of resource events.Methods inherited from interface com.luciad.util.collections.ILcdMultiKeyMap
branchKeySet, branchSize, clearRecursive, get, put, recursiveLeafKeySet, remove, removeRecursive
Methods inherited from interface java.util.Map
clear, compute, computeIfAbsent, computeIfPresent, containsKey, containsValue, entrySet, equals, forEach, get, getOrDefault, hashCode, isEmpty, keySet, merge, put, putAll, putIfAbsent, remove, remove, replace, replace, replaceAll, size, values
-
Method Details
-
destroy
Frees all resources stored in the cache.- Parameters:
aGLDrawable
- drawable
-
getResourceCount
int getResourceCount()Gets the number of resources stored in the cache.- Returns:
- the number of resources stored in the cache
-
getBytes
long getBytes()Gets the sum of the total number of bytes allocated by the resources stored in the cache.- Returns:
- the total number of bytes held by resources stored in the cache.
-
getBytes
Gets the sum of the total number of bytes allocated by the resources stored in the cache for the given identifier.- Parameters:
aSourceString
- the identifier for which the memory usage is queried- Returns:
- the total number of bytes held by resources stored in the cache for the given identifier
-
getMaxBytes
long getMaxBytes()Gets the maximal number of bytes that can be stored in this cache.- Returns:
- the maximal number of bytes that can be stored in this cache
-
getSourceStringsInDecreasingOrder
Collection<String> getSourceStringsInDecreasingOrder()Gets the resources' source strings sorted in decreasing bytes usage orders. The source with the most bytes occupied in the cache is the first in the returned collection, the one with the least bytes occupied the last. This list can be useful for debugging purposes.- Returns:
- the source string identifiers of resources stored in the cache in decreasing bytes usage order.
-
addCacheListener
Adds the given listener so that it gets notified of key resource events (addition, usage, removal).It is highly discouraged to add listeners to the GL resource cache for production purposes since this may result in the generation of a large amount of
TLspGLResourceCacheEvent
objects. However, it can be useful during monitoring or debugging.- Parameters:
aListener
- the listener
-
removeCacheListener
Removes the given listener so that it stops being notified of resource events.- Parameters:
aListener
- the listener to remove.
-
getBranch
Description copied from interface:ILcdMultiKeyMap
Returns the branch that is associated with the given key, ornull
if the branch does not exist.- Specified by:
getBranch
in interfaceILcdMultiKeyMap<Object,
ALspGLResource> - Parameters:
aKeys
- the key- Returns:
- the branch associated with the given key, can be
null
if a branch does not exist. - See Also:
-
getOrCreateBranch
Description copied from interface:ILcdMultiKeyMap
Creates and returns a new branch for the given key. A new branch (or sub-branch) is only created when necessary.- Specified by:
getOrCreateBranch
in interfaceILcdMultiKeyMap<Object,
ALspGLResource> - Parameters:
aKeys
- the key- Returns:
- the branch associated with the given key. This method never returns
null
.
-
branchEntrySet
Set<? extends Map.Entry<Object,? extends ILspGLResourceCache>> branchEntrySet()Description copied from interface:ILcdMultiKeyMap
Gets the entries of this branch's branch map.- Specified by:
branchEntrySet
in interfaceILcdMultiKeyMap<Object,
ALspGLResource> - Returns:
- the branch entry set
-
branchValues
Collection<? extends ILspGLResourceCache> branchValues()Description copied from interface:ILcdMultiKeyMap
Gets the values of this branch's leaf map.- Specified by:
branchValues
in interfaceILcdMultiKeyMap<Object,
ALspGLResource> - Returns:
- the branch value set
-