final long communicationTimeout,
final String networkName, final String networkTitle, final String color_back,
final int cyc) {
final RasterPlotter.DrawMode drawMode = (RasterPlotter.darkColor(color_back)) ? RasterPlotter.DrawMode.MODE_ADD : RasterPlotter.DrawMode.MODE_SUB;
final RasterPlotter networkPicture = new RasterPlotter(width, height, drawMode, color_back);
if (seedDB == null) return networkPicture; // no other peers known
final int maxradius = Math.min(width, height) / 2;
final int innerradius = maxradius * 4 / 10;
final int outerradius = maxradius - 20;
// draw network circle
networkPicture.setColor(COL_DHTCIRCLE);
networkPicture.arc(width / 2, height / 2, innerradius - 20, innerradius + 20, 100);
//System.out.println("Seed Maximum distance is " + yacySeed.maxDHTDistance);
//System.out.println("Seed Minimum distance is " + yacySeed.minDHTNumber);
Seed seed;
long lastseen;
// start processes that actually draw the peers
//final BlockingQueue<drawNetworkPicturePeerJob> drawQueue = new LinkedBlockingDeque<drawNetworkPicturePeerJob>();
//final drawNetworkPicturePeerJob poison = new drawNetworkPicturePeerJob();
/*
final Thread[] drawThreads = new Thread[Runtime.getRuntime().availableProcessors()];
for (int i = 0; i < drawThreads.length; i++) {
drawThreads[i] = new Thread() {
public void run() {
try {
drawNetworkPicturePeerJob job;
while ((job = drawQueue.take()) != poison) job.draw();
} catch (final InterruptedException e) {
}
}
};
drawThreads[i].start();
}
*/
// draw connected senior and principals
int count = 0;
int totalCount = 0;
Iterator<Seed> e = seedDB.seedsConnected(true, false, null, (float) 0.0);
while (e.hasNext() && count < maxCount) {
seed = e.next();
if (seed == null) {
Log.logWarning("NetworkGraph", "connected seed == null");
continue;
}
if (seed.hash.startsWith("AD")) {//temporary patch
continue;
}
//Log.logInfo("NetworkGraph", "drawing peer " + seed.getName());
new drawNetworkPicturePeerJob(networkPicture, width / 2, height / 2, innerradius, outerradius, seed, COL_ACTIVE_DOT, COL_ACTIVE_LINE, COL_ACTIVE_TEXT, coronaangle, cyc).draw();
count++;
}
totalCount += count;
// draw disconnected senior and principals that have been seen lately
count = 0;
e = seedDB.seedsSortedDisconnected(false, Seed.LASTSEEN);
while (e.hasNext() && count < maxCount) {
seed = e.next();
if (seed == null) {
Log.logWarning("NetworkGraph", "disconnected seed == null");
continue;
}
lastseen = Math.abs((System.currentTimeMillis() - seed.getLastSeenUTC()) / 1000 / 60);
if (lastseen > passiveLimit) {
break; // we have enough, this list is sorted so we don't miss anything
}
new drawNetworkPicturePeerJob(networkPicture, width / 2, height / 2, innerradius, outerradius, seed, COL_PASSIVE_DOT, COL_PASSIVE_LINE, COL_PASSIVE_TEXT, coronaangle, cyc).draw();
count++;
}
totalCount += count;
// draw juniors that have been seen lately
count = 0;
e = seedDB.seedsSortedPotential(false, Seed.LASTSEEN);
while (e.hasNext() && count < maxCount) {
seed = e.next();
if (seed == null) {
Log.logWarning("NetworkGraph", "potential seed == null");
continue;
}
lastseen = Math.abs((System.currentTimeMillis() - seed.getLastSeenUTC()) / 1000 / 60);
if (lastseen > potentialLimit) {
break; // we have enough, this list is sorted so we don't miss anything
}
new drawNetworkPicturePeerJob(networkPicture, width / 2, height / 2, innerradius, outerradius, seed, COL_POTENTIAL_DOT, COL_POTENTIAL_LINE, COL_POTENTIAL_TEXT, coronaangle, cyc).draw();
count++;
}
totalCount += count;
// draw my own peer
new drawNetworkPicturePeerJob(networkPicture, width / 2, height / 2, innerradius, outerradius, seedDB.mySeed(), COL_MYPEER_DOT, COL_MYPEER_LINE, COL_MYPEER_TEXT, coronaangle, cyc).draw();
// signal termination
//for (@SuppressWarnings("unused") final Thread t: drawThreads) try { drawQueue.put(poison); } catch (final InterruptedException ee) {}
// draw DHT activity
if (communicationTimeout >= 0) {
final Date horizon = new Date(System.currentTimeMillis() - communicationTimeout);
for (final Hit event: EventChannel.channels(EventChannel.DHTRECEIVE)) {
if (event == null || event.getPubDate() == null) continue;
if (event.getPubDate().after(horizon)) {
//System.out.println("*** NETWORK-DHTRECEIVE: " + event.getLink());
drawNetworkPictureDHT(networkPicture, width / 2, height / 2, innerradius, seedDB.mySeed(), seedDB.get(event.getLink()), COL_DHTIN, coronaangle, false, cyc);
}
}
for (final Hit event: EventChannel.channels(EventChannel.DHTSEND)) {
if (event == null || event.getPubDate() == null) continue;
if (event.getPubDate().after(horizon)) {
//System.out.println("*** NETWORK-DHTSEND: " + event.getLink());
drawNetworkPictureDHT(networkPicture, width / 2, height / 2, innerradius, seedDB.mySeed(), seedDB.get(event.getLink()), COL_DHTOUT, coronaangle, true, cyc);
}
}
}
// draw description
networkPicture.setColor(COL_HEADLINE);
PrintTool.print(networkPicture, 2, 6, 0, "YACY NETWORK '" + networkName.toUpperCase() + "'", -1);
PrintTool.print(networkPicture, 2, 14, 0, networkTitle.toUpperCase(), -1);
PrintTool.print(networkPicture, width - 2, 6, 0, "SNAPSHOT FROM " + new Date().toString().toUpperCase(), 1);
PrintTool.print(networkPicture, width - 2, 14, 0, "DRAWING OF " + totalCount + " SELECTED PEERS", 1);