Statistics

- Started working on a statistics class to collect Kad statistics
This commit is contained in:
Joshua Kissoon 2014-05-06 09:13:16 +05:30
parent 8aecda34c7
commit 7817100253
2 changed files with 46 additions and 8 deletions

View File

@ -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
*/
public static long dataSent = 0;
public static long dataReceived = 0;
/* How much data was sent and received by the server over the network */
private long totalDataSent, totalDataReceived;
{
this.totalDataSent = 0;
this.totalDataReceived = 0;
}
/**
* Used to indicate some data is sent
*
* @param size The size of the data sent
*/
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;
}
}

View File

@ -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<Integer, Receiver> 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 */