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.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpSession;
|
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.CacheManager;
|
||||||
import net.sf.ehcache.Ehcache;
|
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.apache.regexp.RE;
|
||||||
import org.gcube.application.framework.core.session.ASLSession;
|
import org.gcube.application.framework.core.session.ASLSession;
|
||||||
|
@ -81,7 +86,8 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
|
||||||
.getLogger(GWTdbManagerServiceImpl.class);
|
.getLogger(GWTdbManagerServiceImpl.class);
|
||||||
|
|
||||||
// private CacheManager cacheManager;
|
// private CacheManager cacheManager;
|
||||||
private static Ehcache employeeCache;
|
private static Cache employeeCache;
|
||||||
|
private static CacheManager cacheManager;
|
||||||
public static List<String> listAlgorithms;
|
public static List<String> listAlgorithms;
|
||||||
|
|
||||||
public GWTdbManagerServiceImpl() throws Exception {
|
public GWTdbManagerServiceImpl() throws Exception {
|
||||||
|
@ -92,45 +98,93 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
|
||||||
|
|
||||||
super.init();
|
super.init();
|
||||||
|
|
||||||
// create cache
|
|
||||||
try {
|
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);
|
// cache folder
|
||||||
// if (!f.exists()){
|
String cachePath = System.getenv("CATALINA_TMPDIR") + "/DBManager";
|
||||||
// f.mkdir();
|
logger.info("dbmanager-> Creating cache in folder: " + cachePath);
|
||||||
//
|
|
||||||
// }
|
|
||||||
|
|
||||||
// config.setDiskStorePath(path);
|
CacheManager cacheManager = CacheManager.create();
|
||||||
// config.setDiskPersistent(true);
|
|
||||||
// config.setOverflowToDisk(true);
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
if (cacheManager == null) {
|
||||||
logger.error("dbmanager-> Failed to get cache: ", e);
|
logger.error("dbmanager-> Failed to get the cacheManager. cacheManager null");
|
||||||
// e.printStackTrace();
|
throw new ServletException(
|
||||||
throw e;
|
"Failed to get the cacheManager. cacheManager null");
|
||||||
}
|
}
|
||||||
|
|
||||||
// create folder that will contain file samplings and submitquery result
|
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
|
// in the /webapps/folder_portlet
|
||||||
String path = this.getServletContext().getRealPath("") + "/"
|
String path = this.getServletContext().getRealPath("") + "/"
|
||||||
+ "computationResult";
|
+ "computationResult";
|
||||||
|
|
||||||
// System.out.println("***PATH FILE: " + path);
|
|
||||||
|
|
||||||
File computationResult = new File(path);
|
File computationResult = new File(path);
|
||||||
if (!computationResult.exists()) {
|
if (!computationResult.exists()) {
|
||||||
computationResult.mkdir();
|
computationResult.mkdir();
|
||||||
// System.out.println("***DIRECTORY CREATED");
|
logger.info("dbmanager-> Folder computationResult created in : "
|
||||||
|
+ this.getServletContext().getRealPath(""));
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
// TODO: handle exception
|
||||||
|
logger.error("dbmanager-> ", e);
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void createCache(String cachePath) throws ServletException {
|
||||||
|
|
||||||
|
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();
|
super.destroy();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// System.out.println("*** REMOVING CACHE");
|
|
||||||
CacheManager cacheManager = CacheManager.getInstance();
|
CacheManager cacheManager = CacheManager.getInstance();
|
||||||
|
|
||||||
|
if (cacheManager != null) {
|
||||||
if (cacheManager.cacheExists("DBCache")) {
|
if (cacheManager.cacheExists("DBCache")) {
|
||||||
// System.out.println("*** cache exist");
|
// System.out.println("*** cache exist");
|
||||||
cacheManager.removeCache("DBCache");
|
cacheManager.removeCache("DBCache");
|
||||||
// cacheManager.removalAll();
|
// cacheManager.removalAll();
|
||||||
// System.out.println("*** cache removed");
|
// System.out.println("*** cache removed");
|
||||||
|
logger.info("dbmanager-> DBCache removed");
|
||||||
}
|
}
|
||||||
|
|
||||||
cacheManager.shutdown();
|
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) {
|
} catch (Exception e) {
|
||||||
// TODO: handle exception
|
// TODO: handle exception
|
||||||
logger.error("dbmanager-> ", e);
|
logger.error("dbmanager-> Failed to destroy the cache", e);
|
||||||
// e.printStackTrace();
|
// e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -513,7 +577,8 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
|
||||||
logger.info("dbmanager-> DatabaseName: " + db);
|
logger.info("dbmanager-> DatabaseName: " + db);
|
||||||
logger.info("dbmanager-> SchemaName: " + scm);
|
logger.info("dbmanager-> SchemaName: " + scm);
|
||||||
|
|
||||||
if ((elementType!=null)&&(elementType.equals(ConstantsPortlet.SCHEMA))) {
|
if ((elementType != null)
|
||||||
|
&& (elementType.equals(ConstantsPortlet.SCHEMA))) {
|
||||||
if ((rs == null) || (rs.equals(""))) {
|
if ((rs == null) || (rs.equals(""))) {
|
||||||
throw new Exception("Unable to load data");
|
throw new Exception("Unable to load data");
|
||||||
}
|
}
|
||||||
|
@ -524,7 +589,8 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
|
||||||
throw new Exception("Unable to load data");
|
throw new Exception("Unable to load data");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ((elementType!=null)&&(elementType.equals(ConstantsPortlet.DATABASE))) {
|
if ((elementType != null)
|
||||||
|
&& (elementType.equals(ConstantsPortlet.DATABASE))) {
|
||||||
if ((rs == null) || (rs.equals(""))) {
|
if ((rs == null) || (rs.equals(""))) {
|
||||||
throw new Exception("Unable to load data");
|
throw new Exception("Unable to load data");
|
||||||
}
|
}
|
||||||
|
@ -892,18 +958,16 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
|
||||||
String partialPathFile = applicationPath + "/computationResult/"
|
String partialPathFile = applicationPath + "/computationResult/"
|
||||||
+ fileName;
|
+ fileName;
|
||||||
|
|
||||||
|
|
||||||
SubmitQueryResultWithFileFromServlet obj = new SubmitQueryResultWithFileFromServlet(
|
SubmitQueryResultWithFileFromServlet obj = new SubmitQueryResultWithFileFromServlet(
|
||||||
listAttributes, convertedQuery, partialPathFile);
|
listAttributes, convertedQuery, partialPathFile);
|
||||||
|
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SamplingResultWithFileFromServlet sample(
|
public SamplingResultWithFileFromServlet sample(
|
||||||
LinkedHashMap<String, String> dataInput, String elementType) throws Exception {
|
LinkedHashMap<String, String> dataInput, String elementType)
|
||||||
|
throws Exception {
|
||||||
// data input
|
// data input
|
||||||
List<Parameter> inputParameters = new ArrayList<Parameter>();
|
List<Parameter> inputParameters = new ArrayList<Parameter>();
|
||||||
// output sample result
|
// output sample result
|
||||||
|
@ -923,7 +987,8 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
|
||||||
logger.info("dbmanager-> SchemaName: " + scm);
|
logger.info("dbmanager-> SchemaName: " + scm);
|
||||||
logger.info("dbmanager-> TableName: " + tab);
|
logger.info("dbmanager-> TableName: " + tab);
|
||||||
|
|
||||||
if ((elementType!=null)&&(elementType.equals(ConstantsPortlet.SCHEMA))) {
|
if ((elementType != null)
|
||||||
|
&& (elementType.equals(ConstantsPortlet.SCHEMA))) {
|
||||||
if ((rs == null) || (rs.equals(""))) {
|
if ((rs == null) || (rs.equals(""))) {
|
||||||
throw new Exception("Unable to load data");
|
throw new Exception("Unable to load data");
|
||||||
}
|
}
|
||||||
|
@ -937,7 +1002,8 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
|
||||||
throw new Exception("Unable to load data");
|
throw new Exception("Unable to load data");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ((elementType!=null)&&(elementType.equals(ConstantsPortlet.DATABASE))) {
|
if ((elementType != null)
|
||||||
|
&& (elementType.equals(ConstantsPortlet.DATABASE))) {
|
||||||
if ((rs == null) || (rs.equals(""))) {
|
if ((rs == null) || (rs.equals(""))) {
|
||||||
throw new Exception("Unable to load data");
|
throw new Exception("Unable to load data");
|
||||||
}
|
}
|
||||||
|
@ -1003,7 +1069,8 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SamplingResultWithFileFromServlet smartSample(
|
public SamplingResultWithFileFromServlet smartSample(
|
||||||
LinkedHashMap<String, String> dataInput, String elementType) throws Exception {
|
LinkedHashMap<String, String> dataInput, String elementType)
|
||||||
|
throws Exception {
|
||||||
// data input
|
// data input
|
||||||
List<Parameter> inputParameters = new ArrayList<Parameter>();
|
List<Parameter> inputParameters = new ArrayList<Parameter>();
|
||||||
// output sample result
|
// output sample result
|
||||||
|
@ -1023,7 +1090,8 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
|
||||||
logger.info("dbmanager-> SchemaName: " + scm);
|
logger.info("dbmanager-> SchemaName: " + scm);
|
||||||
logger.info("dbmanager-> TableName: " + tab);
|
logger.info("dbmanager-> TableName: " + tab);
|
||||||
|
|
||||||
if ((elementType!=null)&&(elementType.equals(ConstantsPortlet.SCHEMA))) {
|
if ((elementType != null)
|
||||||
|
&& (elementType.equals(ConstantsPortlet.SCHEMA))) {
|
||||||
if ((rs == null) || (rs.equals(""))) {
|
if ((rs == null) || (rs.equals(""))) {
|
||||||
throw new Exception("Unable to load data");
|
throw new Exception("Unable to load data");
|
||||||
}
|
}
|
||||||
|
@ -1037,7 +1105,8 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
|
||||||
throw new Exception("Unable to load data");
|
throw new Exception("Unable to load data");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ((elementType!=null)&&(elementType.equals(ConstantsPortlet.DATABASE))) {
|
if ((elementType != null)
|
||||||
|
&& (elementType.equals(ConstantsPortlet.DATABASE))) {
|
||||||
if ((rs == null) || (rs.equals(""))) {
|
if ((rs == null) || (rs.equals(""))) {
|
||||||
throw new Exception("Unable to load data");
|
throw new Exception("Unable to load data");
|
||||||
}
|
}
|
||||||
|
@ -1103,7 +1172,8 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SamplingResultWithFileFromServlet randomSample(
|
public SamplingResultWithFileFromServlet randomSample(
|
||||||
LinkedHashMap<String, String> dataInput, String elementType) throws Exception {
|
LinkedHashMap<String, String> dataInput, String elementType)
|
||||||
|
throws Exception {
|
||||||
|
|
||||||
// data input
|
// data input
|
||||||
List<Parameter> inputParameters = new ArrayList<Parameter>();
|
List<Parameter> inputParameters = new ArrayList<Parameter>();
|
||||||
|
@ -1124,7 +1194,8 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
|
||||||
logger.info("dbmanager-> SchemaName: " + scm);
|
logger.info("dbmanager-> SchemaName: " + scm);
|
||||||
logger.info("dbmanager-> TableName: " + tab);
|
logger.info("dbmanager-> TableName: " + tab);
|
||||||
|
|
||||||
if ((elementType!=null)&&(elementType.equals(ConstantsPortlet.SCHEMA))) {
|
if ((elementType != null)
|
||||||
|
&& (elementType.equals(ConstantsPortlet.SCHEMA))) {
|
||||||
if ((rs == null) || (rs.equals(""))) {
|
if ((rs == null) || (rs.equals(""))) {
|
||||||
throw new Exception("Unable to load data");
|
throw new Exception("Unable to load data");
|
||||||
}
|
}
|
||||||
|
@ -1138,7 +1209,8 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
|
||||||
throw new Exception("Unable to load data");
|
throw new Exception("Unable to load data");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ((elementType!=null)&&(elementType.equals(ConstantsPortlet.DATABASE))) {
|
if ((elementType != null)
|
||||||
|
&& (elementType.equals(ConstantsPortlet.DATABASE))) {
|
||||||
if ((rs == null) || (rs.equals(""))) {
|
if ((rs == null) || (rs.equals(""))) {
|
||||||
throw new Exception("Unable to load data");
|
throw new Exception("Unable to load data");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue