Package chemaxon.jchem.db.cache
Enum Class CacheManager
- All Implemented Interfaces:
chemaxon.jchem.db.cache.CacheManagerMXBean
,Serializable
,Comparable<CacheManager>
,java.lang.constant.Constable
@PublicAPI
public enum CacheManager
extends Enum<CacheManager>
implements chemaxon.jchem.db.cache.CacheManagerMXBean
Singleton for managing cache-related functions. Object available as
CacheManager.INSTANCE.
- Since:
- 6.0
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enum
For internal use only.Nested classes/interfaces inherited from class java.lang.Enum
Enum.EnumDesc<E extends Enum<E>>
-
Enum Constant Summary
Enum Constants -
Method Summary
Modifier and TypeMethodDescriptionvoid
Clears the cache that stores fingerprints and structures.chemaxon.jchem.db.cache.JChemCache
findCache
(ConnectionHandler ch, String tableName, boolean cartridgeMode) For internal use only.Gets the names and sizes of tables currently in the cache.chemaxon.jchem.db.cache.CacheRemovalMethod
For internal use only.boolean
Gets the default pin behavior of loading cache.boolean
isCacheLoaded
(ConnectionHandler connectionHandler, String tableName) Returns whether the cache is loaded.boolean
isCacheLoadStarted
(ConnectionHandler connectionHandler, String tableName) Returns whether the cache is loaded or cache load has been started.void
loadCache
(ConnectionHandler connectionHandler, String tableName, boolean haltOnError) Loads or updates cache directly into memory without making a (first) search in the table.void
loadCache
(ConnectionHandler connectionHandler, String tableName, boolean haltOnError, boolean pinCache) Loads or updates cache directly into memory without making a (first) search in the table.void
loadCache
(ConnectionHandler connectionHandler, String tableName, String indexedTable, String indexedColumn, boolean haltOnError, boolean pinCache) For internal use only.void
pinCache
(ConnectionHandler connectionHandler, String tableName) Pins cache into memory.void
setCacheExpirationTime
(double hours) Sets the expiration time for the structure cache.void
setCacheRemovalMethod
(chemaxon.jchem.db.cache.CacheRemovalMethod cacheRemovalMethod) For internal use only.void
setMaxCacheSize
(int maxCacheSizeMB) Sets the desired cache memory allocation policy.void
setMinNonCachedMemory
(int minNonCachedMemoryMB) Sets the desired cache memory allocation policy.void
setPinCacheDefaultValue
(boolean pinCacheDefaultValue) Sets the default pin behavior of loading cache.void
unloadCache
(ConnectionHandler connectionHandler, String tableName) Unloads cache from the memory.void
unloadCache
(ConnectionHandler connectionHandler, String tableName, boolean cartridgeMode, boolean haltOnError) For internal use only.void
unpinCache
(ConnectionHandler connectionHandler, String tableName) Unpins cache from memory without making a (first) search in the table.static CacheManager
Returns the enum constant of this class with the specified name.static CacheManager[]
values()
Returns an array containing the constants of this enum class, in the order they are declared.
-
Enum Constant Details
-
INSTANCE
-
-
Method Details
-
values
Returns an array containing the constants of this enum class, in the order they are declared.- Returns:
- an array containing the constants of this enum class, in the order they are declared
-
valueOf
Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)- Parameters:
name
- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
IllegalArgumentException
- if this enum class has no constant with the specified nameNullPointerException
- if the argument is null
-
setPinCacheDefaultValue
public void setPinCacheDefaultValue(boolean pinCacheDefaultValue) Sets the default pin behavior of loading cache. It relates to both automatically and manually loaded caches.- Parameters:
pinCacheDefaultValue
- set the new default value- Since:
- 6.0
- See Also:
-
getPinCacheDefaultValue
public boolean getPinCacheDefaultValue()Gets the default pin behavior of loading cache.- Returns:
- the default behavior of pinning cache when loading cache
- Since:
- 6.0
- See Also:
-
loadCache
public void loadCache(ConnectionHandler connectionHandler, String tableName, boolean haltOnError, boolean pinCache) throws Exception Loads or updates cache directly into memory without making a (first) search in the table.- Parameters:
connectionHandler
- ConnectionHandler with live connectiontableName
- the name of the structure table to load into the cachehaltOnError
- if true, stops on any errors during loading; tries to recover otherwisepinCache
- if set to true, the cache is pinned into memory and won't be released when physical memory is deemed insufficient to hold an additional structure table cached. Otherwise it is thrown out in that case.- Throws:
Exception
- depending on the haltOnError setting, it may throw an exception- Since:
- 6.0
-
loadCache
public void loadCache(ConnectionHandler connectionHandler, String tableName, boolean haltOnError) throws Exception Loads or updates cache directly into memory without making a (first) search in the table.- Parameters:
connectionHandler
- ConnectionHandler with live connectiontableName
- the name of the structure table to load into the cachehaltOnError
- if true, stops on any errors during loading; tries to recover otherwise- Throws:
Exception
- depending on the haltOnError setting, it may throw an exception- Since:
- 6.0
-
loadCache
public void loadCache(ConnectionHandler connectionHandler, String tableName, String indexedTable, String indexedColumn, boolean haltOnError, boolean pinCache) throws Exception For internal use only.- Parameters:
connectionHandler
- ConnectionHandler with live connectiontableName
- the name of the structure table to load into the cacheindexedTable
- the name of the tableindexedColumn
- the name of the indexed columnhaltOnError
- if true, stops on any errors during loading; tries to recover otherwise.pinCache
- if true, the cache is pinned- Throws:
Exception
- whatever
-
pinCache
public void pinCache(ConnectionHandler connectionHandler, String tableName) throws Exception, IllegalArgumentException Pins cache into memory. The cache is pinned into memory and won't be released when physical memory is deemed insufficient to hold an additional structure table cached.- Parameters:
connectionHandler
- ConnectionHandler with live connectiontableName
- the name of the structure table to be pinned into the cache- Throws:
Exception
- depending on the haltOnError setting, it may throw an exceptionIllegalArgumentException
- if no cache is loaded into memory for the structure table- Since:
- 6.0
-
unpinCache
public void unpinCache(ConnectionHandler connectionHandler, String tableName) throws Exception, IllegalArgumentException Unpins cache from memory without making a (first) search in the table. The cache is pinned into memory and won't be released when physical memory is deemed insufficient to hold an additional structure table cached.- Parameters:
connectionHandler
- ConnectionHandler with live connectiontableName
- the name of the structure table to be pinned into the cache- Throws:
Exception
- depending on the haltOnError setting, it may throw an exceptionIllegalArgumentException
- if no cache is loaded into memory for the structure table- Since:
- 6.0
-
findCache
public chemaxon.jchem.db.cache.JChemCache findCache(ConnectionHandler ch, String tableName, boolean cartridgeMode) throws chemaxon.jchem.base.storage.PersistenceException For internal use only.- Parameters:
ch
- the connection to usetableName
- the name of the tablecartridgeMode
- true if cartridge- Returns:
- a cache responsible for the table
- Throws:
chemaxon.jchem.base.storage.PersistenceException
- if some error occurs
-
getCacheRemovalMethod
public chemaxon.jchem.db.cache.CacheRemovalMethod getCacheRemovalMethod()For internal use only.- Returns:
- the current cacheRemovalMethod
-
setCacheRemovalMethod
public void setCacheRemovalMethod(chemaxon.jchem.db.cache.CacheRemovalMethod cacheRemovalMethod) For internal use only.- Parameters:
cacheRemovalMethod
- the removalmethod to use
-
unloadCache
public void unloadCache(ConnectionHandler connectionHandler, String tableName, boolean cartridgeMode, boolean haltOnError) throws chemaxon.jchem.base.storage.PersistenceException For internal use only.- Parameters:
connectionHandler
- connection handler to usetableName
- the name of the tablecartridgeMode
- true if used from cartridgehaltOnError
- haltonerror state- Throws:
chemaxon.jchem.base.storage.PersistenceException
- if it encounter some problem
-
unloadCache
public void unloadCache(ConnectionHandler connectionHandler, String tableName) throws Exception, IllegalArgumentException Unloads cache from the memory. This can be useful when the server is low on memory and an unused table is loaded into memory.- Parameters:
connectionHandler
- ConnectionHandler with live connectiontableName
- the name of the structure table to unload from cache- Throws:
Exception
- if some error is encountered.IllegalArgumentException
- if no cache is loaded into memory for the structure table- Since:
- 6.0
-
isCacheLoaded
public boolean isCacheLoaded(ConnectionHandler connectionHandler, String tableName) throws Exception Returns whether the cache is loaded. If the cache load has been started, but it isn't finished yet, the function returns false. Be aware that when changes are made in the table, the cache needs to be updated. So despite this function returning true, the next search may be slower than usual.- Parameters:
connectionHandler
- ConnectionHandler with live connectiontableName
- the name of the structure table to look for- Returns:
- true if cache is loaded
- Throws:
Exception
- if some error is encountered.- Since:
- 6.0
-
isCacheLoadStarted
public boolean isCacheLoadStarted(ConnectionHandler connectionHandler, String tableName) throws Exception Returns whether the cache is loaded or cache load has been started.- Parameters:
connectionHandler
- ConnectionHandler with live connectiontableName
- the name of the structure table to look for- Returns:
- true if cache is loaded or the cache load has been started
- Throws:
Exception
- if some error is encountered.- Since:
- 6.0
-
setMaxCacheSize
public void setMaxCacheSize(int maxCacheSizeMB) Sets the desired cache memory allocation policy.
NOTE: the current cache size won't change automatically, only during next cache load or update event. If set to -1 (auto-detect) orminFreeMem
is not set to 0, the program tries to determine the maximum amount of memory available for allocation by calling the garbage collector and determining the available memory.
NOTE: Under Java Runtime Environment 1.3.1 or older the available memory size cannot be determined. In this case JChem allocates cache for tables until it detects OutOfMemoryError during loading.- Parameters:
maxCacheSizeMB
- the maximum amount of memory the cache allowed to utilize in megabytes. Set -1 for auto-detection (default):maxCacheSize = available_memory - minFreeMem
- Since:
- 6.1
- See Also:
-
setMinNonCachedMemory
public void setMinNonCachedMemory(int minNonCachedMemoryMB) Sets the desired cache memory allocation policy.
NOTE: the current cache size won't change automatically, only during next cache load or update event. If not set to 0 ormaxCacheSize
is set to -1 (auto-detect), the program tries to determine the maximum amount of memory available for allocation by calling the garbage collector and determining the available memory.
NOTE: Under Java Runtime Environment 1.3.1 or older the available memory size cannot be determined. In this case JChem allocates cache for tables until it detects OutOfMemoryError during loading.- Parameters:
minNonCachedMemoryMB
- the minimum amount of memory that should be left free for future non-cache allocations in megabytes.
Set to 0 if not specified.
Set to -1 for auto-detection (default):- 10 % of all available space for future allocations
- Not smaller, than 250 MB
- Nor bigger, than 1000 MB
- Since:
- 6.1
- See Also:
-
getCachedTables
Gets the names and sizes of tables currently in the cache.- Returns:
- the names and allocated memory size in bytes as key - value (String - Long) pairs.
- Since:
- 6.1
-
clearCache
public void clearCache()Clears the cache that stores fingerprints and structures.- Since:
- 6.1
-
setCacheExpirationTime
public void setCacheExpirationTime(double hours) Sets the expiration time for the structure cache. At the start of each search all tables are purged from cache that were searched before the specified time period. Naturally the currently searched tables are never purged.- Parameters:
hours
- the time in hours. The default value is 0. Set to 0 for no expiration.- Since:
- 6.1
- See Also:
-