yacy_search_server/htroot/PeerLoadPicture.java
orbiter 1d8d51075c refactoring:
- removed the plasma package. The name of that package came from a very early pre-version of YaCy, even before YaCy was named AnomicHTTPProxy. The Proxy project introduced search for cache contents using class files that had been developed during the plasma project. Information from 2002 about plasma can be found here:
http://web.archive.org/web/20020802110827/http://anomic.de/AnomicPlasma/index.html
We stil have one class that comes mostly unchanged from the plasma project, the Condenser class. But this is now part of the document package and all other classes in the plasma package can be assigned to other packages.
- cleaned up the http package: better structure of that class and clean isolation of server and client classes. The old HTCache becomes part of the client sub-package of http.
- because the plasmaSwitchboard is now part of the search package all servlets had to be touched to declare a different package source.

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@6232 6c8d7289-2bf4-0310-a012-ef5d649a1542
2009-07-19 20:37:44 +00:00

87 lines
3.3 KiB
Java

import java.awt.Color;
import java.awt.Image;
import java.util.HashMap;
import java.util.Iterator;
import de.anomic.http.metadata.RequestHeader;
import de.anomic.search.SwitchboardConstants;
import de.anomic.server.serverBusyThread;
import de.anomic.server.serverObjects;
import de.anomic.server.serverSwitch;
import de.anomic.ymage.NetworkGraph;
import de.anomic.ymage.NetworkGraph.CircleThreadPiece;
public class PeerLoadPicture {
public static Image respond(final RequestHeader header, final serverObjects post, final serverSwitch env) {
int width = 800;
int height = 600;
boolean showidle = true;
if (post != null) {
width = post.getInt("width", 800);
height = post.getInt("height", 600);
showidle = post.get("showidle", "true").equals("true");
}
final CircleThreadPiece idle = new CircleThreadPiece("Idle", new Color(170, 255, 170));
final CircleThreadPiece misc = new CircleThreadPiece("Misc.", new Color(190, 50, 180));
final HashMap<String, CircleThreadPiece> pieces = new HashMap<String, CircleThreadPiece>();
pieces.put(null, idle);
pieces.put(SwitchboardConstants.INDEX_DIST, new CircleThreadPiece("DHT-Distribution", new Color(119, 136, 153)));
pieces.put(SwitchboardConstants.PEER_PING, new CircleThreadPiece("YaCy Core", new Color(255, 230, 160)));
final Iterator<String> threads = env.threadNames();
String threadname;
serverBusyThread thread;
long busy_time = 0;
//Iterate over threads
while (threads.hasNext()) {
threadname = threads.next();
thread = env.getThread(threadname);
//count total times
busy_time += thread.getBlockTime();
busy_time += thread.getExecTime();
if (showidle) idle.addExecTime(thread.getSleepTime());
//count threadgroup-specific times
final CircleThreadPiece piece = pieces.get(threadname);
if (piece == null) {
misc.addExecTime(thread.getBlockTime()+thread.getExecTime());
} else {
piece.addExecTime(thread.getBlockTime()+thread.getExecTime());
}
}
busy_time += idle.getExecTime();
// set respective angles
final Iterator<CircleThreadPiece> it = pieces.values().iterator();
CircleThreadPiece current;
while (it.hasNext()) {
current = it.next();
current.setFraction(busy_time);
//remove unneccessary elements
if(current.getAngle() == 0) it.remove();
}
misc.setFraction(busy_time);
// too small values lead to an error, too big to huge CPU/memory consumption,
// resulting in possible DOS.
if (width < 40) width = 40;
if (width > 1920) width = 1920;
if (height < 30) height = 30;
if (height > 1440) height = 1440;
return NetworkGraph.getPeerLoadPicture(
5000,
width,
height,
pieces.values().toArray(new CircleThreadPiece[pieces.size()]),
misc
);
}
}