public class ObjectsCache extends 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(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 |
isEmpty()
Indicates whether the cache is empty.
|
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 |
setReadOnly(boolean readOnly)
Sets the cache in read only.
|
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.
|
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 objectpublic 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
- the objectpublic void addObject(String dbName, String tableName, String objectKey, Object object, boolean modifiedOrNew) throws IOException, SQLException, InterruptedException
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 newIOException
- if an IOException occursSQLException
- if an SQLException occursInterruptedException
- if an InterruptedException occurspublic boolean memoryCheck()
public void saveObjects(ArrayList<String> entryKeys) throws IOException, SQLException
entryKeys
- the keys of the entriesSQLException
- exception thrown whenever an error occurred while
adding the object in the databaseIOException
- 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 databaseIOException
- 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 cacheSQLException
- exception thrown whenever an error occurred while
adding the object in the databaseIOException
- exception thrown whenever an error occurred while
writing the objectpublic void saveObject(String entryKey) throws IOException, SQLException, InterruptedException
entryKey
- the key of the entrySQLException
- exception thrown whenever an error occurred while
adding the object in the databaseIOException
- exception thrown whenever an error occurred while
writing the objectInterruptedException
- if an InterruptedException occurspublic void saveObject(String entryKey, boolean clearEntry) throws IOException, SQLException, InterruptedException
entryKey
- the key of the entryclearEntry
- a boolean indicating whether the entry shall be cleared
from the cacheSQLException
- exception thrown whenever an error occurred while
adding the object in the databaseIOException
- exception thrown whenever an error occurred while
writing the objectInterruptedException
- if an InterruptedException occurspublic void updateCache() throws IOException, SQLException, InterruptedException
SQLException
- exception thrown whenever an error occurred while
adding the object in the databaseIOException
- exception thrown whenever an error occurred while
writing the objectInterruptedException
- if an InterruptedException occurspublic 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 nullSQLException
- exception thrown whenever an error occurred while
adding the object in the databaseIOException
- 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 keypublic 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 nullSQLException
- exception thrown whenever an error occurred while
adding the object in the databaseIOException
- exception thrown whenever an error occurred while
writing the objectpublic boolean isEmpty()
public void setReadOnly(boolean readOnly)
readOnly
- boolean indicating whether the cache should be in read
onlyCopyright © 2016. All rights reserved.