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;
/** draw a picture of the yacy network */
public class NetworkPicture
{
public class NetworkPicture {
private static final ConcurrentLog log = new ConcurrentLog("NetworkPicture");
private static final Semaphore sync = new Semaphore(1, true);
private static EncodedImage buffer = null;
private static long lastAccessSeconds = 0;
public static EncodedImage respond(
final RequestHeader header,
final serverObjects post,
@ -52,26 +50,26 @@ public class NetworkPicture
final boolean authorized = sb.adminAuthenticated(header) >= 2;
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 = "
+ authorized
+ ", timeSeconds - lastAccessSeconds = "
+ (timeSeconds - lastAccessSeconds));
return buffer;
return NetworkGraph.buffer;
}
if ( buffer != null && sync.availablePermits() == 0 ) {
return buffer;
if ( NetworkGraph.buffer != null && sync.availablePermits() == 0 ) {
return NetworkGraph.buffer;
}
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 = "
+ authorized
+ ", timeSeconds - lastAccessSeconds = "
+ (timeSeconds - lastAccessSeconds));
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
@ -124,7 +122,7 @@ public class NetworkPicture
if ( maxCount > 10000 ) {
maxCount = 10000;
}
buffer =
NetworkGraph.buffer =
new EncodedImage(NetworkGraph.getNetworkPicture(
sb.peers,
width,
@ -141,7 +139,7 @@ public class NetworkPicture
lastAccessSeconds = System.currentTimeMillis() / 1000;
sync.release();
return buffer;
return NetworkGraph.buffer;
}
}

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

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

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

Loading…
Cancel
Save