Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance
Java decentralizedintranet-searchintranet-search-enginep2pp2p-networkprivacyprivacy-protectionsearch-enginesearchenginewebweb-search-enginewebsearchwebseearch-engine
added a buffer for network images to reduced load on yacy.net network image server
orbitere7ea3b3cc5ec
diff --git a/htroot/NetworkPicture.java b/htroot/NetworkPicture.javaindex 6fd72b7b8..a06769809 100644--- a/htroot/NetworkPicture.java+++ b/htroot/NetworkPicture.java@@ -24,21 +24,32 @@// along with this program; if not, write to the Free Software// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA-import net.yacy.visualization.RasterPlotter;+import java.util.TreeMap;+import de.anomic.http.server.RequestHeader;import de.anomic.search.Switchboard;import de.anomic.search.SwitchboardConstants;import de.anomic.server.serverObjects;import de.anomic.server.serverSwitch;+import de.anomic.yacy.graphics.EncodedImage;import de.anomic.yacy.graphics.NetworkGraph;/** draw a picture of the yacy network */public class NetworkPicture {- public static RasterPlotter respond(final RequestHeader header, final serverObjects post, final serverSwitch env) {+ private static final TreeMap<Long, EncodedImage> buffer = new TreeMap<Long, EncodedImage>();++ public static EncodedImage respond(final RequestHeader header, final serverObjects post, final serverSwitch env) {final Switchboard sb = (Switchboard) env;final boolean authorized = sb.adminAuthenticated(header) >= 2;+ long timeSeconds = System.currentTimeMillis() / 1000;+ EncodedImage bufferedImage = null;+ synchronized (buffer) {+ bufferedImage = buffer.get(timeSeconds);+ }+ if (bufferedImage != null) return bufferedImage;+int width = 768;int height = 576;int passiveLimit = 720; // 12 hours@@ -73,7 +84,12 @@ public class NetworkPicture {if (passiveLimit > 1000000) passiveLimit = 1000000;if (potentialLimit > 1000000) potentialLimit = 1000000;if (maxCount > 10000) maxCount = 10000;- return NetworkGraph.getNetworkPicture(sb.peers, 10000, width, height, passiveLimit, potentialLimit, maxCount, coronaangle, communicationTimeout, env.getConfig(SwitchboardConstants.NETWORK_NAME, "unspecified"), env.getConfig("network.unit.description", "unspecified"), bgcolor);+ bufferedImage = new EncodedImage(NetworkGraph.getNetworkPicture(sb.peers, 10000, width, height, passiveLimit, potentialLimit, maxCount, coronaangle, communicationTimeout, env.getConfig(SwitchboardConstants.NETWORK_NAME, "unspecified"), env.getConfig("network.unit.description", "unspecified"), bgcolor).getImage(), "png");+ synchronized (buffer) {+ buffer.put(timeSeconds, bufferedImage);+ while (buffer.size() > 8) buffer.remove(buffer.firstKey());+ }+ return bufferedImage;}}diff --git a/source/de/anomic/http/server/HTTPDFileHandler.java b/source/de/anomic/http/server/HTTPDFileHandler.javaindex 8e06c86ef..9ec7f6bfa 100644--- a/source/de/anomic/http/server/HTTPDFileHandler.java+++ b/source/de/anomic/http/server/HTTPDFileHandler.java@@ -101,6 +101,7 @@ import de.anomic.server.serverObjects;import de.anomic.server.serverSwitch;import de.anomic.server.servletProperties;import de.anomic.yacy.yacyBuildProperties;+import de.anomic.yacy.graphics.EncodedImage;public final class HTTPDFileHandler {@@ -548,6 +549,20 @@ public final class HTTPDFileHandler {result.writeTo(out);}}+ if (img instanceof EncodedImage) {+ final EncodedImage yp = (EncodedImage) img;+ // send an image to client+ targetDate = new Date(System.currentTimeMillis());+ nocache = true;+ final String mimeType = MimeTable.ext2mime(targetExt, "text/html");+ final ByteBuffer result = yp.getImage();++ // write the array to the client+ HTTPDemon.sendRespondHeader(conProp, out, httpVersion, 200, null, mimeType, result.length(), targetDate, null, null, null, null, nocache);+ if (!method.equals(HeaderFramework.METHOD_HEAD)) {+ result.writeTo(out);+ }+ }if (img instanceof Image) {final Image i = (Image) img;// send an image to clientdiff --git a/source/de/anomic/yacy/graphics/EncodedImage.java b/source/de/anomic/yacy/graphics/EncodedImage.javanew file mode 100644index 000000000..7c4337f62--- /dev/null+++ b/source/de/anomic/yacy/graphics/EncodedImage.java@@ -0,0 +1,24 @@+package de.anomic.yacy.graphics;++import java.awt.image.BufferedImage;++import net.yacy.kelondro.util.ByteBuffer;+import net.yacy.visualization.RasterPlotter;++public class EncodedImage {+ private ByteBuffer image;+ private String extension;++ public EncodedImage(final BufferedImage sourceImage, final String targetExt) {+ this.image = RasterPlotter.exportImage(sourceImage, targetExt);+ this.extension = targetExt;+ }++ public ByteBuffer getImage() {+ return this.image;+ }++ public String getExtension() {+ return this.extension;+ }+}