count message names for statistical reasons
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Fri, 11 Apr 2008 06:35:53 +0000 (06:35 +0000)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Fri, 11 Apr 2008 06:35:53 +0000 (06:35 +0000)
git-svn-id: http://trooper/svn/projects/jSite/trunk@706 c3eda9e8-030b-0410-8277-bc7414b0a119

src/net/pterodactylus/util/fcp/FcpConnection.java

index 8ea71ee..f5629ca 100644 (file)
@@ -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<String, Integer> incomingMessageStatistics = Collections.synchronizedMap(new HashMap<String, Integer>());
+
        /**
         * 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 <cod>1</code>
+        * 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);
+       }
+
 }