better resistance of NetworkImage generation against heavy load

this is needed for the network image on the yacy.net home page

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

@ -24,6 +24,8 @@
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
import java.util.concurrent.Semaphore;
import de.anomic.http.server.RequestHeader;
import de.anomic.search.Switchboard;
import de.anomic.search.SwitchboardConstants;
@ -35,7 +37,7 @@ import de.anomic.yacy.graphics.NetworkGraph;
/** draw a picture of the yacy network */
public class NetworkPicture {
private static final Object sync = new Object();
private static final Semaphore sync = new Semaphore(1);
private static EncodedImage buffer = null;
private static long lastAccessSeconds = 0;
@ -48,7 +50,9 @@ public class NetworkPicture {
//System.out.println("*** NetworkPicture: cache hit (1)");
return buffer;
}
synchronized (sync) {
if (buffer != null && sync.availablePermits() == 0) return buffer;
try {
sync.acquire();
if (buffer != null && !authorized && timeSeconds - lastAccessSeconds < 2) {
//System.out.println("*** NetworkPicture: cache hit (2)");
return buffer;
@ -89,6 +93,9 @@ public class NetworkPicture {
if (maxCount > 10000) maxCount = 10000;
buffer = 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");
lastAccessSeconds = System.currentTimeMillis() / 1000;
sync.release();
} catch (InterruptedException e) {
if (sync.availablePermits() == 0) sync.release();
}
return buffer;
}

Loading…
Cancel
Save