From 70bf6044b374b038e893682ced5d96a00eaf63b1 Mon Sep 17 00:00:00 2001 From: Joshua Kissoon Date: Wed, 7 May 2014 21:23:04 +0530 Subject: [PATCH] Added toString to statistician --- src/kademlia/Statistician.java | 33 ++++++++++++++++++++++++++++++++ src/kademlia/core/KadServer.java | 4 ++-- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/src/kademlia/Statistician.java b/src/kademlia/Statistician.java index bd4bafe..6f7311a 100644 --- a/src/kademlia/Statistician.java +++ b/src/kademlia/Statistician.java @@ -126,4 +126,37 @@ public class Statistician DecimalFormat df = new DecimalFormat("#.00"); return new Double(df.format(avg)); } + + public String toString() + { + StringBuilder sb = new StringBuilder("Statistician: ["); + + sb.append("Bootstrap Time: "); + sb.append(this.getBootstrapTime()); + sb.append("; "); + + sb.append("Data Sent: "); + sb.append(this.getTotalDataSent()); + sb.append("; "); + + sb.append("Data Received: "); + sb.append(this.getTotalDataReceived()); + sb.append("; "); + + sb.append("Num Content Lookups: "); + sb.append(this.numContentLookups()); + sb.append("; "); + + sb.append("Avg Content Lookup Time: "); + sb.append(this.averageContentLookupTime()); + sb.append("; "); + + sb.append("Avg Content Lookup Route Lth: "); + sb.append(this.averageContentLookupRouteLength()); + sb.append("; "); + + sb.append("]"); + + return sb.toString(); + } } diff --git a/src/kademlia/core/KadServer.java b/src/kademlia/core/KadServer.java index 7906ff6..8afd3e9 100644 --- a/src/kademlia/core/KadServer.java +++ b/src/kademlia/core/KadServer.java @@ -161,7 +161,7 @@ public class KadServer /** * Internal sendMessage method called by the public sendMessage method after a communicationId is generated */ - private synchronized void sendMessage(Node to, Message msg, int comm) throws IOException + private void sendMessage(Node to, Message msg, int comm) throws IOException { /* Use a try-with resource to auto-close streams after usage */ try (ByteArrayOutputStream bout = new ByteArrayOutputStream(); DataOutputStream dout = new DataOutputStream(bout);) @@ -192,7 +192,7 @@ public class KadServer /** * Listen for incoming messages in a separate thread */ - private synchronized void listen() + private void listen() { try {