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 javax.servlet.http.HttpSession;
|
||||||
import net.sf.ehcache.Cache;
|
import net.sf.ehcache.Cache;
|
||||||
import net.sf.ehcache.CacheManager;
|
import net.sf.ehcache.CacheManager;
|
||||||
|
import net.sf.ehcache.Status;
|
||||||
import net.sf.ehcache.config.CacheConfiguration;
|
import net.sf.ehcache.config.CacheConfiguration;
|
||||||
import net.sf.ehcache.config.MemoryUnit;
|
import net.sf.ehcache.config.MemoryUnit;
|
||||||
import net.sf.ehcache.config.SizeOfPolicyConfiguration;
|
import net.sf.ehcache.config.SizeOfPolicyConfiguration;
|
||||||
|
@ -108,7 +109,9 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
|
||||||
String cachePath = System.getenv("CATALINA_TMPDIR") + "/DBManager";
|
String cachePath = System.getenv("CATALINA_TMPDIR") + "/DBManager";
|
||||||
logger.info("dbmanager-> Creating cache in folder: " + cachePath);
|
logger.info("dbmanager-> Creating cache in folder: " + cachePath);
|
||||||
|
|
||||||
CacheManager cacheManager = CacheManager.create();
|
// CacheManager cacheManager = CacheManager.create();
|
||||||
|
|
||||||
|
cacheManager = CacheManager.create();
|
||||||
|
|
||||||
if (cacheManager == null) {
|
if (cacheManager == null) {
|
||||||
logger.error("dbmanager-> Error while starting the servlet. Failed to get the cacheManager. 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) {
|
private synchronized void insertDataIntoCache(net.sf.ehcache.Element data) {
|
||||||
if (DBCache != null) {
|
logger.info("dbmanager-> disk store path for the cache: " + cacheManager.getDiskStorePath());
|
||||||
DBCache.put(data);
|
|
||||||
|
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) {
|
private synchronized net.sf.ehcache.Element getDataFromCache(String key) {
|
||||||
net.sf.ehcache.Element data = null;
|
net.sf.ehcache.Element data = null;
|
||||||
if (DBCache != null) {
|
logger.info("dbmanager-> disk store path for the cache: " + cacheManager.getDiskStorePath());
|
||||||
|
|
||||||
data = DBCache.get(key);
|
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;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2468,9 +2497,23 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
|
||||||
}
|
}
|
||||||
|
|
||||||
private synchronized void refreshCache(String key) throws Exception {
|
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 {
|
// try {
|
||||||
// System.out.println("SIZE CACHE PRE REMOVING: " + DBCache.getSize());
|
// System.out.println("SIZE CACHE PRE REMOVING: " + DBCache.getSize());
|
||||||
DBCache.remove(key);
|
// DBCache.remove(key);
|
||||||
// System.out.println("SIZE CACHE POST REMOVING: " + DBCache.getSize());
|
// System.out.println("SIZE CACHE POST REMOVING: " + DBCache.getSize());
|
||||||
// } catch (Exception e) {
|
// } catch (Exception e) {
|
||||||
// TODO: handle exception
|
// TODO: handle exception
|
||||||
|
@ -2486,22 +2529,49 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
|
||||||
|
|
||||||
logger.info("dbmanager-> refreshing submitted queries in cache with key:"
|
logger.info("dbmanager-> refreshing submitted queries in cache with key:"
|
||||||
+ 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();
|
// recover keys list that match the key
|
||||||
int listSize = keysInCache.size();
|
for (int i = 0; i < listSize; i++) {
|
||||||
List<String> keysToBeRemoved = new ArrayList<>();
|
if (keysInCache.get(i).startsWith(key)) {
|
||||||
|
// System.out.println("data removed with key: " +
|
||||||
// recover keys list that match the key
|
// keysInCache.get(i));
|
||||||
for (int i = 0; i < listSize; i++) {
|
keysToBeRemoved.add(keysInCache.get(i));
|
||||||
if (keysInCache.get(i).startsWith(key)) {
|
}
|
||||||
// System.out.println("data removed with key: " +
|
}
|
||||||
// keysInCache.get(i));
|
// remove keys
|
||||||
keysToBeRemoved.add(keysInCache.get(i));
|
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);
|
// List<String> keysInCache = DBCache.getKeys();
|
||||||
// System.out.println("SubmittedQuery refreshed with key: " + key);
|
// 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(
|
private synchronized void refreshSamplingsInCache(
|
||||||
|
@ -2512,24 +2582,53 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
|
||||||
+ keyUsedForSamplingsRefresh
|
+ keyUsedForSamplingsRefresh
|
||||||
+ " "
|
+ " "
|
||||||
+ keyUsedForSmartSamplingRefresh);
|
+ keyUsedForSmartSamplingRefresh);
|
||||||
|
|
||||||
|
logger.info("dbmanager-> disk store path for the cache: " + cacheManager.getDiskStorePath());
|
||||||
|
|
||||||
|
|
||||||
List<String> keysInCache = DBCache.getKeys();
|
if(cacheManager.cacheExists("DBCache")){
|
||||||
int listSize = keysInCache.size();
|
if (DBCache.getStatus().toString().equals(Status.STATUS_ALIVE.toString())){
|
||||||
List<String> keysToBeRemoved = new ArrayList<>();
|
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
|
// recover keys list that match the key
|
||||||
for (int i = 0; i < listSize; i++) {
|
for (int i = 0; i < listSize; i++) {
|
||||||
if ((keysInCache.get(i).startsWith(keyUsedForSamplingsRefresh))
|
if ((keysInCache.get(i).startsWith(keyUsedForSamplingsRefresh))
|
||||||
|| (keysInCache.get(i)
|
|| (keysInCache.get(i)
|
||||||
.startsWith(keyUsedForSmartSamplingRefresh))) {
|
.startsWith(keyUsedForSmartSamplingRefresh))) {
|
||||||
keysToBeRemoved.add(keysInCache.get(i));
|
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);
|
// List<String> keysInCache = DBCache.getKeys();
|
||||||
// System.out.println("Samplings refreshed with keys: "
|
// int listSize = keysInCache.size();
|
||||||
// + keyUsedForSamplingsRefresh + " "
|
// List<String> keysToBeRemoved = new ArrayList<>();
|
||||||
// + keyUsedForSmartSamplingRefresh);
|
//
|
||||||
|
// // 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)
|
private String storeResultIntoCSVFile(List<Result> result, String n)
|
||||||
|
|
Loading…
Reference in New Issue