From 9275b9b4a5d6dc9f286f13510a45494d8442e8a5 Mon Sep 17 00:00:00 2001 From: Jascha Starke Date: Tue, 1 Oct 2013 16:58:01 +0200 Subject: [PATCH] Module reload fix, Better Thread-Performance-Warning --- .../minecraft/limitedcreative/Config.java | 18 ++---------------- .../limitedcreative/LimitedCreative.java | 3 +-- .../blockstate/BlockStateConfig.java | 2 +- .../blockstate/thread/ThreadLink.java | 17 ++++++++++++++--- .../cmdblocker/CmdBlockerConfig.java | 2 +- .../limitedcreative/gmperm/GMPermConfig.java | 2 +- .../inventories/InventoryConfig.java | 2 +- .../limitedcreative/limits/LimitConfig.java | 2 +- .../limitedcreative/regions/RegionConfig.java | 2 +- 9 files changed, 23 insertions(+), 27 deletions(-) diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/Config.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/Config.java index ea72555..4875bff 100644 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/Config.java +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/Config.java @@ -1,7 +1,5 @@ package de.jaschastarke.minecraft.limitedcreative; -import org.bukkit.configuration.ConfigurationSection; - import de.jaschastarke.bukkit.lib.Core; import de.jaschastarke.bukkit.lib.configuration.ConfigurationContainer; import de.jaschastarke.bukkit.lib.configuration.PluginConfiguration; @@ -31,25 +29,13 @@ public class Config extends PluginConfiguration { super(plugin); } - @Override - public void setValues(ConfigurationSection sect) { - super.setValues(sect); - - if (plugin.getModules().count() > 0) - setModuleStates(); - } - - public void setModuleStates() { - ModuleEntry metricsEntry = plugin.getModule(FeatureMetrics.class).getModuleEntry(); - metricsEntry.setEnabled(getMetrics()); - } - @Override public void setValue(IConfigurationNode node, Object pValue) throws InvalidValueException { super.setValue(node, pValue); if (node.getName().equals("metrics")) { - setModuleStates(); + ModuleEntry metricsEntry = plugin.getModule(FeatureMetrics.class).getModuleEntry(); + metricsEntry.setEnabled(getMetrics()); } } diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/LimitedCreative.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/LimitedCreative.java index 8480faa..3854d27 100644 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/LimitedCreative.java +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/LimitedCreative.java @@ -35,11 +35,10 @@ public class LimitedCreative extends Core { addModule(new ModCmdBlocker(this)); addModule(new ModGameModePerm(this)); addModule(new ModBlockStates(this)); - addModule(new FeatureMetrics(this)); + addModule(new FeatureMetrics(this)).setDefaultEnabled(config.getMetrics()); listeners.addListener(new DependencyListener(this)); - config.setModuleStates(); config.saveDefault(); try { diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/BlockStateConfig.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/BlockStateConfig.java index dda499f..3fa76ce 100644 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/BlockStateConfig.java +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/BlockStateConfig.java @@ -56,7 +56,7 @@ public class BlockStateConfig extends Configuration implements IConfigurationSub @Override public void setValues(ConfigurationSection sect) { super.setValues(sect); - entry.setEnabled(getEnabled()); + entry.setDefaultEnabled(getEnabled()); } @Override public String getName() { diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/thread/ThreadLink.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/thread/ThreadLink.java index abfcddc..5846811 100644 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/thread/ThreadLink.java +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/thread/ThreadLink.java @@ -19,9 +19,11 @@ import de.jaschastarke.minecraft.limitedcreative.blockstate.ThreadedModel; public class ThreadLink { private static final int BATCH_ACTION_LENGTH = 10; - private static final int QUEUE_ACCESS_WARNING_DURATION = 5; + private static final int QUEUE_ACCESS_WARNING_DURATION = 5; // ms private static final int COUNT_WARNING_QUEUE = 5; private static final int COUNT_ERROR_QUEUE = 20; + private static final int QUEUE_TIMING_DURATION = 500; // ms + private long lastTimeout; private Stack updateQueue = new Stack(); private boolean shutdown = false; @@ -56,6 +58,7 @@ public class ThreadLink { public void run() { if (getModule().isDebug()) log.debug("DB-Thread '" + Thread.currentThread().getName() + "' started."); + lastTimeout = System.currentTimeMillis(); while (!shutdown || !updateQueue.isEmpty()) { try { List acts = new LinkedList(); @@ -63,9 +66,17 @@ public class ThreadLink { while (updateQueue.isEmpty() && !shutdown) updateQueue.wait(); if (updateQueue.size() > (BATCH_ACTION_LENGTH * COUNT_ERROR_QUEUE)) { - getLog().severe("Extrem large DB-Queue in " + Thread.currentThread().getName() + ": " + updateQueue.size()); + if (System.currentTimeMillis() - lastTimeout > QUEUE_TIMING_DURATION) { + getLog().warn("Extrem large DB-Queue in " + Thread.currentThread().getName() + ": " + updateQueue.size()); + lastTimeout = System.currentTimeMillis(); + } } else if (updateQueue.size() > (BATCH_ACTION_LENGTH * COUNT_WARNING_QUEUE)) { - getLog().warn("Large DB-Queue in " + Thread.currentThread().getName() + ": " + updateQueue.size()); + if (System.currentTimeMillis() - lastTimeout > QUEUE_TIMING_DURATION) { + getLog().info("Large DB-Queue in " + Thread.currentThread().getName() + ": " + updateQueue.size()); + lastTimeout = System.currentTimeMillis(); + } + } else if (updateQueue.size() <= BATCH_ACTION_LENGTH) { + lastTimeout = System.currentTimeMillis(); } for (int i = 0; i < BATCH_ACTION_LENGTH && !updateQueue.isEmpty(); i++) { acts.add(updateQueue.pop()); diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/cmdblocker/CmdBlockerConfig.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/cmdblocker/CmdBlockerConfig.java index 0220fa3..e059d4f 100644 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/cmdblocker/CmdBlockerConfig.java +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/cmdblocker/CmdBlockerConfig.java @@ -38,7 +38,7 @@ public class CmdBlockerConfig extends Configuration implements IConfigurationSub @Override public void setValues(ConfigurationSection sect) { super.setValues(sect); - entry.setEnabled(getEnabled()); + entry.setDefaultEnabled(getEnabled()); } @Override diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/gmperm/GMPermConfig.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/gmperm/GMPermConfig.java index 4f4f221..f54788e 100644 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/gmperm/GMPermConfig.java +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/gmperm/GMPermConfig.java @@ -48,7 +48,7 @@ public class GMPermConfig extends Configuration implements IConfigurationSubGrou @Override public void setValues(ConfigurationSection sect) { super.setValues(sect); - entry.setEnabled(getEnabled()); + entry.setDefaultEnabled(getEnabled()); } @Override public String getName() { diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/inventories/InventoryConfig.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/inventories/InventoryConfig.java index f6fba61..0bd5e51 100644 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/inventories/InventoryConfig.java +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/inventories/InventoryConfig.java @@ -53,7 +53,7 @@ public class InventoryConfig extends Configuration implements IConfigurationSubG } super.setValues(sect); - entry.setEnabled(getEnabled()); + entry.setDefaultEnabled(getEnabled()); // Config Upgrade if (!sect.contains("storeCreative") && sect.contains("creative")) diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/limits/LimitConfig.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/limits/LimitConfig.java index 989c47b..5357081 100644 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/limits/LimitConfig.java +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/limits/LimitConfig.java @@ -50,7 +50,7 @@ public class LimitConfig extends Configuration implements IConfigurationSubGroup @Override public void setValues(ConfigurationSection sect) { super.setValues(sect); - entry.setEnabled(getEnabled()); + entry.setDefaultEnabled(getEnabled()); // Config Upgrade if (!sect.contains("interact") && sect.contains("sign")) { diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/regions/RegionConfig.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/regions/RegionConfig.java index b0dcd72..c7b8ed5 100644 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/regions/RegionConfig.java +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/regions/RegionConfig.java @@ -47,7 +47,7 @@ public class RegionConfig extends Configuration implements IConfigurationSubGrou @Override public void setValues(ConfigurationSection sect) { super.setValues(sect); - entry.setEnabled(getEnabled()); + entry.setDefaultEnabled(getEnabled()); // Config Upgrade if (!sect.contains("rememberOptional") && sect.contains("remember"))