Skip to content

DM-8579: vis server cleanup #247

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 6, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package edu.caltech.ipac.firefly.server;

import edu.caltech.ipac.firefly.data.ServerParams;
import edu.caltech.ipac.firefly.server.visualize.SrvParam;
import edu.caltech.ipac.firefly.util.BrowserInfo;
import edu.caltech.ipac.util.StringUtils;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,12 @@


import edu.caltech.ipac.firefly.data.ServerParams;
import edu.caltech.ipac.firefly.server.rpc.JsonDataCommands;
import edu.caltech.ipac.firefly.server.rpc.PushCommands;
import edu.caltech.ipac.firefly.server.rpc.ResolveServerCommands;
import edu.caltech.ipac.firefly.server.rpc.ResourceServerCommands;
import edu.caltech.ipac.firefly.server.rpc.VisServerCommands;
import edu.caltech.ipac.firefly.server.servlets.HttpServCommands;
import edu.caltech.ipac.firefly.server.visualize.*;
import edu.caltech.ipac.firefly.server.query.SearchServerCommands;

import javax.servlet.http.HttpServletRequest;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
/*
* License information at https://github.com/Caltech-IPAC/firefly/blob/master/License.txt
*/
package edu.caltech.ipac.firefly.server.visualize;

/*
* License information at https://github.com/Caltech-IPAC/firefly/blob/master/License.txt
*/
package edu.caltech.ipac.firefly.server;
/**
* User: roby
* Date: 12/19/12
Expand All @@ -12,6 +16,7 @@
import edu.caltech.ipac.firefly.data.ServerParams;
import edu.caltech.ipac.firefly.data.TableServerRequest;
import edu.caltech.ipac.firefly.server.util.QueryUtil;
import edu.caltech.ipac.firefly.server.visualize.VisJsonSerializer;
import edu.caltech.ipac.firefly.visualize.PlotState;
import edu.caltech.ipac.firefly.visualize.WebPlotRequest;
import edu.caltech.ipac.visualize.plot.ImagePt;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import edu.caltech.ipac.util.StringUtils;
import edu.caltech.ipac.util.cache.Cache;
import edu.caltech.ipac.util.cache.CacheKey;
import edu.caltech.ipac.util.cache.Cleanupable;
import edu.caltech.ipac.util.cache.FileHolder;
import edu.caltech.ipac.util.download.URLDownload;
import net.sf.ehcache.CacheException;
Expand All @@ -23,7 +22,6 @@
import java.net.URL;
import java.util.HashMap;
import java.util.List;
import java.util.concurrent.TimeUnit;

/**
* Date: Jul 17, 2008
Expand All @@ -37,9 +35,6 @@ public class EhcacheProvider implements Cache.Provider {
private static final net.sf.ehcache.CacheManager manager;
private static net.sf.ehcache.CacheManager sharedManager;
private static final boolean enableJMX = AppProperties.getBooleanProperty("ehcache.jmx.monitor", true);
private static final int cleanupIntervalMin = AppProperties.getIntProperty("ehcache.cleanup.internal.minutes", 5);
private static final String cleanupTypes[] = findCleanupCacheTypes();
// private static final MemCleanup cleanup= new MemCleanup();
private static HashMap<String, Boolean> fileListenersReg = new HashMap<String, Boolean>();
private static HashMap<String, Boolean> logListenersReg = new HashMap<String, Boolean>();
private static long curConfModTime = 0;
Expand Down Expand Up @@ -85,8 +80,6 @@ public class EhcacheProvider implements Cache.Provider {
}


// if (cleanupTypes.length>0) cleanup.start();

if (enableJMX) {
// // enable JMX monitoring for ehcache
// MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
Expand Down Expand Up @@ -357,77 +350,4 @@ private void logEvent(String event, Ehcache cache, Element element) {
// StringUtils.toString(element.getValue()));
}
}


private static class MemCleanup implements Runnable {


private volatile Thread _thread= null;

MemCleanup() {
}

public void stop() {
synchronized (this) {
Thread t= _thread;
_thread= null;
if (t!=null) t.interrupt();
}
}

public void start() {
synchronized (this) {
if (_thread==null) {
_thread= new Thread(this, "EhcacheProvider-cleanup");
}
_thread.setDaemon(true);
_thread.start();
}
}

public void run() {
try {
boolean loop = true;
while (loop) {

Element el;
Ehcache ehcache;
List list;
long cleanUpTime = System.currentTimeMillis() - (cleanupIntervalMin * 1000 * 60);
for (String ctype : cleanupTypes) {
ehcache = manager.getCache(ctype);
list = ehcache.getKeys();
// Logger.briefDebug("MemCleanup awake, list size: " + list.size());
for (Object key : list) {
el = ehcache.getQuiet(key);
if (el != null && el.getValue() instanceof Cleanupable &&
el.getLastAccessTime() < cleanUpTime) {
((Cleanupable) el.getValue()).cleanup();
}
}
}

synchronized (this) {
loop = (_thread != null);
}

if (loop) {
try {
TimeUnit.SECONDS.sleep(120);
} catch (InterruptedException e) { /* ignore*/ }
}


