Had some issues with saving node state since saving configuration had a problem. We do not need to save configuration! Fixed the bug by making the configuration transient

This commit is contained in:
Joshua Kissoon 2014-03-31 22:50:57 +05:30
parent b1ab1be760
commit 1995682992
6 changed files with 18 additions and 10 deletions

View File

@ -39,8 +39,8 @@ javac.compilerargs=
javac.deprecation=false
javac.processorpath=\
${javac.classpath}
javac.source=1.7
javac.target=1.7
javac.source=1.8
javac.target=1.8
javac.test.classpath=\
${javac.classpath}:\
${build.classes.dir}

View File

@ -61,7 +61,7 @@ public class Kademlia
private final transient DHT dht;
private final transient Timer timer;
private final int udpPort;
private KadConfiguration config;
private transient KadConfiguration config;
/* Factories */
private final transient MessageFactory messageFactory;
@ -123,7 +123,8 @@ public class Kademlia
public Kademlia(String ownerId, NodeId defaultId, int udpPort) throws IOException
{
this(ownerId, new Node(defaultId, InetAddress.getLocalHost(), udpPort), udpPort, new DHT(ownerId, new DefaultConfiguration()), new DefaultConfiguration());
this(ownerId, new Node(defaultId, InetAddress.getLocalHost(), udpPort), udpPort,
new DHT(ownerId, new DefaultConfiguration()), new DefaultConfiguration());
}
/**
@ -185,7 +186,7 @@ public class Kademlia
din = new DataInputStream(new FileInputStream(getStateStorageFolderName(ownerId, iconfig) + File.separator + "dht.kns"));
DHT idht = new JsonDHTSerializer().read(din);
return new Kademlia(ownerId, inode, ikad.getPort(), idht, ikad.getCurrentConfiguration());
return new Kademlia(ownerId, inode, ikad.getPort(), idht, iconfig);
}
/**

View File

@ -19,6 +19,14 @@ public class DefaultConfiguration implements KadConfiguration
private final static int STALE = 1;
private final static String LOCAL_FOLDER = "kademlia";
/**
* Default constructor to support Gson Serialization
*/
public DefaultConfiguration()
{
}
@Override
public long restoreInterval()
{

View File

@ -8,7 +8,7 @@ package kademlia.core;
*/
public interface KadConfiguration
{
/**
* @return Interval in milliseconds between execution of RestoreOperations.
*/

View File

@ -31,7 +31,7 @@ public class KadServer
private static final int DATAGRAM_BUFFER_SIZE = 64 * 1024; // 64KB
/* Basic Kad Objects */
private final KadConfiguration config;
private final transient KadConfiguration config;
/* Server Objects */
private final int udpPort;

View File

@ -9,7 +9,6 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.util.List;
import java.util.NoSuchElementException;
import kademlia.core.DefaultConfiguration;
import kademlia.core.GetParameter;
import kademlia.core.KadConfiguration;
import kademlia.exceptions.ContentExistException;
@ -27,8 +26,8 @@ public class DHT
{
private transient StorageEntryManager entriesManager;
private transient final JsonSerializer<KadContent> contentSerializer;
private final KadConfiguration config;
private final transient JsonSerializer<KadContent> contentSerializer;
private final transient KadConfiguration config;
private final String ownerId;