checks added in methods that performs operations on the cache and cacheManager variable changed from local to private static
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/databases-manager-portlet@100896 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
2a9b3e4a2a
commit
c65cba2a56
|
@ -22,6 +22,7 @@ import javax.servlet.http.HttpServletRequest;
|
|||
import javax.servlet.http.HttpSession;
|
||||
import net.sf.ehcache.Cache;
|
||||
import net.sf.ehcache.CacheManager;
|
||||
import net.sf.ehcache.Status;
|
||||
import net.sf.ehcache.config.CacheConfiguration;
|
||||
import net.sf.ehcache.config.MemoryUnit;
|
||||
import net.sf.ehcache.config.SizeOfPolicyConfiguration;
|
||||
|
@ -108,7 +109,9 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
|
|||
String cachePath = System.getenv("CATALINA_TMPDIR") + "/DBManager";
|
||||
logger.info("dbmanager-> Creating cache in folder: " + cachePath);
|
||||
|
||||
CacheManager cacheManager = CacheManager.create();
|
||||
// CacheManager cacheManager = CacheManager.create();
|
||||
|
||||
cacheManager = CacheManager.create();
|
||||
|
||||
if (cacheManager == null) {
|
||||
logger.error("dbmanager-> Error while starting the servlet. Failed to get the cacheManager. cacheManager null");
|
||||
|
@ -2068,18 +2071,44 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
|
|||
}
|
||||
|
||||
private synchronized void insertDataIntoCache(net.sf.ehcache.Element data) {
|
||||
if (DBCache != null) {
|
||||
DBCache.put(data);
|
||||
logger.info("dbmanager-> disk store path for the cache: " + cacheManager.getDiskStorePath());
|
||||
|
||||
if(cacheManager.cacheExists("DBCache")){
|
||||
if (DBCache.getStatus().toString().equals(Status.STATUS_ALIVE.toString())){
|
||||
logger.info("dbmanager-> Cache Status:"+ "STATUS_ALIVE");
|
||||
|
||||
DBCache.put(data);
|
||||
// logger.info("dbmanager-> element added in cache with key: " + data.getKey().toString());
|
||||
|
||||
}else{
|
||||
logger.info("dbmanager-> Cache Status:"+ DBCache.getStatus().toString());
|
||||
}
|
||||
}
|
||||
// if (DBCache != null) {
|
||||
// DBCache.put(data);
|
||||
// }
|
||||
}
|
||||
|
||||
private synchronized net.sf.ehcache.Element getDataFromCache(String key) {
|
||||
net.sf.ehcache.Element data = null;
|
||||
if (DBCache != null) {
|
||||
|
||||
data = DBCache.get(key);
|
||||
|
||||
logger.info("dbmanager-> disk store path for the cache: " + cacheManager.getDiskStorePath());
|
||||
|
||||
if(cacheManager.cacheExists("DBCache")){
|
||||
if (DBCache.getStatus().toString().equals(Status.STATUS_ALIVE.toString())){
|
||||
logger.info("dbmanager-> Cache Status:"+ "STATUS_ALIVE");
|
||||
|
||||
data = DBCache.get(key);
|
||||
// System.out.println("element get from cache with key " + key);
|
||||
|
||||
}else{
|
||||
logger.info("dbmanager-> Cache Status:"+ DBCache.getStatus().toString());
|
||||
}
|
||||
}
|
||||
|
||||
// if (DBCache != null) {
|
||||
// data = DBCache.get(key);
|
||||
// }
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
|
@ -2468,9 +2497,23 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
|
|||
}
|
||||
|
||||
private synchronized void refreshCache(String key) throws Exception {
|
||||
|
||||
logger.info("dbmanager-> disk store path for the cache: " + cacheManager.getDiskStorePath());
|
||||
|
||||
if(cacheManager.cacheExists("DBCache")){
|
||||
if (DBCache.getStatus().toString().equals(Status.STATUS_ALIVE.toString())){
|
||||
logger.info("dbmanager-> Cache Status:"+ Status.STATUS_ALIVE.toString());
|
||||
|
||||
DBCache.remove(key);
|
||||
// logger.info("dbmanager-> Element with key: " +key+ " removed.");
|
||||
}else{
|
||||
logger.info("dbmanager-> Cache Status:"+ DBCache.getStatus().toString());
|
||||
}
|
||||
}
|
||||
|
||||
// try {
|
||||
// System.out.println("SIZE CACHE PRE REMOVING: " + DBCache.getSize());
|
||||
DBCache.remove(key);
|
||||
// DBCache.remove(key);
|
||||
// System.out.println("SIZE CACHE POST REMOVING: " + DBCache.getSize());
|
||||
// } catch (Exception e) {
|
||||
// TODO: handle exception
|
||||
|
@ -2486,22 +2529,49 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
|
|||
|
||||
logger.info("dbmanager-> refreshing submitted queries in cache with key:"
|
||||
+ key);
|
||||
|
||||
logger.info("dbmanager-> disk store path for the cache: " + cacheManager.getDiskStorePath());
|
||||
|
||||
if(cacheManager.cacheExists("DBCache")){
|
||||
if (DBCache.getStatus().toString().equals(Status.STATUS_ALIVE.toString())){
|
||||
logger.info("dbmanager-> Cache Status:"+ "STATUS_ALIVE");
|
||||
|
||||
List<String> keysInCache = DBCache.getKeys();
|
||||
int listSize = keysInCache.size();
|
||||
List<String> keysToBeRemoved = new ArrayList<>();
|
||||
|
||||
List<String> keysInCache = DBCache.getKeys();
|
||||
int listSize = keysInCache.size();
|
||||
List<String> keysToBeRemoved = new ArrayList<>();
|
||||
|
||||
// recover keys list that match the key
|
||||
for (int i = 0; i < listSize; i++) {
|
||||
if (keysInCache.get(i).startsWith(key)) {
|
||||
// System.out.println("data removed with key: " +
|
||||
// keysInCache.get(i));
|
||||
keysToBeRemoved.add(keysInCache.get(i));
|
||||
// recover keys list that match the key
|
||||
for (int i = 0; i < listSize; i++) {
|
||||
if (keysInCache.get(i).startsWith(key)) {
|
||||
// System.out.println("data removed with key: " +
|
||||
// keysInCache.get(i));
|
||||
keysToBeRemoved.add(keysInCache.get(i));
|
||||
}
|
||||
}
|
||||
// remove keys
|
||||
DBCache.removeAll(keysToBeRemoved);
|
||||
// System.out.println("SubmittedQuery refreshed with key: " + key);
|
||||
|
||||
}else{
|
||||
logger.info("dbmanager-> Cache Status:"+ DBCache.getStatus().toString());
|
||||
}
|
||||
}
|
||||
// remove keys
|
||||
DBCache.removeAll(keysToBeRemoved);
|
||||
// System.out.println("SubmittedQuery refreshed with key: " + key);
|
||||
|
||||
// List<String> keysInCache = DBCache.getKeys();
|
||||
// int listSize = keysInCache.size();
|
||||
// List<String> keysToBeRemoved = new ArrayList<>();
|
||||
//
|
||||
// // recover keys list that match the key
|
||||
// for (int i = 0; i < listSize; i++) {
|
||||
// if (keysInCache.get(i).startsWith(key)) {
|
||||
// // System.out.println("data removed with key: " +
|
||||
// // keysInCache.get(i));
|
||||
// keysToBeRemoved.add(keysInCache.get(i));
|
||||
// }
|
||||
// }
|
||||
// // remove keys
|
||||
// DBCache.removeAll(keysToBeRemoved);
|
||||
// // System.out.println("SubmittedQuery refreshed with key: " + key);
|
||||
}
|
||||
|
||||
private synchronized void refreshSamplingsInCache(
|
||||
|
@ -2512,24 +2582,53 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
|
|||
+ keyUsedForSamplingsRefresh
|
||||
+ " "
|
||||
+ keyUsedForSmartSamplingRefresh);
|
||||
|
||||
logger.info("dbmanager-> disk store path for the cache: " + cacheManager.getDiskStorePath());
|
||||
|
||||
|
||||
List<String> keysInCache = DBCache.getKeys();
|
||||
int listSize = keysInCache.size();
|
||||
List<String> keysToBeRemoved = new ArrayList<>();
|
||||
if(cacheManager.cacheExists("DBCache")){
|
||||
if (DBCache.getStatus().toString().equals(Status.STATUS_ALIVE.toString())){
|
||||
logger.info("dbmanager-> Cache Status:"+ "STATUS_ALIVE");
|
||||
|
||||
List<String> keysInCache = DBCache.getKeys();
|
||||
int listSize = keysInCache.size();
|
||||
List<String> keysToBeRemoved = new ArrayList<>();
|
||||
|
||||
// recover keys list that match the key
|
||||
for (int i = 0; i < listSize; i++) {
|
||||
if ((keysInCache.get(i).startsWith(keyUsedForSamplingsRefresh))
|
||||
|| (keysInCache.get(i)
|
||||
.startsWith(keyUsedForSmartSamplingRefresh))) {
|
||||
keysToBeRemoved.add(keysInCache.get(i));
|
||||
// recover keys list that match the key
|
||||
for (int i = 0; i < listSize; i++) {
|
||||
if ((keysInCache.get(i).startsWith(keyUsedForSamplingsRefresh))
|
||||
|| (keysInCache.get(i)
|
||||
.startsWith(keyUsedForSmartSamplingRefresh))) {
|
||||
keysToBeRemoved.add(keysInCache.get(i));
|
||||
}
|
||||
}
|
||||
// remove keys
|
||||
DBCache.removeAll(keysToBeRemoved);
|
||||
// System.out.println("Samplings refreshed with keys: "
|
||||
// + keyUsedForSamplingsRefresh + " "
|
||||
// + keyUsedForSmartSamplingRefresh);
|
||||
}else{
|
||||
logger.info("dbmanager-> Cache Status:"+ DBCache.getStatus().toString());
|
||||
}
|
||||
}
|
||||
// remove keys
|
||||
DBCache.removeAll(keysToBeRemoved);
|
||||
// System.out.println("Samplings refreshed with keys: "
|
||||
// + keyUsedForSamplingsRefresh + " "
|
||||
// + keyUsedForSmartSamplingRefresh);
|
||||
}
|
||||
|
||||
// List<String> keysInCache = DBCache.getKeys();
|
||||
// int listSize = keysInCache.size();
|
||||
// List<String> keysToBeRemoved = new ArrayList<>();
|
||||
//
|
||||
// // recover keys list that match the key
|
||||
// for (int i = 0; i < listSize; i++) {
|
||||
// if ((keysInCache.get(i).startsWith(keyUsedForSamplingsRefresh))
|
||||
// || (keysInCache.get(i)
|
||||
// .startsWith(keyUsedForSmartSamplingRefresh))) {
|
||||
// keysToBeRemoved.add(keysInCache.get(i));
|
||||
// }
|
||||
// }
|
||||
// // remove keys
|
||||
// DBCache.removeAll(keysToBeRemoved);
|
||||
// // System.out.println("Samplings refreshed with keys: "
|
||||
// // + keyUsedForSamplingsRefresh + " "
|
||||
// // + keyUsedForSmartSamplingRefresh);
|
||||
}
|
||||
|
||||
private String storeResultIntoCSVFile(List<Result> result, String n)
|
||||
|
|
Loading…
Reference in New Issue