synchronized (this) {
loop = (_thread != null);
}

}
} catch (Throwable e) {
_log.error(e, "MemCleanup encountered unexpected exception. This should not happen.");
}
_log.briefDebug("MemCleanup exiting");
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
import edu.caltech.ipac.firefly.server.util.QueryUtil;
import edu.caltech.ipac.firefly.server.util.ipactable.DataGroupPart;
import edu.caltech.ipac.firefly.server.visualize.FileData;
import edu.caltech.ipac.firefly.server.visualize.FileRetriever;
import edu.caltech.ipac.firefly.server.visualize.FileRetrieverFactory;
import edu.caltech.ipac.firefly.server.visualize.imageretrieve.FileRetriever;
import edu.caltech.ipac.firefly.server.visualize.imageretrieve.ImageFileRetrieverFactory;
import edu.caltech.ipac.firefly.ui.creator.CommonParams;
import edu.caltech.ipac.firefly.visualize.WebPlotRequest;
import edu.caltech.ipac.util.DataGroup;
Expand Down Expand Up @@ -142,7 +142,7 @@ private FileInfo makeFileInfoForRequest(DataObject data,
}

WebPlotRequest wpReq= WebPlotRequest.makeProcessorRequest(sr,"dummy title");
FileRetriever retrieve= FileRetrieverFactory.getRetriever(wpReq);
FileRetriever retrieve= ImageFileRetrieverFactory.getRetriever(wpReq);
if (retrieve!=null) {
try {
FileData fileData = retrieve.getFile(wpReq);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import edu.caltech.ipac.firefly.server.util.QueryUtil;
import edu.caltech.ipac.firefly.server.util.ipactable.DataGroupPart;
import edu.caltech.ipac.firefly.server.util.ipactable.JsonTableUtil;
import edu.caltech.ipac.firefly.server.visualize.SrvParam;
import edu.caltech.ipac.firefly.server.SrvParam;
import edu.caltech.ipac.util.CollectionUtil;
import edu.caltech.ipac.util.StringUtils;
import org.json.simple.JSONObject;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,16 @@
*/
package edu.caltech.ipac.firefly.server.query;

import edu.caltech.ipac.firefly.server.ServerContext;
import edu.caltech.ipac.util.download.FailedRequestException;
import edu.caltech.ipac.firefly.core.SearchDescResolver;
import edu.caltech.ipac.firefly.data.ServerRequest;
import edu.caltech.ipac.firefly.data.table.TableMeta;
import edu.caltech.ipac.firefly.server.ServerContext;
import edu.caltech.ipac.firefly.server.packagedata.FileInfo;
import edu.caltech.ipac.firefly.server.util.Logger;
import edu.caltech.ipac.firefly.server.visualize.LockingVisNetwork;
import edu.caltech.ipac.util.DataType;
import edu.caltech.ipac.util.download.FailedRequestException;
import edu.caltech.ipac.visualize.net.AnyUrlParams;

import java.io.IOException;
import java.io.OutputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;
import java.util.Map;


Expand Down Expand Up @@ -46,7 +40,6 @@ protected FileInfo loadData(ServerRequest sr) throws IOException, DataAccessExce
}
}
retval= LockingVisNetwork.getFitsFile(params);
_logger.info("retrieving URL:" + url.toString());
} catch (FailedRequestException e) {
_logger.warn(e, "Could not retrieve URL");
} catch (MalformedURLException e) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
/*
* License information at https://github.com/Caltech-IPAC/firefly/blob/master/License.txt
*/
package edu.caltech.ipac.firefly.server.visualize;

/*
* License information at https://github.com/Caltech-IPAC/firefly/blob/master/License.txt
*/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

duplicate addition.

package edu.caltech.ipac.firefly.server.rpc;
/**
* User: roby
* Date: 3/5/12
Expand All @@ -10,6 +14,7 @@


import edu.caltech.ipac.firefly.server.ServCommand;
import edu.caltech.ipac.firefly.server.SrvParam;
import edu.caltech.ipac.util.download.URLDownload;
import edu.caltech.ipac.firefly.data.ServerParams;
import edu.caltech.ipac.firefly.server.ServerContext;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
import edu.caltech.ipac.firefly.server.ServerContext;
import edu.caltech.ipac.firefly.server.query.SearchManager;
import edu.caltech.ipac.firefly.server.visualize.FileData;
import edu.caltech.ipac.firefly.server.visualize.FileRetriever;
import edu.caltech.ipac.firefly.server.visualize.FileRetrieverFactory;
import edu.caltech.ipac.firefly.server.visualize.imageretrieve.FileRetriever;
import edu.caltech.ipac.firefly.server.visualize.imageretrieve.ImageFileRetrieverFactory;
import edu.caltech.ipac.firefly.server.visualize.VisServerOps;
import edu.caltech.ipac.firefly.visualize.Band;
import edu.caltech.ipac.firefly.visualize.FileAndHeaderInfo;
Expand Down Expand Up @@ -61,7 +61,7 @@ public WebPlotResult recomputeStretch(PlotState state,


public WebPlotResult setZoomLevel(PlotState state[], float level, boolean isFullScreen) {
return VisServerOps.setZoomLevel(state, level, false, isFullScreen);
return VisServerOps.setZoomLevel(state, level, isFullScreen);
}

public WebPlotResult crop(PlotState stateAry[],
Expand Down Expand Up @@ -205,7 +205,7 @@ private WebPlotResult getRawDataSetResult(WebPlotRequest request){
}
} else {
File f= null;
FileRetriever retrieve= FileRetrieverFactory.getRetriever(request);
FileRetriever retrieve= ImageFileRetrieverFactory.getRetriever(request);
if (retrieve!=null) {
FileData retf= retrieve.getFile(request);
f= retf.getFile();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
/*
* License information at https://github.com/Caltech-IPAC/firefly/blob/master/License.txt
*/
package edu.caltech.ipac.firefly.server.visualize;

