mirror of
https://github.com/ChronosX88/KademliaDHT.git
synced 2024-11-24 19:22:18 +00:00
Statistician
- Returns some times in milliseconds instead of microseconds KadServer - Made a few operations synchronized - Handled the exception when the timer is already canceled
This commit is contained in:
parent
1bee79789d
commit
718fa78b9d
@ -111,11 +111,11 @@ public class Statistician
|
|||||||
/**
|
/**
|
||||||
* Compute the average time a content lookup took
|
* Compute the average time a content lookup took
|
||||||
*
|
*
|
||||||
* @return The average time
|
* @return The average time in milliseconds
|
||||||
*/
|
*/
|
||||||
public double averageContentLookupTime()
|
public double averageContentLookupTime()
|
||||||
{
|
{
|
||||||
double avg = (double) this.totalContentLookupTime / (double) this.numContentLookups;
|
double avg = (double) ((double) this.totalContentLookupTime / (double) this.numContentLookups) / 1000000D;
|
||||||
DecimalFormat df = new DecimalFormat("#.00");
|
DecimalFormat df = new DecimalFormat("#.00");
|
||||||
return new Double(df.format(avg));
|
return new Double(df.format(avg));
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,7 @@ public class DefaultConfiguration implements KadConfiguration
|
|||||||
private final static long RESPONSE_TIMEOUT = 1500;
|
private final static long RESPONSE_TIMEOUT = 1500;
|
||||||
private final static long OPERATION_TIMEOUT = 3000;
|
private final static long OPERATION_TIMEOUT = 3000;
|
||||||
private final static int CONCURRENCY = 10;
|
private final static int CONCURRENCY = 10;
|
||||||
private final static int K = 10;
|
private final static int K = 5;
|
||||||
private final static int RCSIZE = 3;
|
private final static int RCSIZE = 3;
|
||||||
private final static int STALE = 1;
|
private final static int STALE = 1;
|
||||||
private final static String LOCAL_FOLDER = "kademlia";
|
private final static String LOCAL_FOLDER = "kademlia";
|
||||||
|
@ -111,7 +111,7 @@ public class KadServer
|
|||||||
{
|
{
|
||||||
if (!isRunning)
|
if (!isRunning)
|
||||||
{
|
{
|
||||||
throw new KadServerDownException("Kad Server is not running on node " + this.localNode);
|
throw new KadServerDownException(this.localNode + " - Kad Server is not running.");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Generate a random communication ID */
|
/* Generate a random communication ID */
|
||||||
@ -120,11 +120,18 @@ public class KadServer
|
|||||||
/* If we have a receiver */
|
/* If we have a receiver */
|
||||||
if (recv != null)
|
if (recv != null)
|
||||||
{
|
{
|
||||||
/* Setup the receiver to handle message response */
|
try
|
||||||
receivers.put(comm, recv);
|
{
|
||||||
TimerTask task = new TimeoutTask(comm, recv);
|
/* Setup the receiver to handle message response */
|
||||||
timer.schedule(task, this.config.responseTimeout());
|
receivers.put(comm, recv);
|
||||||
tasks.put(comm, task);
|
TimerTask task = new TimeoutTask(comm, recv);
|
||||||
|
timer.schedule(task, this.config.responseTimeout());
|
||||||
|
tasks.put(comm, task);
|
||||||
|
}
|
||||||
|
catch (IllegalStateException ex)
|
||||||
|
{
|
||||||
|
/* The timer is already cancelled so we cannot do anything here really */
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Send the message */
|
/* Send the message */
|
||||||
@ -154,7 +161,7 @@ public class KadServer
|
|||||||
/**
|
/**
|
||||||
* Internal sendMessage method called by the public sendMessage method after a communicationId is generated
|
* Internal sendMessage method called by the public sendMessage method after a communicationId is generated
|
||||||
*/
|
*/
|
||||||
private void sendMessage(Node to, Message msg, int comm) throws IOException
|
private synchronized void sendMessage(Node to, Message msg, int comm) throws IOException
|
||||||
{
|
{
|
||||||
/* Use a try-with resource to auto-close streams after usage */
|
/* Use a try-with resource to auto-close streams after usage */
|
||||||
try (ByteArrayOutputStream bout = new ByteArrayOutputStream(); DataOutputStream dout = new DataOutputStream(bout);)
|
try (ByteArrayOutputStream bout = new ByteArrayOutputStream(); DataOutputStream dout = new DataOutputStream(bout);)
|
||||||
@ -185,7 +192,7 @@ public class KadServer
|
|||||||
/**
|
/**
|
||||||
* Listen for incoming messages in a separate thread
|
* Listen for incoming messages in a separate thread
|
||||||
*/
|
*/
|
||||||
private void listen()
|
private synchronized void listen()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -272,7 +279,7 @@ public class KadServer
|
|||||||
/**
|
/**
|
||||||
* Stops listening and shuts down the server
|
* Stops listening and shuts down the server
|
||||||
*/
|
*/
|
||||||
public void shutdown()
|
public synchronized void shutdown()
|
||||||
{
|
{
|
||||||
this.isRunning = false;
|
this.isRunning = false;
|
||||||
this.socket.close();
|
this.socket.close();
|
||||||
|
Loading…
Reference in New Issue
Block a user