From: David ‘Bombe’ Roden Date: Fri, 11 Apr 2008 06:35:53 +0000 (+0000) Subject: count message names for statistical reasons X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=5c3d23ad2d5f3567b283e7e86ca55787033cbc0f;p=jSite2.git count message names for statistical reasons git-svn-id: http://trooper/svn/projects/jSite/trunk@706 c3eda9e8-030b-0410-8277-bc7414b0a119 --- diff --git a/src/net/pterodactylus/util/fcp/FcpConnection.java b/src/net/pterodactylus/util/fcp/FcpConnection.java index 8ea71ee..f5629ca 100644 --- a/src/net/pterodactylus/util/fcp/FcpConnection.java +++ b/src/net/pterodactylus/util/fcp/FcpConnection.java @@ -26,7 +26,10 @@ import java.net.InetAddress; import java.net.Socket; import java.net.UnknownHostException; import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; import java.util.List; +import java.util.Map; import net.pterodactylus.util.io.Closer; import net.pterodactylus.util.io.LimitedInputStream; @@ -63,6 +66,9 @@ public class FcpConnection { /** The connection handler. */ private FcpConnectionHandler connectionHandler; + /** Incoming message statistics. */ + private Map incomingMessageStatistics = Collections.synchronizedMap(new HashMap()); + /** * Creates a new FCP connection to the Freenet node running on the given * host, listening on the default port. @@ -457,6 +463,7 @@ public class FcpConnection { */ void handleMessage(FcpMessage fcpMessage) { String messageName = fcpMessage.getName(); + countMessage(messageName); if ("SimpleProgress".equals(messageName)) { fireReceivedSimpleProgress(new SimpleProgress(fcpMessage)); } else if ("ProtocolError".equals(messageName)) { @@ -513,4 +520,23 @@ public class FcpConnection { } } + // + // PRIVATE METHODS + // + + /** + * Incremets the counter in {@link #incomingMessageStatistics} by 1 + * for the given message name. + * + * @param name + * The name of the message to count + */ + private void countMessage(String name) { + int oldValue = 0; + if (incomingMessageStatistics.containsKey(name)) { + oldValue = incomingMessageStatistics.get(name); + } + incomingMessageStatistics.put(name, oldValue + 1); + } + }