From 78171002530edbd074519e5a64d5fa8982de038d Mon Sep 17 00:00:00 2001 From: Joshua Kissoon Date: Tue, 6 May 2014 09:13:16 +0530 Subject: [PATCH] Statistics - Started working on a statistics class to collect Kad statistics --- src/kademlia/Statistics.java | 49 +++++++++++++++++++++++++++++--- src/kademlia/core/KadServer.java | 5 +--- 2 files changed, 46 insertions(+), 8 deletions(-) diff --git a/src/kademlia/Statistics.java b/src/kademlia/Statistics.java index dbdd6b9..c76ac3e 100644 --- a/src/kademlia/Statistics.java +++ b/src/kademlia/Statistics.java @@ -1,7 +1,9 @@ package kademlia; /** - * Class that keeps statistics for a single run + * Class that keeps statistics for this Kademlia instance. + * + * These statistics are temporary and will be lost when Kad is shut down. * * @author Joshua Kissoon * @since 20140505 @@ -9,9 +11,48 @@ package kademlia; public class Statistics { + /* How much data was sent and received by the server over the network */ + private long totalDataSent, totalDataReceived; + + + { + this.totalDataSent = 0; + this.totalDataReceived = 0; + } + /** - * How much data was sent and received by the server over the network + * Used to indicate some data is sent + * + * @param size The size of the data sent */ - public static long dataSent = 0; - public static long dataReceived = 0; + public void sentData(long size) + { + this.totalDataSent += size; + } + + /** + * @return The total data sent + */ + public long getTotalDataSent() + { + return this.totalDataSent; + } + + /** + * Used to indicate some data was received + * + * @param size The size of the data received + */ + public void receivedData(long size) + { + this.totalDataReceived += size; + } + + /** + * @return The total data received + */ + public long getTotalDataReceived() + { + return this.totalDataReceived; + } } diff --git a/src/kademlia/core/KadServer.java b/src/kademlia/core/KadServer.java index 7fb8da2..5dfa4af 100644 --- a/src/kademlia/core/KadServer.java +++ b/src/kademlia/core/KadServer.java @@ -13,7 +13,6 @@ import java.util.Map; import java.util.Random; import java.util.Timer; import java.util.TimerTask; -import kademlia.Statistics; import kademlia.exceptions.KadServerDownException; import kademlia.message.Message; import kademlia.message.MessageFactory; @@ -36,7 +35,6 @@ public class KadServer private final transient KadConfiguration config; /* Server Objects */ - private final int udpPort; private final DatagramSocket socket; private transient boolean isRunning; private final Map receivers; @@ -68,7 +66,6 @@ public class KadServer */ public KadServer(int udpPort, MessageFactory mFactory, Node localNode, KadConfiguration config) throws SocketException { - this.udpPort = udpPort; this.config = config; this.socket = new DatagramSocket(udpPort); @@ -196,7 +193,7 @@ public class KadServer DatagramPacket packet = new DatagramPacket(buffer, buffer.length); socket.receive(packet); - Statistics.dataReceived += packet.getLength(); + //Statistics.dataReceived += packet.getLength(); //System.out.println("Received packet of size: " + packet.getLength()); /* We've received a packet, now handle it */