mirror of
https://github.com/ChronosX88/KademliaDHT.git
synced 2024-11-22 02:02:21 +00:00
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:
parent
7817100253
commit
899390b4a3
@ -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;
|
||||
}
|
||||
@ -122,7 +130,7 @@ public class KademliaNode
|
||||
};
|
||||
refreshOperationTimer.schedule(refreshOperationTTask, this.config.restoreInterval(), this.config.restoreInterval());
|
||||
}
|
||||
|
||||
|
||||
public final void stopRefreshOperation()
|
||||
{
|
||||
/* Close off the timer tasks */
|
||||
|
@ -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 */
|
@ -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;
|
||||
@ -57,22 +60,21 @@ public class KadServer
|
||||
/**
|
||||
* Initialize our KadServer
|
||||
*
|
||||
* @param udpPort The port to listen on
|
||||
* @param mFactory Factory used to create messages
|
||||
* @param localNode Local node on which this server runs on
|
||||
* @param udpPort The port to listen on
|
||||
* @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();
|
||||
@ -192,7 +194,7 @@ public class KadServer
|
||||
byte[] buffer = new byte[DATAGRAM_BUFFER_SIZE];
|
||||
DatagramPacket packet = new DatagramPacket(buffer, buffer.length);
|
||||
socket.receive(packet);
|
||||
|
||||
|
||||
//Statistics.dataReceived += packet.getLength();
|
||||
//System.out.println("Received packet of size: " + packet.getLength());
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user