Statistics

- Renamed the statistics class to Statistician since that's is what it is - a statistician that manages the Kad statistics
- Passed the statistician to our Server to collect data
This commit is contained in:
Joshua Kissoon 2014-05-06 09:21:34 +05:30
parent 7817100253
commit 899390b4a3
3 changed files with 21 additions and 11 deletions

View File

@ -67,6 +67,14 @@ public class KademliaNode
/* Factories */ /* Factories */
private final transient MessageFactory messageFactory; private final transient MessageFactory messageFactory;
/* Statistics */
private final Statistician statistician;
{
statistician = new Statistician();
}
/** /**
* Creates a Kademlia DistributedMap using the specified name as filename base. * Creates a Kademlia DistributedMap using the specified name as filename base.
* If the id cannot be read from disk the specified defaultId is used. * If the id cannot be read from disk the specified defaultId is used.
@ -93,7 +101,7 @@ public class KademliaNode
this.config = config; this.config = config;
this.routingTable = routingTable; this.routingTable = routingTable;
this.messageFactory = new MessageFactory(this, this.dht, this.config); this.messageFactory = new MessageFactory(this, this.dht, this.config);
this.server = new KadServer(udpPort, this.messageFactory, this.localNode, this.config); this.server = new KadServer(udpPort, this.messageFactory, this.localNode, this.config, this.statistician);
this.startRefreshOperation(); this.startRefreshOperation();
this.isRunning = true; this.isRunning = true;
} }

View File

@ -8,7 +8,7 @@ package kademlia;
* @author Joshua Kissoon * @author Joshua Kissoon
* @since 20140505 * @since 20140505
*/ */
public class Statistics public class Statistician
{ {
/* How much data was sent and received by the server over the network */ /* How much data was sent and received by the server over the network */

View File

@ -13,6 +13,7 @@ import java.util.Map;
import java.util.Random; import java.util.Random;
import java.util.Timer; import java.util.Timer;
import java.util.TimerTask; import java.util.TimerTask;
import kademlia.Statistician;
import kademlia.exceptions.KadServerDownException; import kademlia.exceptions.KadServerDownException;
import kademlia.message.Message; import kademlia.message.Message;
import kademlia.message.MessageFactory; import kademlia.message.MessageFactory;
@ -46,6 +47,8 @@ public class KadServer
/* Factories */ /* Factories */
private final MessageFactory messageFactory; private final MessageFactory messageFactory;
private final Statistician statistician;
{ {
isRunning = true; isRunning = true;
@ -57,22 +60,21 @@ public class KadServer
/** /**
* Initialize our KadServer * Initialize our KadServer
* *
* @param udpPort The port to listen on * @param udpPort The port to listen on
* @param mFactory Factory used to create messages * @param mFactory Factory used to create messages
* @param localNode Local node on which this server runs on * @param localNode Local node on which this server runs on
* @param config * @param config
* @param statistician A statistician to manage the server statistics
* *
* @throws java.net.SocketException * @throws java.net.SocketException
*/ */
public KadServer(int udpPort, MessageFactory mFactory, Node localNode, KadConfiguration config) throws SocketException public KadServer(int udpPort, MessageFactory mFactory, Node localNode, KadConfiguration config, Statistician statistician) throws SocketException
{ {
this.config = config; this.config = config;
this.socket = new DatagramSocket(udpPort); this.socket = new DatagramSocket(udpPort);
this.localNode = localNode; this.localNode = localNode;
this.messageFactory = mFactory; this.messageFactory = mFactory;
this.statistician = statistician;
/* Start listening for incoming requests in a new thread */ /* Start listening for incoming requests in a new thread */
this.startListener(); this.startListener();