Skip to content

Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance

- generalized ymage initialization options - auto-adoption of performance memory graph to needed dimension

orbiterbe214e594f00
diff --git a/htroot/Banner.java b/htroot/Banner.java
index d169c2942..3f29e9b2b 100644
--- a/htroot/Banner.java
+++ b/htroot/Banner.java
@@ -55,10 +55,7 @@ import de.anomic.ymage.ymageMatrix;
import de.anomic.yacy.yacyCore;
import de.anomic.yacy.yacySeed;
-import java.awt.Image;
import java.awt.image.BufferedImage;
-import java.awt.Toolkit;
-import java.io.File;
import java.io.IOException;
import java.net.URL;
import javax.imageio.ImageIO;
diff --git a/htroot/PerformanceGraph.java b/htroot/PerformanceGraph.java
index 5715b7882..05004f91d 100644
--- a/htroot/PerformanceGraph.java
+++ b/htroot/PerformanceGraph.java
@@ -40,16 +40,43 @@ public class PerformanceGraph {
public static ymageMatrix respond(httpHeader header, serverObjects post, serverSwitch env) {
plasmaSwitchboard sb = (plasmaSwitchboard) env;
- ymageChart ip = new ymageChart(660, 240, "000010", 30, 30, 20, 20, "PEER PERFORMANCE GRAPH: PAGES/MINUTE and USED MEMORY");
- ip.declareDimension(ymageChart.DIMENSION_BOTTOM, 60, 60, -600, "000000", "CCCCCC", "TIME/SECONDS");
- ip.declareDimension(ymageChart.DIMENSION_LEFT, 50, 40, 0, "008800", null , "PPM [PAGES/MINUTE]");
- ip.declareDimension(ymageChart.DIMENSION_RIGHT, 100, 20, 0, "0000FF", "CCCCCC", "MEMORY/MEGABYTE");
+ if (post == null) post = new serverObjects();
- // draw ppm
- ip.setColor("008800");
+ // find maximum values for automatic graph dimension adoption
Iterator i = sb.ppmHistory.entrySet().iterator();
Map.Entry entry;
- int ppm;
+ int ppm, maxppm = 50;
+ while (i.hasNext()) {
+ entry = (Map.Entry) i.next();
+ ppm = (int) ((Long) entry.getValue()).longValue();
+ if (ppm > maxppm) maxppm = ppm;
+ }
+ i = sb.usedMemoryHistory.entrySet().iterator();
+ long bytes, maxbytes = 100 * 1024 * 1024;
+ while (i.hasNext()) {
+ entry = (Map.Entry) i.next();
+ bytes = ((Long) entry.getValue()).longValue();
+ if (bytes > maxbytes) maxbytes = bytes;
+ }
+
+ // declare graph and set dimensions
+ int height = 240;
+ int width = 660;
+ int leftborder = 30;
+ int rightborder = 30;
+ int topborder = 20;
+ int bottomborder = 20;
+ int vspace = height - topborder - bottomborder;
+ int hspace = width - leftborder - rightborder;
+ int maxtime = 600;
+ ymageChart ip = new ymageChart(width, height, "FFFFFF", "000000", leftborder, rightborder, topborder, bottomborder, "PEER PERFORMANCE GRAPH: PAGES/MINUTE and USED MEMORY");
+ ip.declareDimension(ymageChart.DIMENSION_BOTTOM, 60, hspace / (maxtime / 60), -maxtime, "000000", "CCCCCC", "TIME/SECONDS");
+ ip.declareDimension(ymageChart.DIMENSION_LEFT, 20, /*40*/ vspace * 20 / maxppm, 0, "008800", null , "PPM [PAGES/MINUTE]");
+ ip.declareDimension(ymageChart.DIMENSION_RIGHT, 100, /*20*/ vspace * 100 / (int)(maxbytes / 1024 / 1024), 0, "0000FF", "CCCCCC", "MEMORY/MEGABYTE");
+
+ // draw ppm
+ ip.setColor("008800");
+ i = sb.ppmHistory.entrySet().iterator();
long time, now = System.currentTimeMillis();
int x0 = 1, x1, y0 = 0, y1;
while (i.hasNext()) {
@@ -59,7 +86,7 @@ public class PerformanceGraph {
//System.out.println("PPM: time = " + time + ", ppm = " + ppm);
x1 = (int) (time/1000);
y1 = ppm;
- ip.chartDot(ymageChart.DIMENSION_BOTTOM, ymageChart.DIMENSION_LEFT, x1, y1, 2);
+ ip.chartDot(ymageChart.DIMENSION_BOTTOM, ymageChart.DIMENSION_LEFT, x1, y1, 1);
if (x0 < 0) ip.chartLine(ymageChart.DIMENSION_BOTTOM, ymageChart.DIMENSION_LEFT, x0, y0, x1, y1);
x0 = x1; y0 = y1;
}
@@ -67,7 +94,6 @@ public class PerformanceGraph {
// draw memory
ip.setColor("0000FF");
i = sb.usedMemoryHistory.entrySet().iterator();
- long bytes;
x0 = 1;
while (i.hasNext()) {
entry = (Map.Entry) i.next();
@@ -76,7 +102,7 @@ public class PerformanceGraph {
//System.out.println("Memory: time = " + time + ", bytes = " + bytes);
x1 = (int) (time/1000);
y1 = (int) (bytes / 1024 / 1024);
- ip.chartDot(ymageChart.DIMENSION_BOTTOM, ymageChart.DIMENSION_RIGHT, x1, y1, 2);
+ ip.chartDot(ymageChart.DIMENSION_BOTTOM, ymageChart.DIMENSION_RIGHT, x1, y1, 1);
if (x0 < 0) ip.chartLine(ymageChart.DIMENSION_BOTTOM, ymageChart.DIMENSION_RIGHT, x0, y0, x1, y1);
x0 = x1; y0 = y1;
}
diff --git a/htroot/SearchEventPicture.java b/htroot/SearchEventPicture.java
index 634ec0dc2..068a9305d 100644
--- a/htroot/SearchEventPicture.java
+++ b/htroot/SearchEventPicture.java
@@ -60,7 +60,7 @@ public class SearchEventPicture {
String eventID = (String) header.get("event", plasmaSearchEvent.lastEventID);
if (eventID == null) return null;
ymageMatrix yp = plasmaGrafics.getSearchEventPicture(eventID);
- if (yp == null) return new ymageMatrix(1, 1, "000000"); // empty image
+ if (yp == null) return new ymageMatrix(1, 1, ymageMatrix.MODE_SUB, "000000"); // empty image
return yp;
}
diff --git a/htroot/WebStructurePicture_p.java b/htroot/WebStructurePicture_p.java
index 22f57ddb9..392134241 100644
--- a/htroot/WebStructurePicture_p.java
+++ b/htroot/WebStructurePicture_p.java
@@ -83,8 +83,7 @@ public class WebStructurePicture_p {
ymageMatrix graphPicture;
if (host == null) {
// probably no information available
- graphPicture = new ymageMatrix(width, height, ymageGraph.color_back);
- graphPicture.setMode(ymageMatrix.MODE_SUB);
+ graphPicture = new ymageMatrix(width, height, ymageMatrix.MODE_SUB, ymageGraph.color_back);
ymageToolPrint.print(graphPicture, width / 2, height / 2, 0, "NO WEB STRUCTURE DATA AVAILABLE.", 0);
ymageToolPrint.print(graphPicture, width / 2, height / 2 + 16, 0, "START A WEB CRAWL TO OBTAIN STRUCTURE DATA.", 0);
} else {
@@ -104,7 +103,6 @@ public class WebStructurePicture_p {
}
// print headline
graphPicture.setColor(ymageGraph.color_text);
- graphPicture.setMode(ymageMatrix.MODE_SUB);
ymageToolPrint.print(graphPicture, 2, 8, 0, "YACY WEB-STRUCTURE ANALYSIS", -1);
if (host != null) ymageToolPrint.print(graphPicture, 2, 16, 0, "LINK ENVIRONMENT OF DOMAIN " + host.toUpperCase(), -1);
ymageToolPrint.print(graphPicture, width - 2, 8, 0, "SNAPSHOT FROM " + new Date().toString().toUpperCase(), 1);
diff --git a/htroot/imagetest.java b/htroot/imagetest.java
index 004dd6cd9..69277accf 100644
--- a/htroot/imagetest.java
+++ b/htroot/imagetest.java
@@ -84,9 +84,7 @@ public class imagetest {
for (int i = 20; i < 100; i++) r.setPixel(i, 34, new int[]{0, 0, 255});
return bi;
*/
- ymageMatrix img = new ymageMatrix(800, 600, "000000");
-
- img.setMode(ymageMatrix.MODE_SUB);
+ ymageMatrix img = new ymageMatrix(800, 600, ymageMatrix.MODE_SUB, "000000");
img.setColor(ymageMatrix.SUBTRACTIVE_BLACK);
for (int y = 0; y < 600; y = y + 50) ymageToolPrint.print(img, 0, 6 + y, 0, "" + y, -1);
for (int x = 0; x < 800; x = x + 50) ymageToolPrint.print(img, x, 6 , 0, "" + x, -1);
diff --git a/source/dbtest.java b/source/dbtest.java
index 48994287e..83dced322 100644
--- a/source/dbtest.java
+++ b/source/dbtest.java
@@ -472,7 +472,7 @@ final class memprofiler extends Thread {
public memprofiler(int width, int height, int expectedTimeSeconds, File outputFile) {
this.outputFile = outputFile;
int expectedKilobytes = 20 * 1024;//(Runtime.getRuntime().totalMemory() / 1024);
- memChart = new ymageChart(width, height, "000010", 50, 20, 20, 20, "MEMORY CHART FROM EXECUTION AT " + new Date());
+ memChart = new ymageChart(width, height, "FFFFFF", "000000", 50, 20, 20, 20, "MEMORY CHART FROM EXECUTION AT " + new Date());
int timescale = 10; // steps with each 10 seconds
int memscale = 1024;
memChart.declareDimension(ymageChart.DIMENSION_BOTTOM, timescale, (width - 40) * timescale / expectedTimeSeconds, 0, "FFFFFF", "555555", "SECONDS");
diff --git a/source/de/anomic/plasma/plasmaGrafics.java b/source/de/anomic/plasma/plasmaGrafics.java
index 9add8dbb1..f6b3be98a 100644
--- a/source/de/anomic/plasma/plasmaGrafics.java
+++ b/source/de/anomic/plasma/plasmaGrafics.java
@@ -49,7 +49,6 @@ package de.anomic.plasma;
import java.awt.Color;
import java.awt.Graphics2D;
-import java.awt.Image;
import java.awt.RenderingHints;
import java.awt.image.BufferedImage;
import java.util.Date;
@@ -168,7 +167,6 @@ public class plasmaGrafics {
// draw in the search target
plasmaSearchQuery query = event.getQuery();
Iterator i = query.queryHashes.iterator();
- eventPicture.setMode(ymageMatrix.MODE_SUB);
eventPicture.setColor(ymageMatrix.SUBTRACTIVE_BLACK);
while (i.hasNext()) {
hash = (String) i.next();
@@ -198,8 +196,7 @@ public class plasmaGrafics {
if (yacyCore.seedDB == null) return; // no other peers known
- networkPicture = new ymageMatrix(width, height, bgcolor);
- networkPicture.setMode(ymageMatrix.MODE_SUB);
+ networkPicture = new ymageMatrix(width, height, ymageMatrix.MODE_SUB, bgcolor);
// draw network circle
networkPicture.setColor(COL_DHTCIRCLE);
@@ -258,7 +255,6 @@ public class plasmaGrafics {
// draw description
networkPicture.setColor(COL_HEADLINE);
- networkPicture.setMode(ymageMatrix.MODE_SUB);
ymageToolPrint.print(networkPicture, 2, 8, 0, "YACY NETWORK '" + networkName.toUpperCase() + "'", -1);
ymageToolPrint.print(networkPicture, 2, 16, 0, networkTitle.toUpperCase(), -1);
ymageToolPrint.print(networkPicture, width - 2, 8, 0, "SNAPSHOT FROM " + new Date().toString().toUpperCase(), 1);
@@ -278,7 +274,6 @@ public class plasmaGrafics {
if (linelength > outerradius) linelength = outerradius;
int dotsize = 6 + 2 * (int) (seed.getLinkCount() / 500000L);
if (dotsize > 18) dotsize = 18;
- img.setMode(ymageMatrix.MODE_SUB);
// draw dot
img.setColor(colorDot);
img.arcDot(x, y, innerradius, angle, dotsize);
@@ -295,7 +290,6 @@ public class plasmaGrafics {
if (ppm10 > 3) ppm10 = 3;
// draw a wave around crawling peers
long strength;
- img.setMode(ymageMatrix.MODE_SUB);
img.setColor("303030");
img.arcArc(x, y, innerradius, angle, dotsize + 1, dotsize + 1, 0, 360);
int waveradius = innerradius / 2;
@@ -382,11 +376,8 @@ public class plasmaGrafics {
private static void drawBannerPicture(int width, int height, String bgcolor, String textcolor, String bordercolor, String name, long links, long words, String type, int ppm, String network, long nlinks, long nwords, double nqph, long nppm, BufferedImage newLogo) {
int exprlength = 19;
-
logo = newLogo;
-
- bannerPicture = new ymageMatrix(width, height, bgcolor);
- bannerPicture.setMode(ymageMatrix.MODE_SUB);
+ bannerPicture = new ymageMatrix(width, height, ymageMatrix.MODE_SUB, bgcolor);
// draw description
bannerPicture.setColor(textcolor);
diff --git a/source/de/anomic/ymage/ymageCaptcha.java b/source/de/anomic/ymage/ymageCaptcha.java
index 1e60555c4..4e817027c 100644
--- a/source/de/anomic/ymage/ymageCaptcha.java
+++ b/source/de/anomic/ymage/ymageCaptcha.java
@@ -47,8 +47,8 @@ import javax.imageio.ImageIO;
public class ymageCaptcha extends ymageMatrix {
- public ymageCaptcha(int width, int height, String code) {
- super(width, height, SUBTRACTIVE_WHITE);
+ public ymageCaptcha(int width, int height, byte displayMode, String code) {
+ super(width, height, displayMode, SUBTRACTIVE_WHITE);
this.create(code);
}
@@ -100,7 +100,7 @@ public class ymageCaptcha extends ymageMatrix {
// go into headless awt mode
System.setProperty("java.awt.headless", "true");
- ymageCaptcha m = new ymageCaptcha(200, 70, args[1]);
+ ymageCaptcha m = new ymageCaptcha(200, 70, ymageMatrix.MODE_REPLACE, args[1]);
try {
ImageIO.write(m.getImage(), "png", new java.io.File(args[0]));
} catch (java.io.IOException e) {
diff --git a/source/de/anomic/ymage/ymageChart.java b/source/de/anomic/ymage/ymageChart.java
index 4ed4cb025..6f0e71be0 100644
--- a/source/de/anomic/ymage/ymageChart.java
+++ b/source/de/anomic/ymage/ymageChart.java
@@ -65,16 +65,16 @@ public class ymageChart extends ymageMatrix {
String[] colscale = new String[]{null,null,null,null};
String[] tablenames = new String[]{"","","",""};
- public ymageChart(int width, int height, String backgroundColor,
+ public ymageChart(int width, int height, String backgroundColor, String foregroundColor,
int leftborder, int rightborder, int topborder, int bottomborder,
String name) {
- super(width, height, backgroundColor);
+ super(width, height, ymageMatrix.MODE_REPLACE, backgroundColor);
this.leftborder = leftborder;
this.rightborder = rightborder;
this.topborder = topborder;
this.bottomborder = bottomborder;
if (name != null) {
- this.setColor("000000");
+ this.setColor(foregroundColor);
ymageToolPrint.print(this, width / 2 - name.length() * 3, 6, 0, name, -1);
}
}
@@ -155,7 +155,7 @@ public class ymageChart extends ymageMatrix {
public static void main(String[] args) {
System.setProperty("java.awt.headless", "true");
- ymageChart ip = new ymageChart(660, 240, "000010", 30, 30, 20, 20, "PEER PERFORMANCE GRAPH: PAGES/MINUTE and USED MEMORY");
+ ymageChart ip = new ymageChart(660, 240, "FFFFFF", "000000", 30, 30, 20, 20, "PEER PERFORMANCE GRAPH: PAGES/MINUTE and USED MEMORY");
ip.declareDimension(DIMENSION_BOTTOM, 60, 60, -600, "000000", "CCCCCC", "TIME/SECONDS");
//ip.declareDimension(DIMENSION_TOP, 10, 40, "000000", null, "count");
ip.declareDimension(DIMENSION_LEFT, 50, 40, 0, "008800", null , "PPM [PAGES/MINUTE]");
diff --git a/source/de/anomic/ymage/ymageDemoApplet.java b/source/de/anomic/ymage/ymageDemoApplet.java
index 05d3b4c0d..7b0a1e62c 100644
--- a/source/de/anomic/ymage/ymageDemoApplet.java
+++ b/source/de/anomic/ymage/ymageDemoApplet.java
@@ -47,7 +47,7 @@ public class ymageDemoApplet extends Applet implements Runnable {
public void update(Graphics g) {
Dimension d = getSize();
- offGraphics = new ymageMatrix(d.width, d.height, ymageMatrix.SUBTRACTIVE_WHITE);
+ offGraphics = new ymageMatrix(d.width, d.height, ymageMatrix.MODE_REPLACE, ymageMatrix.SUBTRACTIVE_WHITE);
paintFrame(offGraphics);
g.drawImage(offGraphics.getImage(), 0, 0, null);
}
diff --git a/source/de/anomic/ymage/ymageGraph.java b/source/de/anomic/ymage/ymageGraph.java
index ef0bdd4cc..1f9f93afa 100644
--- a/source/de/anomic/ymage/ymageGraph.java
+++ b/source/de/anomic/ymage/ymageGraph.java
@@ -131,10 +131,9 @@ public class ymageGraph {
private static final long color_lineend = 0x555555;
public ymageMatrix draw(int width, int height, int leftborder, int rightborder, int topborder, int bottomborder) {
- ymageMatrix image = new ymageMatrix(width, height, color_back);
+ ymageMatrix image = new ymageMatrix(width, height, ymageMatrix.MODE_SUB, color_back);
double xfactor = ((rightmost - leftmost) == 0.0) ? 0.0 : (width - leftborder - rightborder) / (rightmost - leftmost);
double yfactor = ((topmost - bottommost) == 0.0) ? 0.0 : (height - topborder - bottomborder) / (topmost - bottommost);
- image.setMode(ymageMatrix.MODE_SUB);
// draw dots and names
Iterator i = points.entrySet().iterator();
diff --git a/source/de/anomic/ymage/ymageMatrix.java b/source/de/anomic/ymage/ymageMatrix.java
index 1cf697335..1c48a9df2 100644
--- a/source/de/anomic/ymage/ymageMatrix.java
+++ b/source/de/anomic/ymage/ymageMatrix.java
@@ -64,31 +64,16 @@ public class ymageMatrix /*implements Cloneable*/ {
private int[] defaultCol;
private byte defaultMode;
- /*
- public ymageMatrix(ymageMatrix matrix) throws RuntimeException {
- if (!(serverMemory.available(1024 * 1024 + 3 * width * height, true))) throw new RuntimeException("ymage: not enough memory (" + serverMemory.available() + ") available");
- // clones the matrix
- this.width = matrix.width;
- this.height = matrix.height;
- this.defaultColR = matrix.defaultColR;
- this.defaultColG = matrix.defaultColG;
- this.defaultColB = matrix.defaultColB;
- this.defaultMode = matrix.defaultMode;
- this.grid = (WritableRaster) matrix.grid.
- System.arraycopy(matrix.grid, 0, this.grid, 0, matrix.grid.length);
- }
- */
-
- public ymageMatrix(int width, int height, String backgroundColor) {
- this(width, height, colNum(backgroundColor));
+ public ymageMatrix(int width, int height, byte drawMode, String backgroundColor) {
+ this(width, height, drawMode, colNum(backgroundColor));
}
- public ymageMatrix(int width, int height, long backgroundColor) {
+ public ymageMatrix(int width, int height, byte drawMode, long backgroundColor) {
if (!(serverMemory.request(1024 * 1024 + 3 * width * height, false))) throw new RuntimeException("ymage: not enough memory (" + serverMemory.available() + ") available");
this.width = width;
this.height = height;
this.defaultCol = new int[]{0xFF, 0xFF, 0xFF};
- this.defaultMode = MODE_REPLACE;
+ this.defaultMode = drawMode;
image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
Graphics2D gr = image.createGraphics();
@@ -96,18 +81,23 @@ public class ymageMatrix /*implements Cloneable*/ {
//gr.clearRect(0, 0, width, height);
grid = image.getRaster();
- //if (backgroundColor != SUBTRACTIVE_WHITE) {
- // fill grid with background color
- byte bgR = (byte) (0xFF - (backgroundColor >> 16));
- byte bgG = (byte) (0xFF - ((backgroundColor >> 8) & 0xff));
- byte bgB = (byte) (0xFF - (backgroundColor & 0xff));
- int[] c = new int[]{bgR, bgG, bgB};
- for (int i = 0; i < width; i++) {
- for (int j = 0; j < height; j++) {
- grid.setPixel(i, j, c);
- }
+ // fill grid with background color
+ byte bgR, bgG, bgB;
+ if (drawMode == MODE_SUB) {
+ bgR = (byte) (0xFF - (backgroundColor >> 16));
+ bgG = (byte) (0xFF - ((backgroundColor >> 8) & 0xff));
+ bgB = (byte) (0xFF - (backgroundColor & 0xff));
+ } else {
+ bgR = (byte) (backgroundColor >> 16);
+ bgG = (byte) ((backgroundColor >> 8) & 0xff);
+ bgB = (byte) (backgroundColor & 0xff);
+ }
+ int[] c = new int[]{bgR, bgG, bgB};
+ for (int i = 0; i < width; i++) {
+ for (int j = 0; j < height; j++) {
+ grid.setPixel(i, j, c);
}
- //}
+ }
}
public BufferedImage getImage() {
@@ -141,11 +131,11 @@ public class ymageMatrix /*implements Cloneable*/ {
public void setColor(String s) {
setColor(colNum(s));
}
-
+ /*
public void setMode(byte m) {
this.defaultMode = m;
}
-
+ */
public void plot(int x, int y) {
if ((x < 0) || (x >= width)) return;
if ((y < 0) || (y >= height)) return;
@@ -290,7 +280,6 @@ public class ymageMatrix /*implements Cloneable*/ {
}
public static void demoPaint(ymageMatrix m) {
- m.setMode(MODE_SUB);
m.setColor(SUBTRACTIVE_CYAN);
m.line(0, 10, 100, 10); ymageToolPrint.print(m, 0, 5, 0, "Cyan", -1);
m.line(50, 0, 50, 300);
@@ -318,7 +307,7 @@ public class ymageMatrix /*implements Cloneable*/ {
// go into headless awt mode
System.setProperty("java.awt.headless", "true");
- ymageMatrix m = new ymageMatrix(200, 300, SUBTRACTIVE_WHITE);
+ ymageMatrix m = new ymageMatrix(200, 300, MODE_SUB, SUBTRACTIVE_WHITE);
demoPaint(m);
try {
ImageIO.write(m.getImage(), "png", new java.io.File(args[0]));