mirror of
https://github.com/ChronosX88/KademliaDHT.git
synced 2024-12-23 08:11:47 +00:00
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:
parent
46b8c1329a
commit
426af4d345
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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");
|
||||
|
Loading…
Reference in New Issue
Block a user