Removed the Save_state decision from configuration and allow the user to specify if to save the state when they call shutdown

This commit is contained in:
Joshua Kissoon 2014-03-26 16:23:17 +05:30
parent 46b8c1329a
commit 426af4d345
3 changed files with 6 additions and 9 deletions

View File

@ -53,9 +53,4 @@ public class Configuration
* Local Storage location - Relative to the user's home folder (Cross-Platform)
*/
public static String LOCAL_FOLDER = "kademlia";
/**
* Should we save the node state when the node is shut down and reload it when the node is re-loaded
*/
public static boolean SAVE_STATE_ON_SHUTDOWN = true;
}

View File

@ -282,15 +282,17 @@ public class Kademlia
/**
* Here we handle properly shutting down the Kademlia instance
*
* @param saveState Whether to save the application state or not
*
* @throws java.io.FileNotFoundException
*/
public void shutdown() throws FileNotFoundException, IOException
public void shutdown(final boolean saveState) throws IOException
{
/* Shut down the server */
this.server.shutdown();
/* Save this Kademlia instance's state if required */
if (Configuration.SAVE_STATE_ON_SHUTDOWN)
if (saveState)
{
/* Save the system state */
this.saveKadState();
@ -302,7 +304,7 @@ public class Kademlia
*
* @throws java.io.FileNotFoundException
*/
private void saveKadState() throws FileNotFoundException, IOException
private void saveKadState() throws IOException
{
DataOutputStream dout;

View File

@ -73,7 +73,7 @@ public class SaveStateTest
/* Shutting down kad1 and restarting it */
System.out.println("\n\n\nShutting down Kad instance");
System.out.println(kad2);
kad1.shutdown();
kad1.shutdown(true);
System.out.println("\n\n\nReloading Kad instance from file");
Kademlia kadR2 = Kademlia.loadFromFile("JoshuaK");