public class ObjectsCache
extends java.lang.Object
Constructor and Description |
---|
ObjectsCache()
Constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
addDb(ObjectsDB objectsDB)
Adds a database in the list of the databases handled by the cache.
|
void |
addObject(java.lang.String dbName,
java.lang.String tableName,
java.lang.String objectKey,
java.lang.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.
|
java.lang.Object |
getObject(java.lang.String dbName,
java.lang.String tableName,
java.lang.String objectKey)
Returns the objects if present in the cache.
|
boolean |
inCache(java.lang.String dbName,
java.lang.String tableName,
java.lang.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(java.lang.String dbName,
java.lang.String tableName,
java.lang.String objectKey)
Removes an object from the cache mappings.
|
void |
saveCache(WaitingHandler waitingHandler,
boolean emptyCache)
Saves the cache content in the database.
|
void |
saveObject(java.lang.String entryKey)
Saves an entry in the database if modified and clears it from the cache.
|
void |
saveObject(java.lang.String entryKey,
boolean clearEntry)
Saves an entry in the database if modified.
|
void |
saveObjects(java.util.ArrayList<java.lang.String> entryKeys)
Saves an entry in the database if modified and clears it from the cache.
|
void |
saveObjects(java.util.ArrayList<java.lang.String> entryKeys,
WaitingHandler waitingHandler)
Saves an entry in the database if modified and clears it from the cache.
|
void |
saveObjects(java.util.ArrayList<java.lang.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(java.lang.String dbName,
java.lang.String tableName,
java.lang.String objectKey,
java.lang.Object object)
Sets that a match has been modified and returns true in case of success.
|
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(java.lang.String dbName, java.lang.String tableName, java.lang.String objectKey)
dbName
- the name of the databasetableName
- the name of the tableobjectKey
- the key of the objectpublic java.lang.Object getObject(java.lang.String dbName, java.lang.String tableName, java.lang.String objectKey)
dbName
- the name of the databasetableName
- the name of the tableobjectKey
- the key of the objectpublic boolean updateObject(java.lang.String dbName, java.lang.String tableName, java.lang.String objectKey, java.lang.Object object)
dbName
- the name of the databasetableName
- the name of the tableobjectKey
- the key of the objectobject
- public void addObject(java.lang.String dbName, java.lang.String tableName, java.lang.String objectKey, java.lang.Object object, boolean modifiedOrNew) throws java.io.IOException, java.sql.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 newjava.io.IOException
java.sql.SQLException
public boolean memoryCheck()
public void saveObjects(java.util.ArrayList<java.lang.String> entryKeys) throws java.io.IOException, java.sql.SQLException
entryKeys
- the keys of the entriesjava.sql.SQLException
- exception thrown whenever an error occurred while
adding the object in the databasejava.io.IOException
- exception thrown whenever an error occurred while
writing the objectpublic void saveObjects(java.util.ArrayList<java.lang.String> entryKeys, WaitingHandler waitingHandler) throws java.io.IOException, java.sql.SQLException
entryKeys
- the keys of the entrieswaitingHandler
- a waiting handler displaying progress to the user.
Can be null. Progress will be displayed as secondary.java.sql.SQLException
- exception thrown whenever an error occurred while
adding the object in the databasejava.io.IOException
- exception thrown whenever an error occurred while
writing the objectpublic void saveObjects(java.util.ArrayList<java.lang.String> entryKeys, WaitingHandler waitingHandler, boolean clearEntries) throws java.io.IOException, java.sql.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 cachejava.sql.SQLException
- exception thrown whenever an error occurred while
adding the object in the databasejava.io.IOException
- exception thrown whenever an error occurred while
writing the objectpublic void saveObject(java.lang.String entryKey) throws java.io.IOException, java.sql.SQLException
entryKey
- the key of the entryjava.sql.SQLException
- exception thrown whenever an error occurred while
adding the object in the databasejava.io.IOException
- exception thrown whenever an error occurred while
writing the objectpublic void saveObject(java.lang.String entryKey, boolean clearEntry) throws java.io.IOException, java.sql.SQLException
entryKey
- the key of the entryclearEntry
- a boolean indicating whether the entry shall be cleared
from the cachejava.sql.SQLException
- exception thrown whenever an error occurred while
adding the object in the databasejava.io.IOException
- exception thrown whenever an error occurred while
writing the objectpublic void updateCache() throws java.io.IOException, java.sql.SQLException
java.sql.SQLException
- exception thrown whenever an error occurred while
adding the object in the databasejava.io.IOException
- exception thrown whenever an error occurred while
writing the objectpublic void reduceMemoryConsumption(double share, WaitingHandler waitingHandler) throws java.io.IOException, java.sql.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 nulljava.sql.SQLException
- exception thrown whenever an error occurred while
adding the object in the databasejava.io.IOException
- exception thrown whenever an error occurred while
writing the objectpublic boolean inCache(java.lang.String dbName, java.lang.String tableName, java.lang.String objectKey)
dbName
- the database nametableName
- the table nameobjectKey
- the object keypublic void saveCache(WaitingHandler waitingHandler, boolean emptyCache) throws java.io.IOException, java.sql.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 nulljava.sql.SQLException
- exception thrown whenever an error occurred while
adding the object in the databasejava.io.IOException
- exception thrown whenever an error occurred while
writing the objectCopyright © 2013. All Rights Reserved.