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;
/** 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.
*/
void handleMessage(FcpMessage fcpMessage) {
String messageName = fcpMessage.getName();
+ countMessage(messageName);
if ("SimpleProgress".equals(messageName)) {
fireReceivedSimpleProgress(new SimpleProgress(fcpMessage));
} else if ("ProtocolError".equals(messageName)) {
}
}
+ //
+ // 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);
+ }
+
}