automatically clear graphics cache

pull/1/head
Michael Peter Christen 11 years ago
parent 505f58c79c
commit a1ac4c3b76

@ -36,14 +36,12 @@ import net.yacy.server.serverObjects;
import net.yacy.server.serverSwitch; import net.yacy.server.serverSwitch;
/** draw a picture of the yacy network */ /** draw a picture of the yacy network */
public class NetworkPicture public class NetworkPicture {
{
private static final ConcurrentLog log = new ConcurrentLog("NetworkPicture"); private static final ConcurrentLog log = new ConcurrentLog("NetworkPicture");
private static final Semaphore sync = new Semaphore(1, true); private static final Semaphore sync = new Semaphore(1, true);
private static EncodedImage buffer = null;
private static long lastAccessSeconds = 0; private static long lastAccessSeconds = 0;
public static EncodedImage respond( public static EncodedImage respond(
final RequestHeader header, final RequestHeader header,
final serverObjects post, final serverObjects post,
@ -52,26 +50,26 @@ public class NetworkPicture
final boolean authorized = sb.adminAuthenticated(header) >= 2; final boolean authorized = sb.adminAuthenticated(header) >= 2;
final long timeSeconds = System.currentTimeMillis() / 1000; final long timeSeconds = System.currentTimeMillis() / 1000;
if (buffer != null && !authorized && timeSeconds - lastAccessSeconds < 2) { if (NetworkGraph.buffer != null && !authorized && timeSeconds - lastAccessSeconds < 2) {
if (log.isFine()) log.fine("cache hit (1); authorized = " if (log.isFine()) log.fine("cache hit (1); authorized = "
+ authorized + authorized
+ ", timeSeconds - lastAccessSeconds = " + ", timeSeconds - lastAccessSeconds = "
+ (timeSeconds - lastAccessSeconds)); + (timeSeconds - lastAccessSeconds));
return buffer; return NetworkGraph.buffer;
} }
if ( buffer != null && sync.availablePermits() == 0 ) { if ( NetworkGraph.buffer != null && sync.availablePermits() == 0 ) {
return buffer; return NetworkGraph.buffer;
} }
sync.acquireUninterruptibly(); sync.acquireUninterruptibly();
if (buffer != null && !authorized && timeSeconds - lastAccessSeconds < 2) { if (NetworkGraph.buffer != null && !authorized && timeSeconds - lastAccessSeconds < 2) {
if (log.isFine()) log.fine("cache hit (2); authorized = " if (log.isFine()) log.fine("cache hit (2); authorized = "
+ authorized + authorized
+ ", timeSeconds - lastAccessSeconds = " + ", timeSeconds - lastAccessSeconds = "
+ (timeSeconds - lastAccessSeconds)); + (timeSeconds - lastAccessSeconds));
sync.release(); sync.release();
return buffer; return NetworkGraph.buffer;
} }
int width = 1280; // 640x480 = VGA, 768x576 = SD/4:3, 1024x576 =SD/16:9 1280x720 = HD/16:9, 1920x1080 = FULL HD/16:9 int width = 1280; // 640x480 = VGA, 768x576 = SD/4:3, 1024x576 =SD/16:9 1280x720 = HD/16:9, 1920x1080 = FULL HD/16:9
@ -124,7 +122,7 @@ public class NetworkPicture
if ( maxCount > 10000 ) { if ( maxCount > 10000 ) {
maxCount = 10000; maxCount = 10000;
} }
buffer = NetworkGraph.buffer =
new EncodedImage(NetworkGraph.getNetworkPicture( new EncodedImage(NetworkGraph.getNetworkPicture(
sb.peers, sb.peers,
width, width,
@ -141,7 +139,7 @@ public class NetworkPicture
lastAccessSeconds = System.currentTimeMillis() / 1000; lastAccessSeconds = System.currentTimeMillis() / 1000;
sync.release(); sync.release();
return buffer; return NetworkGraph.buffer;
} }
} }

@ -53,6 +53,8 @@ import net.yacy.visualization.RasterPlotter;
public class NetworkGraph { public class NetworkGraph {
private final static double DOUBLE_LONG_MAX_VALUE = Long.MAX_VALUE; private final static double DOUBLE_LONG_MAX_VALUE = Long.MAX_VALUE;
public static EncodedImage buffer = null;
private static int shortestName = 10; private static int shortestName = 10;
private static int longestName = 30; private static int longestName = 30;
@ -81,6 +83,10 @@ public class NetworkGraph {
/** Private constructor to avoid instantiation of utility class. */ /** Private constructor to avoid instantiation of utility class. */
private NetworkGraph() { } private NetworkGraph() { }
public static void clearcache() {
buffer = null;
}
public static class CircleThreadPiece { public static class CircleThreadPiece {
private final String pieceName; private final String pieceName;

@ -176,6 +176,7 @@ import net.yacy.peers.DHTSelection;
import net.yacy.peers.Protocol; import net.yacy.peers.Protocol;
import net.yacy.peers.Seed; import net.yacy.peers.Seed;
import net.yacy.peers.SeedDB; import net.yacy.peers.SeedDB;
import net.yacy.peers.graphics.NetworkGraph;
import net.yacy.peers.graphics.WebStructureGraph; import net.yacy.peers.graphics.WebStructureGraph;
import net.yacy.peers.operation.yacyBuildProperties; import net.yacy.peers.operation.yacyBuildProperties;
import net.yacy.peers.operation.yacyRelease; import net.yacy.peers.operation.yacyRelease;
@ -200,6 +201,7 @@ import net.yacy.server.http.RobotsTxtConfig;
import net.yacy.utils.CryptoLib; import net.yacy.utils.CryptoLib;
import net.yacy.utils.UPnP; import net.yacy.utils.UPnP;
import net.yacy.utils.crypt; import net.yacy.utils.crypt;
import net.yacy.visualization.CircleTool;
import com.google.common.io.Files; import com.google.common.io.Files;
@ -1999,6 +2001,9 @@ public final class Switchboard extends serverSwitch {
Cache.commit(); Cache.commit();
Digest.cleanup(); // don't let caches become permanent memory leaks Digest.cleanup(); // don't let caches become permanent memory leaks
// clear graphics caches
CircleTool.clearcache();
NetworkGraph.clearcache();
} }
public int cleanupJobSize() { public int cleanupJobSize() {

@ -35,6 +35,10 @@ import java.util.Set;
public class CircleTool { public class CircleTool {
private static List<int[]> circles = new ArrayList<>(); private static List<int[]> circles = new ArrayList<>();
public static void clearcache() {
circles.clear();
}
private static int[] getCircleCoords(final short radius) { private static int[] getCircleCoords(final short radius) {
if (radius - 1 < circles.size()) return circles.get(radius - 1); if (radius - 1 < circles.size()) return circles.get(radius - 1);

Loading…
Cancel
Save