mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-01-14 12:11:23 +01:00
PlanConfig#getOrDefault
This commit is contained in:
parent
233a930c9c
commit
be8a3b484f
@ -113,7 +113,7 @@ public abstract class SQLDB extends AbstractDatabase {
|
||||
}
|
||||
transactionExecutor.shutdown();
|
||||
try {
|
||||
Long waitMs = config.get(TimeSettings.DB_TRANSACTION_FINISH_WAIT_DELAY);
|
||||
Long waitMs = config.getOrDefault(TimeSettings.DB_TRANSACTION_FINISH_WAIT_DELAY, TimeUnit.SECONDS.toMillis(20L));
|
||||
if (!transactionExecutor.awaitTermination(waitMs, TimeUnit.MILLISECONDS)) {
|
||||
List<Runnable> unfinished = transactionExecutor.shutdownNow();
|
||||
int unfinishedCount = unfinished.size();
|
||||
|
@ -19,6 +19,7 @@ package com.djrapitops.plan.system.settings.config;
|
||||
import com.djrapitops.plan.data.plugin.PluginsConfigSection;
|
||||
import com.djrapitops.plan.system.settings.paths.TimeSettings;
|
||||
import com.djrapitops.plan.system.settings.paths.key.Setting;
|
||||
import com.djrapitops.plugin.logging.console.PluginLogger;
|
||||
import com.djrapitops.plugin.utilities.Verify;
|
||||
|
||||
import javax.inject.Inject;
|
||||
@ -39,15 +40,18 @@ public class PlanConfig extends Config {
|
||||
|
||||
private final PluginsConfigSection pluginsConfigSection;
|
||||
private final WorldAliasSettings worldAliasSettings;
|
||||
private final PluginLogger logger;
|
||||
|
||||
@Inject
|
||||
public PlanConfig(
|
||||
@Named("configFile") File file,
|
||||
WorldAliasSettings worldAliasSettings
|
||||
WorldAliasSettings worldAliasSettings,
|
||||
PluginLogger logger
|
||||
) {
|
||||
super(file);
|
||||
|
||||
this.worldAliasSettings = worldAliasSettings;
|
||||
this.logger = logger;
|
||||
|
||||
pluginsConfigSection = new PluginsConfigSection(this);
|
||||
}
|
||||
@ -69,6 +73,15 @@ public class PlanConfig extends Config {
|
||||
return value;
|
||||
}
|
||||
|
||||
public <T> T getOrDefault(Setting<T> setting, T defaultValue) {
|
||||
try {
|
||||
return get(setting);
|
||||
} catch (IllegalStateException e) {
|
||||
logger.warn(e.getMessage() + ", using '" + defaultValue + "'");
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isTrue(Setting<Boolean> setting) {
|
||||
return get(setting);
|
||||
}
|
||||
|
@ -134,7 +134,7 @@ public class ConfigSettingKeyTest {
|
||||
}
|
||||
|
||||
private PlanConfig createConfig(File configFile) throws IOException {
|
||||
PlanConfig config = new PlanConfig(configFile, null);
|
||||
PlanConfig config = new PlanConfig(configFile, null, logger);
|
||||
config.save();
|
||||
return config;
|
||||
}
|
||||
|
@ -84,7 +84,7 @@ class ConfigUpdaterTest {
|
||||
Path config = tempDir.resolve("oldconfig.yml");
|
||||
Files.copy(oldConfig.toPath(), config, StandardCopyOption.REPLACE_EXISTING);
|
||||
|
||||
PlanConfig planConfig = new PlanConfig(config.toFile(), null);
|
||||
PlanConfig planConfig = new PlanConfig(config.toFile(), null, logger);
|
||||
|
||||
UNDER_TEST.applyConfigUpdate(planConfig);
|
||||
|
||||
@ -100,7 +100,7 @@ class ConfigUpdaterTest {
|
||||
Path config = tempDir.resolve("oldconfig.yml");
|
||||
Files.copy(oldBungeeConfig.toPath(), config, StandardCopyOption.REPLACE_EXISTING);
|
||||
|
||||
PlanConfig planConfig = new PlanConfig(config.toFile(), null);
|
||||
PlanConfig planConfig = new PlanConfig(config.toFile(), null, logger);
|
||||
|
||||
UNDER_TEST.applyConfigUpdate(planConfig);
|
||||
|
||||
@ -122,7 +122,7 @@ class ConfigUpdaterTest {
|
||||
Path config = tempDir.resolve("oldconfig.yml");
|
||||
Files.copy(oldConfig.toPath(), config, StandardCopyOption.REPLACE_EXISTING);
|
||||
|
||||
PlanConfig planConfig = new PlanConfig(config.toFile(), null);
|
||||
PlanConfig planConfig = new PlanConfig(config.toFile(), null, logger);
|
||||
|
||||
ConfigChange[] changes = UNDER_TEST.configEnhancementPatch();
|
||||
assertMoveChangesAreAppliedProperly(planConfig, changes);
|
||||
@ -133,7 +133,7 @@ class ConfigUpdaterTest {
|
||||
Path config = tempDir.resolve("oldconfig.yml");
|
||||
Files.copy(oldBungeeConfig.toPath(), config, StandardCopyOption.REPLACE_EXISTING);
|
||||
|
||||
PlanConfig planConfig = new PlanConfig(config.toFile(), null);
|
||||
PlanConfig planConfig = new PlanConfig(config.toFile(), null, logger);
|
||||
|
||||
ConfigChange[] changes = UNDER_TEST.configEnhancementPatch();
|
||||
assertMoveChangesAreAppliedProperly(planConfig, changes);
|
||||
|
Loading…
Reference in New Issue
Block a user