diff options
author | snowleo <schneeleo@gmail.com> | 2013-04-23 00:47:45 +0200 |
---|---|---|
committer | snowleo <schneeleo@gmail.com> | 2013-04-23 00:47:45 +0200 |
commit | 1b6f1a88db761518dc8a50049ad086d04af8ef30 (patch) | |
tree | 3f6f33c2961c480a5fa5a392758fe9e41b3daf9a | |
parent | 9b821545fde9b5a4e3e1f3ef3d83b32bf2a5e09a (diff) | |
download | Essentials-1b6f1a88db761518dc8a50049ad086d04af8ef30.tar Essentials-1b6f1a88db761518dc8a50049ad086d04af8ef30.tar.gz Essentials-1b6f1a88db761518dc8a50049ad086d04af8ef30.tar.lz Essentials-1b6f1a88db761518dc8a50049ad086d04af8ef30.tar.xz Essentials-1b6f1a88db761518dc8a50049ad086d04af8ef30.zip |
Allow to forceSave conf files
3 files changed, 35 insertions, 6 deletions
diff --git a/Essentials/src/com/earth2me/essentials/EssentialsConf.java b/Essentials/src/com/earth2me/essentials/EssentialsConf.java index 8f0c69dd6..26f9d1c9d 100644 --- a/Essentials/src/com/earth2me/essentials/EssentialsConf.java +++ b/Essentials/src/com/earth2me/essentials/EssentialsConf.java @@ -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; @@ -250,6 +252,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; } diff --git a/Essentials/src/com/earth2me/essentials/EssentialsUpgrade.java b/Essentials/src/com/earth2me/essentials/EssentialsUpgrade.java index 384e15603..60b23a8c8 100644 --- a/Essentials/src/com/earth2me/essentials/EssentialsUpgrade.java +++ b/Essentials/src/com/earth2me/essentials/EssentialsUpgrade.java @@ -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(); } } diff --git a/Essentials/src/com/earth2me/essentials/api/Economy.java b/Essentials/src/com/earth2me/essentials/api/Economy.java index 579afd4d1..c22145a13 100644 --- a/Essentials/src/com/earth2me/essentials/api/Economy.java +++ b/Essentials/src/com/earth2me/essentials/api/Economy.java @@ -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) |