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 */
private final transient MessageFactory messageFactory;
/* Statistics */
private final Statistician statistician;
{
statistician = new Statistician();
}
/**
* Creates a Kademlia DistributedMap using the specified name as filename base.
* If the id cannot be read from disk the specified defaultId is used.
@ -93,7 +101,7 @@ public class KademliaNode
this.config = config;
this.routingTable = routingTable;
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.isRunning = true;
}

View File

@ -8,7 +8,7 @@ package kademlia;
* @author Joshua Kissoon
* @since 20140505
*/
public class Statistics
public class Statistician
{
/* 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.Timer;
import java.util.TimerTask;
import kademlia.Statistician;
import kademlia.exceptions.KadServerDownException;
import kademlia.message.Message;
import kademlia.message.MessageFactory;
@ -46,6 +47,8 @@ public class KadServer
/* Factories */
private final MessageFactory messageFactory;
private final Statistician statistician;
{
isRunning = true;
@ -61,18 +64,17 @@ public class KadServer
* @param mFactory Factory used to create messages
* @param localNode Local node on which this server runs on
* @param config
* @param statistician A statistician to manage the server statistics
*
* @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.socket = new DatagramSocket(udpPort);
this.localNode = localNode;
this.messageFactory = mFactory;
this.statistician = statistician;
/* Start listening for incoming requests in a new thread */
this.startListener();