/*
* License information at https://github.com/Caltech-IPAC/firefly/blob/master/License.txt
*/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

duplicate license info.

package edu.caltech.ipac.firefly.server.rpc;
/**
* User: roby
* Date: 3/5/12
Expand All @@ -16,8 +20,9 @@
import edu.caltech.ipac.firefly.data.ServerEvent;
import edu.caltech.ipac.firefly.data.ServerParams;
import edu.caltech.ipac.firefly.server.ServCommand;
import edu.caltech.ipac.firefly.server.ServerContext;
import edu.caltech.ipac.firefly.server.SrvParam;
import edu.caltech.ipac.firefly.server.events.ServerEventManager;
import edu.caltech.ipac.firefly.server.vispush.PushJob;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;

Expand All @@ -39,7 +44,7 @@ public static class PushAliveCheck extends BaseVisPushCommand {
public String doCommand(Map<String, String[]> paramMap) throws Exception {
SrvParam sp= new SrvParam(paramMap);
String channel= sp.getOptional(ServerParams.CHANNEL_ID);
boolean active= PushJob.getBrowserClientActiveCount(channel,0)>1;
boolean active= getBrowserClientActiveCount(channel,0)>1;
JSONObject map = new JSONObject();
JSONArray outJson = new JSONArray();
outJson.add(map);
Expand All @@ -55,7 +60,7 @@ public String doCommand(Map<String, String[]> paramMap) throws Exception {
SrvParam sp= new SrvParam(paramMap);
String channel= sp.getOptional(ServerParams.CHANNEL_ID);
int tryTime= sp.getOptionalInt(ServerParams.TRY_MS,0);
int activeCount= PushJob.getBrowserClientActiveCount(channel,tryTime);
int activeCount= getBrowserClientActiveCount(channel,tryTime);
JSONObject map = new JSONObject();
JSONArray outJson = new JSONArray();
outJson.add(map);
Expand All @@ -81,4 +86,20 @@ public String doCommand(Map<String, String[]> paramMap) throws Exception {
}

}

private static int getBrowserClientActiveCount(String channel, int tryTime) {
if (channel==null) channel= ServerContext.getRequestOwner().getEventChannel();
int cnt= ServerEventManager.getActiveQueueChannelCnt(channel);
long endTry= System.currentTimeMillis()+tryTime;

try {
while (tryTime>0 && cnt==0 && System.currentTimeMillis()<endTry) {
Thread.sleep(200);
cnt= ServerEventManager.getActiveQueueChannelCnt(channel);
}
} catch (InterruptedException e) {
}

return cnt;
}
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
/*
* License information at https://github.com/Caltech-IPAC/firefly/blob/master/License.txt
*/
package edu.caltech.ipac.firefly.server.visualize;
/**
* User: roby
* Date: 3/5/12
* Time: 12:26 PM
*/
package edu.caltech.ipac.firefly.server.rpc;


import edu.caltech.ipac.astro.net.Resolver;
import edu.caltech.ipac.firefly.data.ServerParams;
import edu.caltech.ipac.firefly.server.ServCommand;
import edu.caltech.ipac.firefly.server.rpc.TargetServicesImpl;
import edu.caltech.ipac.astro.net.Resolver;
import edu.caltech.ipac.firefly.server.SrvParam;
import edu.caltech.ipac.visualize.plot.ResolvedWorldPt;

import java.util.Map;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
/*
* License information at https://github.com/Caltech-IPAC/firefly/blob/master/License.txt
*/
package edu.caltech.ipac.firefly.server.visualize;
/**
* User: roby
* Date: 3/5/12
* Time: 12:26 PM
*/

package edu.caltech.ipac.firefly.server.rpc;

import edu.caltech.ipac.firefly.data.ServerParams;
import edu.caltech.ipac.firefly.data.Version;
import edu.caltech.ipac.firefly.server.ServCommand;
import edu.caltech.ipac.firefly.server.rpc.ResourceServicesImpl;
import edu.caltech.ipac.firefly.server.SrvParam;

import java.util.Map;

Expand Down
Loading