|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.compomics.util.db.ObjectsCache
public class ObjectsCache
An object cache can be combined to an ObjectDB to improve its performance. A single cache can be used by different databases. This ough not to be serialized. The length of lists/maps in the cache shall stay independent from the number of objects in cache.
Constructor Summary | |
---|---|
ObjectsCache()
Constructor. |
Method Summary | |
---|---|
void |
addDb(ObjectsDB objectsDB)
Adds a database in the list of the databases handled by the cache. |
void |
addObject(String dbName,
String tableName,
String objectKey,
Object object,
boolean modifiedOrNew)
Adds an object to the cache. |
int |
getBatchSize()
Returns the batch size in number of objects. |
int |
getCacheSize()
Returns the cache size in number of objects. |
double |
getMemoryShare()
Returns the share of heap size which can be used before emptying the cache. |
Object |
getObject(String dbName,
String tableName,
String objectKey)
Returns the objects if present in the cache. |
boolean |
inCache(String dbName,
String tableName,
String objectKey)
Indicates whether an object is loaded in the cache |
boolean |
isAutomatedMemoryManagement()
Returns whether the cache is in automated memory management mode. |
boolean |
memoryCheck()
Indicates whether the memory used by the application is lower than 99% of the heap size. |
void |
reduceMemoryConsumption(double share,
WaitingHandler waitingHandler)
Reduces the memory consumption by saving the given share of hits. |
void |
removeObject(String dbName,
String tableName,
String objectKey)
Removes an object from the cache mappings. |
void |
saveCache(WaitingHandler waitingHandler,
boolean emptyCache)
Saves the cache content in the database. |
void |
saveObject(String entryKey)
Saves an entry in the database if modified and clears it from the cache. |
void |
saveObject(String entryKey,
boolean clearEntry)
Saves an entry in the database if modified. |
void |
saveObjects(ArrayList<String> entryKeys)
Saves an entry in the database if modified and clears it from the cache. |
void |
saveObjects(ArrayList<String> entryKeys,
WaitingHandler waitingHandler)
Saves an entry in the database if modified and clears it from the cache. |
void |
saveObjects(ArrayList<String> entryKeys,
WaitingHandler waitingHandler,
boolean clearEntries)
Saves an entry in the database if modified. |
void |
setAutomatedMemoryManagement(boolean automatedMemoryManagement)
Sets whether the cache is in automated memory management mode. |
void |
setBatchSize(int batchSize)
Sets the batch size in number of objects. |
void |
setCacheSize(int cacheSize)
Sets the cache size in number of objects. |
void |
setMemoryShare(double memoryShare)
Sets the share of heap size which can be used before emptying the cache. |
void |
updateCache()
Updates the cache according to the memory settings. |
boolean |
updateObject(String dbName,
String tableName,
String objectKey,
Object object)
Sets that a match has been modified and returns true in case of success. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public ObjectsCache()
Method Detail |
---|
public boolean isAutomatedMemoryManagement()
public void setAutomatedMemoryManagement(boolean automatedMemoryManagement)
automatedMemoryManagement
- a boolean indicating whether the cache
is in automated memory management modepublic int getCacheSize()
public void setCacheSize(int cacheSize)
cacheSize
- the cache size in number of objectspublic int getBatchSize()
public void setBatchSize(int batchSize)
batchSize
- the batch size in number of objectspublic double getMemoryShare()
public void setMemoryShare(double memoryShare)
memoryShare
- the share of heap size which can be used before
emptying the cachepublic void addDb(ObjectsDB objectsDB)
objectsDB
- the objects databasepublic void removeObject(String dbName, String tableName, String objectKey)
dbName
- the name of the databasetableName
- the name of the tableobjectKey
- the key of the objectpublic Object getObject(String dbName, String tableName, String objectKey)
dbName
- the name of the databasetableName
- the name of the tableobjectKey
- the key of the object
public boolean updateObject(String dbName, String tableName, String objectKey, Object object)
dbName
- the name of the databasetableName
- the name of the tableobjectKey
- the key of the objectobject
-
public void addObject(String dbName, String tableName, String objectKey, Object object, boolean modifiedOrNew) throws IOException, SQLException
dbName
- the name of the databasetableName
- the name of the tableobjectKey
- the key of the objectobject
- the object to store in the cachemodifiedOrNew
- true if the object is modified or new
IOException
SQLException
public boolean memoryCheck()
public void saveObjects(ArrayList<String> entryKeys) throws IOException, SQLException
entryKeys
- the keys of the entries
SQLException
- exception thrown whenever an error occurred while
adding the object in the database
IOException
- exception thrown whenever an error occurred while
writing the objectpublic void saveObjects(ArrayList<String> entryKeys, WaitingHandler waitingHandler) throws IOException, SQLException
entryKeys
- the keys of the entrieswaitingHandler
- a waiting handler displaying progress to the user.
Can be null. Progress will be displayed as secondary.
SQLException
- exception thrown whenever an error occurred while
adding the object in the database
IOException
- exception thrown whenever an error occurred while
writing the objectpublic void saveObjects(ArrayList<String> entryKeys, WaitingHandler waitingHandler, boolean clearEntries) throws IOException, SQLException
entryKeys
- the keys of the entrieswaitingHandler
- a waiting handler displaying progress to the user.
Can be null. Progress will be displayed as secondary.clearEntries
- a boolean indicating whether the entry shall be
cleared from the cache
SQLException
- exception thrown whenever an error occurred while
adding the object in the database
IOException
- exception thrown whenever an error occurred while
writing the objectpublic void saveObject(String entryKey) throws IOException, SQLException
entryKey
- the key of the entry
SQLException
- exception thrown whenever an error occurred while
adding the object in the database
IOException
- exception thrown whenever an error occurred while
writing the objectpublic void saveObject(String entryKey, boolean clearEntry) throws IOException, SQLException
entryKey
- the key of the entryclearEntry
- a boolean indicating whether the entry shall be cleared
from the cache
SQLException
- exception thrown whenever an error occurred while
adding the object in the database
IOException
- exception thrown whenever an error occurred while
writing the objectpublic void updateCache() throws IOException, SQLException
SQLException
- exception thrown whenever an error occurred while
adding the object in the database
IOException
- exception thrown whenever an error occurred while
writing the objectpublic void reduceMemoryConsumption(double share, WaitingHandler waitingHandler) throws IOException, SQLException
share
- the share to be saved, 0.25 means that 25% of the hits will
be savedwaitingHandler
- a waiting handler on which the progress will be
displayed as secondary progress. can be null
SQLException
- exception thrown whenever an error occurred while
adding the object in the database
IOException
- exception thrown whenever an error occurred while
writing the objectpublic boolean inCache(String dbName, String tableName, String objectKey)
dbName
- the database nametableName
- the table nameobjectKey
- the object key
public void saveCache(WaitingHandler waitingHandler, boolean emptyCache) throws IOException, SQLException
waitingHandler
- a waiting handler on which the progress will beemptyCache
- boolean indicating whether the cache content shall be
cleared while saving displayed as secondary progress. can be null
SQLException
- exception thrown whenever an error occurred while
adding the object in the database
IOException
- exception thrown whenever an error occurred while
writing the object
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |