Allow to forceSave conf files

This commit is contained in:
snowleo 2013-04-23 00:47:45 +02:00
parent 2588e20140
commit 9160410a50
3 changed files with 35 additions and 6 deletions

View File

@ -9,8 +9,10 @@ import java.nio.charset.Charset;
import java.nio.charset.CharsetDecoder;
import java.nio.charset.CoderResult;
import java.util.*;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.logging.Level;
import java.util.logging.Logger;
@ -249,6 +251,31 @@ public class EssentialsConf extends YamlConfiguration
@Override
public synchronized void save(final File file) throws IOException
{
delayedSave(file);
}
public synchronized void forceSave()
{
try
{
Future<?> future = delayedSave(configFile);
if (future != null)
{
future.get();
}
}
catch (InterruptedException ex)
{
LOGGER.log(Level.SEVERE, ex.getMessage(), ex);
}
catch (ExecutionException ex)
{
LOGGER.log(Level.SEVERE, ex.getMessage(), ex);
}
}
private Future<?> delayedSave(final File file)
{
//long startTime = System.nanoTime();
if (file == null)
@ -260,14 +287,16 @@ public class EssentialsConf extends YamlConfiguration
if (data.length() == 0)
{
return;
return null;
}
pendingDiskWrites.incrementAndGet();
EXECUTOR_SERVICE.submit(new WriteRunner(configFile, data, pendingDiskWrites));
Future<?> future = EXECUTOR_SERVICE.submit(new WriteRunner(configFile, data, pendingDiskWrites));
//LOGGER.log(Level.INFO, configFile + " prepared for writing in " + (System.nanoTime() - startTime) + " nsec.");
return future;
}

View File

@ -230,7 +230,7 @@ public class EssentialsUpgrade
config.removeProperty("home");
config.setProperty("home.default", worldName);
config.setProperty("home.worlds." + worldName, loc);
config.save();
config.forceSave();
}
}
}
@ -285,7 +285,7 @@ public class EssentialsUpgrade
((Map<String, Object>)powertools).put(entry.getKey(), temp);
}
}
config.save();
config.forceSave();
}
}
catch (RuntimeException ex)
@ -358,7 +358,7 @@ public class EssentialsUpgrade
}
}
config.removeProperty("home");
config.save();
config.forceSave();
}
}

View File

@ -42,7 +42,7 @@ public final class Economy
npcConfig.load();
npcConfig.setProperty("npc", true);
npcConfig.setProperty("money", ess.getSettings().getStartingBalance());
npcConfig.save();
npcConfig.forceSave();
}
private static void deleteNPC(String name)