added a buffer for network images to reduced load on yacy.net network image server

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@7007 6c8d7289-2bf4-0310-a012-ef5d649a1542
pull/1/head
orbiter 15 years ago
parent d5c65b17a6
commit e7ea3b3cc5

@ -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;
}
}

@ -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 client

@ -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;
}
}
Loading…
Cancel
Save