bug fixed in servlet related to the cache management. Methods init and destroy modified.
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/databases-manager-portlet@100226 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
38d0c898f3
commit
87d240b885
|
@ -22,8 +22,13 @@ import javax.servlet.ServletException;
|
|||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpSession;
|
||||
|
||||
import net.didion.jwnl.data.Exc;
|
||||
import net.sf.ehcache.Cache;
|
||||
import net.sf.ehcache.CacheManager;
|
||||
import net.sf.ehcache.Ehcache;
|
||||
import net.sf.ehcache.config.CacheConfiguration;
|
||||
import net.sf.ehcache.config.MemoryUnit;
|
||||
import net.sf.ehcache.store.MemoryStoreEvictionPolicy;
|
||||
|
||||
import org.apache.regexp.RE;
|
||||
import org.gcube.application.framework.core.session.ASLSession;
|
||||
|
@ -81,7 +86,8 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
|
|||
.getLogger(GWTdbManagerServiceImpl.class);
|
||||
|
||||
// private CacheManager cacheManager;
|
||||
private static Ehcache employeeCache;
|
||||
private static Cache employeeCache;
|
||||
private static CacheManager cacheManager;
|
||||
public static List<String> listAlgorithms;
|
||||
|
||||
public GWTdbManagerServiceImpl() throws Exception {
|
||||
|
@ -92,45 +98,93 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
|
|||
|
||||
super.init();
|
||||
|
||||
// create cache
|
||||
try {
|
||||
// System.out.println("*** CACHE NOT EXISTING");
|
||||
URL url = getClass().getResource("/encache.xml");
|
||||
CacheManager cacheManager = CacheManager.newInstance(url);
|
||||
// getcache
|
||||
employeeCache = cacheManager.getEhcache("DBCache");
|
||||
// String path = System.getenv("CATALINA_TMPDIR");
|
||||
// CacheConfiguration config =
|
||||
// employeeCache.getCacheConfiguration();
|
||||
// String DiskCacheFolderName = "DBManagerDisk";
|
||||
|
||||
// File f = new File(path+"/"+DiskCacheFolderName);
|
||||
// if (!f.exists()){
|
||||
// f.mkdir();
|
||||
//
|
||||
// }
|
||||
// cache folder
|
||||
String cachePath = System.getenv("CATALINA_TMPDIR") + "/DBManager";
|
||||
logger.info("dbmanager-> Creating cache in folder: " + cachePath);
|
||||
|
||||
// config.setDiskStorePath(path);
|
||||
// config.setDiskPersistent(true);
|
||||
// config.setOverflowToDisk(true);
|
||||
CacheManager cacheManager = CacheManager.create();
|
||||
|
||||
if (cacheManager == null) {
|
||||
logger.error("dbmanager-> Failed to get the cacheManager. cacheManager null");
|
||||
throw new ServletException(
|
||||
"Failed to get the cacheManager. cacheManager null");
|
||||
}
|
||||
|
||||
if (cacheManager != null) {
|
||||
// logger.info("dbmanager-> cacheManager not null");
|
||||
if (cacheManager.cacheExists("DBCache")) {
|
||||
// logger.info("dbmanager-> cache exists");
|
||||
cacheManager.removeCache("DBCache");
|
||||
logger.info("dbmanager-> cache removed");
|
||||
|
||||
} else {
|
||||
File f = new File(cachePath + "/" + "DBCache.data");
|
||||
if (f.exists()) {
|
||||
logger.info("dbmanager-> File DBCache.data removed: "
|
||||
+ f.delete());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
createCache(cachePath);
|
||||
|
||||
if (employeeCache == null) {
|
||||
logger.error("dbmanager-> Failed to get the cache. cache null");
|
||||
throw new ServletException(
|
||||
"Failed to get the cache. cache null");
|
||||
} else {
|
||||
cacheManager.addCache(employeeCache);
|
||||
logger.info("dbmanager-> cache added to the cacheManager");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// create folder that will contain file samplings and submitquery
|
||||
// result
|
||||
// in the /webapps/folder_portlet
|
||||
String path = this.getServletContext().getRealPath("") + "/"
|
||||
+ "computationResult";
|
||||
|
||||
File computationResult = new File(path);
|
||||
if (!computationResult.exists()) {
|
||||
computationResult.mkdir();
|
||||
logger.info("dbmanager-> Folder computationResult created in : "
|
||||
+ this.getServletContext().getRealPath(""));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error("dbmanager-> Failed to get cache: ", e);
|
||||
// e.printStackTrace();
|
||||
// TODO: handle exception
|
||||
logger.error("dbmanager-> ", e);
|
||||
throw e;
|
||||
}
|
||||
|
||||
// create folder that will contain file samplings and submitquery result
|
||||
// in the /webapps/folder_portlet
|
||||
String path = this.getServletContext().getRealPath("") + "/"
|
||||
+ "computationResult";
|
||||
}
|
||||
|
||||
// System.out.println("***PATH FILE: " + path);
|
||||
public void createCache(String cachePath) throws ServletException {
|
||||
|
||||
File computationResult = new File(path);
|
||||
if (!computationResult.exists()) {
|
||||
computationResult.mkdir();
|
||||
// System.out.println("***DIRECTORY CREATED");
|
||||
try {
|
||||
|
||||
CacheConfiguration config = new CacheConfiguration();
|
||||
config.setName("DBCache");
|
||||
config.memoryStoreEvictionPolicy(MemoryStoreEvictionPolicy.LRU);
|
||||
config.eternal(false);
|
||||
config.timeToLiveSeconds(172800);
|
||||
config.timeToIdleSeconds(0);
|
||||
// config.maxEntriesLocalHeap(10000);
|
||||
config.diskExpiryThreadIntervalSeconds(120);
|
||||
config.maxBytesLocalDisk(2, MemoryUnit.GIGABYTES);
|
||||
config.maxBytesLocalHeap(200, MemoryUnit.MEGABYTES);
|
||||
config.diskSpoolBufferSizeMB(30);
|
||||
config.overflowToDisk(true);
|
||||
config.diskPersistent(false);
|
||||
config.diskStorePath(cachePath);
|
||||
|
||||
employeeCache = new Cache(config);
|
||||
|
||||
} catch (Exception e) {
|
||||
// TODO: handle exception
|
||||
logger.error("dbmanager-> Failed to create the cache", e);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -139,20 +193,30 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
|
|||
super.destroy();
|
||||
|
||||
try {
|
||||
// System.out.println("*** REMOVING CACHE");
|
||||
CacheManager cacheManager = CacheManager.getInstance();
|
||||
if (cacheManager.cacheExists("DBCache")) {
|
||||
// System.out.println("*** cache exist");
|
||||
cacheManager.removeCache("DBCache");
|
||||
// cacheManager.removalAll();
|
||||
// System.out.println("*** cache removed");
|
||||
}
|
||||
|
||||
cacheManager.shutdown();
|
||||
CacheManager cacheManager = CacheManager.getInstance();
|
||||
|
||||
if (cacheManager != null) {
|
||||
if (cacheManager.cacheExists("DBCache")) {
|
||||
// System.out.println("*** cache exist");
|
||||
cacheManager.removeCache("DBCache");
|
||||
// cacheManager.removalAll();
|
||||
// System.out.println("*** cache removed");
|
||||
logger.info("dbmanager-> DBCache removed");
|
||||
}
|
||||
|
||||
cacheManager.shutdown();
|
||||
|
||||
} else {
|
||||
logger.error("dbmanager-> Failed to get the cacheManager. cacheManager null");
|
||||
throw new Exception(
|
||||
"Failed to get the cacheManager. cacheManager null");
|
||||
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
// TODO: handle exception
|
||||
logger.error("dbmanager-> ", e);
|
||||
logger.error("dbmanager-> Failed to destroy the cache", e);
|
||||
// e.printStackTrace();
|
||||
}
|
||||
|
||||
|
@ -513,22 +577,24 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
|
|||
logger.info("dbmanager-> DatabaseName: " + db);
|
||||
logger.info("dbmanager-> SchemaName: " + scm);
|
||||
|
||||
if ((elementType!=null)&&(elementType.equals(ConstantsPortlet.SCHEMA))) {
|
||||
if ((rs==null)||(rs.equals(""))){
|
||||
if ((elementType != null)
|
||||
&& (elementType.equals(ConstantsPortlet.SCHEMA))) {
|
||||
if ((rs == null) || (rs.equals(""))) {
|
||||
throw new Exception("Unable to load data");
|
||||
}
|
||||
if ((db==null)||(db.equals(""))){
|
||||
if ((db == null) || (db.equals(""))) {
|
||||
throw new Exception("Unable to load data");
|
||||
}
|
||||
if ((scm==null)||(scm.equals(""))){
|
||||
if ((scm == null) || (scm.equals(""))) {
|
||||
throw new Exception("Unable to load data");
|
||||
}
|
||||
}
|
||||
if ((elementType!=null)&&(elementType.equals(ConstantsPortlet.DATABASE))) {
|
||||
if ((rs==null)||(rs.equals(""))){
|
||||
if ((elementType != null)
|
||||
&& (elementType.equals(ConstantsPortlet.DATABASE))) {
|
||||
if ((rs == null) || (rs.equals(""))) {
|
||||
throw new Exception("Unable to load data");
|
||||
}
|
||||
if ((db==null)||(db.equals(""))){
|
||||
if ((db == null) || (db.equals(""))) {
|
||||
throw new Exception("Unable to load data");
|
||||
}
|
||||
}
|
||||
|
@ -760,9 +826,9 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
|
|||
|
||||
// list that contains table attributes
|
||||
List<String> listAttributes = null;
|
||||
|
||||
//converted query
|
||||
String convertedQuery="";
|
||||
|
||||
// converted query
|
||||
String convertedQuery = "";
|
||||
|
||||
String algorithmId = "SUBMITQUERY";
|
||||
|
||||
|
@ -777,14 +843,14 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
|
|||
logger.info("dbmanager-> Query: " + query);
|
||||
logger.info("dbmanager-> SmartCorrections check: "
|
||||
+ smartCorrectionQuery);
|
||||
|
||||
if ((rs==null)||(rs.equals(""))){
|
||||
|
||||
if ((rs == null) || (rs.equals(""))) {
|
||||
throw new Exception("Unable to load data");
|
||||
}
|
||||
if ((db==null)||(db.equals(""))){
|
||||
if ((db == null) || (db.equals(""))) {
|
||||
throw new Exception("Unable to load data");
|
||||
}
|
||||
if ((query==null)||(query.equals(""))){
|
||||
if ((query == null) || (query.equals(""))) {
|
||||
throw new Exception("Unable to load data");
|
||||
}
|
||||
|
||||
|
@ -847,11 +913,11 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
|
|||
// System.out.println("output size submit: " +
|
||||
// output.size());
|
||||
// logger.info("build the result - finished");
|
||||
|
||||
//get the converted query
|
||||
|
||||
if (smartCorrectionQuery==true){
|
||||
convertedQuery=output.get(0).getValue();
|
||||
|
||||
// get the converted query
|
||||
|
||||
if (smartCorrectionQuery == true) {
|
||||
convertedQuery = output.get(0).getValue();
|
||||
output.remove(0);
|
||||
}
|
||||
|
||||
|
@ -891,19 +957,17 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
|
|||
// logger.info("dbmanager-> Application Path: " + applicationPath);
|
||||
String partialPathFile = applicationPath + "/computationResult/"
|
||||
+ fileName;
|
||||
|
||||
|
||||
|
||||
SubmitQueryResultWithFileFromServlet obj = new SubmitQueryResultWithFileFromServlet(
|
||||
listAttributes, convertedQuery, partialPathFile);
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public SamplingResultWithFileFromServlet sample(
|
||||
LinkedHashMap<String, String> dataInput, String elementType) throws Exception {
|
||||
LinkedHashMap<String, String> dataInput, String elementType)
|
||||
throws Exception {
|
||||
// data input
|
||||
List<Parameter> inputParameters = new ArrayList<Parameter>();
|
||||
// output sample result
|
||||
|
@ -922,29 +986,31 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
|
|||
logger.info("dbmanager-> DatabaseName: " + db);
|
||||
logger.info("dbmanager-> SchemaName: " + scm);
|
||||
logger.info("dbmanager-> TableName: " + tab);
|
||||
|
||||
if ((elementType!=null)&&(elementType.equals(ConstantsPortlet.SCHEMA))) {
|
||||
if ((rs==null)||(rs.equals(""))){
|
||||
|
||||
if ((elementType != null)
|
||||
&& (elementType.equals(ConstantsPortlet.SCHEMA))) {
|
||||
if ((rs == null) || (rs.equals(""))) {
|
||||
throw new Exception("Unable to load data");
|
||||
}
|
||||
if ((db==null)||(db.equals(""))){
|
||||
if ((db == null) || (db.equals(""))) {
|
||||
throw new Exception("Unable to load data");
|
||||
}
|
||||
if ((scm==null)||(scm.equals(""))){
|
||||
if ((scm == null) || (scm.equals(""))) {
|
||||
throw new Exception("Unable to load data");
|
||||
}
|
||||
if ((tab==null)||(tab.equals(""))){
|
||||
if ((tab == null) || (tab.equals(""))) {
|
||||
throw new Exception("Unable to load data");
|
||||
}
|
||||
}
|
||||
if ((elementType!=null)&&(elementType.equals(ConstantsPortlet.DATABASE))) {
|
||||
if ((rs==null)||(rs.equals(""))){
|
||||
if ((elementType != null)
|
||||
&& (elementType.equals(ConstantsPortlet.DATABASE))) {
|
||||
if ((rs == null) || (rs.equals(""))) {
|
||||
throw new Exception("Unable to load data");
|
||||
}
|
||||
if ((db==null)||(db.equals(""))){
|
||||
if ((db == null) || (db.equals(""))) {
|
||||
throw new Exception("Unable to load data");
|
||||
}
|
||||
if ((tab==null)||(tab.equals(""))){
|
||||
if ((tab == null) || (tab.equals(""))) {
|
||||
throw new Exception("Unable to load data");
|
||||
}
|
||||
}
|
||||
|
@ -1003,7 +1069,8 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
|
|||
|
||||
@Override
|
||||
public SamplingResultWithFileFromServlet smartSample(
|
||||
LinkedHashMap<String, String> dataInput, String elementType) throws Exception {
|
||||
LinkedHashMap<String, String> dataInput, String elementType)
|
||||
throws Exception {
|
||||
// data input
|
||||
List<Parameter> inputParameters = new ArrayList<Parameter>();
|
||||
// output sample result
|
||||
|
@ -1022,29 +1089,31 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
|
|||
logger.info("dbmanager-> DatabaseName: " + db);
|
||||
logger.info("dbmanager-> SchemaName: " + scm);
|
||||
logger.info("dbmanager-> TableName: " + tab);
|
||||
|
||||
if ((elementType!=null)&&(elementType.equals(ConstantsPortlet.SCHEMA))) {
|
||||
if ((rs==null)||(rs.equals(""))){
|
||||
|
||||
if ((elementType != null)
|
||||
&& (elementType.equals(ConstantsPortlet.SCHEMA))) {
|
||||
if ((rs == null) || (rs.equals(""))) {
|
||||
throw new Exception("Unable to load data");
|
||||
}
|
||||
if ((db==null)||(db.equals(""))){
|
||||
if ((db == null) || (db.equals(""))) {
|
||||
throw new Exception("Unable to load data");
|
||||
}
|
||||
if ((scm==null)||(scm.equals(""))){
|
||||
if ((scm == null) || (scm.equals(""))) {
|
||||
throw new Exception("Unable to load data");
|
||||
}
|
||||
if ((tab==null)||(tab.equals(""))){
|
||||
if ((tab == null) || (tab.equals(""))) {
|
||||
throw new Exception("Unable to load data");
|
||||
}
|
||||
}
|
||||
if ((elementType!=null)&&(elementType.equals(ConstantsPortlet.DATABASE))) {
|
||||
if ((rs==null)||(rs.equals(""))){
|
||||
if ((elementType != null)
|
||||
&& (elementType.equals(ConstantsPortlet.DATABASE))) {
|
||||
if ((rs == null) || (rs.equals(""))) {
|
||||
throw new Exception("Unable to load data");
|
||||
}
|
||||
if ((db==null)||(db.equals(""))){
|
||||
if ((db == null) || (db.equals(""))) {
|
||||
throw new Exception("Unable to load data");
|
||||
}
|
||||
if ((tab==null)||(tab.equals(""))){
|
||||
if ((tab == null) || (tab.equals(""))) {
|
||||
throw new Exception("Unable to load data");
|
||||
}
|
||||
}
|
||||
|
@ -1103,7 +1172,8 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
|
|||
|
||||
@Override
|
||||
public SamplingResultWithFileFromServlet randomSample(
|
||||
LinkedHashMap<String, String> dataInput, String elementType) throws Exception {
|
||||
LinkedHashMap<String, String> dataInput, String elementType)
|
||||
throws Exception {
|
||||
|
||||
// data input
|
||||
List<Parameter> inputParameters = new ArrayList<Parameter>();
|
||||
|
@ -1123,29 +1193,31 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
|
|||
logger.info("dbmanager-> DatabaseName: " + db);
|
||||
logger.info("dbmanager-> SchemaName: " + scm);
|
||||
logger.info("dbmanager-> TableName: " + tab);
|
||||
|
||||
if ((elementType!=null)&&(elementType.equals(ConstantsPortlet.SCHEMA))) {
|
||||
if ((rs==null)||(rs.equals(""))){
|
||||
|
||||
if ((elementType != null)
|
||||
&& (elementType.equals(ConstantsPortlet.SCHEMA))) {
|
||||
if ((rs == null) || (rs.equals(""))) {
|
||||
throw new Exception("Unable to load data");
|
||||
}
|
||||
if ((db==null)||(db.equals(""))){
|
||||
if ((db == null) || (db.equals(""))) {
|
||||
throw new Exception("Unable to load data");
|
||||
}
|
||||
if ((scm==null)||(scm.equals(""))){
|
||||
if ((scm == null) || (scm.equals(""))) {
|
||||
throw new Exception("Unable to load data");
|
||||
}
|
||||
if ((tab==null)||(tab.equals(""))){
|
||||
if ((tab == null) || (tab.equals(""))) {
|
||||
throw new Exception("Unable to load data");
|
||||
}
|
||||
}
|
||||
if ((elementType!=null)&&(elementType.equals(ConstantsPortlet.DATABASE))) {
|
||||
if ((rs==null)||(rs.equals(""))){
|
||||
if ((elementType != null)
|
||||
&& (elementType.equals(ConstantsPortlet.DATABASE))) {
|
||||
if ((rs == null) || (rs.equals(""))) {
|
||||
throw new Exception("Unable to load data");
|
||||
}
|
||||
if ((db==null)||(db.equals(""))){
|
||||
if ((db == null) || (db.equals(""))) {
|
||||
throw new Exception("Unable to load data");
|
||||
}
|
||||
if ((tab==null)||(tab.equals(""))){
|
||||
if ((tab == null) || (tab.equals(""))) {
|
||||
throw new Exception("Unable to load data");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue