Add additional full-update intervall and periodically restart file-watchers

This commit is contained in:
Blue (Lukas Rieger) 2021-06-09 00:34:12 +02:00
parent be059a108f
commit 6e01b607ac
No known key found for this signature in database
GPG Key ID: 904C4995F9E1F800
22 changed files with 130 additions and 38 deletions

View File

@ -83,8 +83,6 @@ public class Plugin {
private WebServer webServer;
private Timer daemonTimer;
private TimerTask saveTask;
private TimerTask metricsTask;
private Map<String, RegionFileWatchService> regionFileWatchServices;
@ -212,7 +210,7 @@ public void load() throws IOException, ParseResourceException {
daemonTimer = new Timer("BlueMap-Plugin-Daemon-Timer", true);
//periodically save
saveTask = new TimerTask() {
TimerTask saveTask = new TimerTask() {
@Override
public void run() {
save();
@ -220,8 +218,35 @@ public void run() {
};
daemonTimer.schedule(saveTask, TimeUnit.MINUTES.toMillis(2), TimeUnit.MINUTES.toMillis(2));
//periodically restart the file-watchers
TimerTask fileWatcherRestartTask = new TimerTask() {
@Override
public void run() {
regionFileWatchServices.values().forEach(RegionFileWatchService::close);
regionFileWatchServices.clear();
initFileWatcherTasks();
}
};
daemonTimer.schedule(fileWatcherRestartTask, TimeUnit.HOURS.toMillis(1), TimeUnit.HOURS.toMillis(1));
//periodically update all (non frozen) maps
if (pluginConfig.getFullUpdateIntervalMinutes() > 0) {
long fullUpdateTime = TimeUnit.MINUTES.toMillis(pluginConfig.getFullUpdateIntervalMinutes());
TimerTask updateAllMapsTask = new TimerTask() {
@Override
public void run() {
for (BmMap map : maps.values()) {
if (pluginState.getMapState(map).isUpdateEnabled()) {
renderManager.scheduleRenderTask(new MapUpdateTask(map));
}
}
}
};
daemonTimer.scheduleAtFixedRate(updateAllMapsTask, fullUpdateTime, fullUpdateTime);
}
//metrics
metricsTask = new TimerTask() {
TimerTask metricsTask = new TimerTask() {
@Override
public void run() {
if (Plugin.this.serverInterface.isMetricsEnabled(coreConfig.isMetricsEnabled()))
@ -232,11 +257,7 @@ public void run() {
//watch map-changes
this.regionFileWatchServices = new HashMap<>();
for (BmMap map : maps.values()) {
if (pluginState.getMapState(map).isUpdateEnabled()) {
startWatchingMap(map);
}
}
initFileWatcherTasks();
//enable api
this.api = new BlueMapAPIImpl(this);
@ -269,18 +290,12 @@ public void unload() {
skinUpdater = null;
//stop scheduled threads
if (metricsTask != null) metricsTask.cancel();
metricsTask = null;
if (saveTask != null) saveTask.cancel();
saveTask = null;
if (daemonTimer != null) daemonTimer.cancel();
daemonTimer = null;
//stop file-watchers
if (regionFileWatchServices != null) {
for (RegionFileWatchService watcher : regionFileWatchServices.values()) {
watcher.close();
}
regionFileWatchServices.values().forEach(RegionFileWatchService::close);
regionFileWatchServices.clear();
}
regionFileWatchServices = null;
@ -415,4 +430,12 @@ public MinecraftVersion getMinecraftVersion() {
return minecraftVersion;
}
private void initFileWatcherTasks() {
for (BmMap map : maps.values()) {
if (pluginState.getMapState(map).isUpdateEnabled()) {
startWatchingMap(map);
}
}
}
}

View File

@ -29,6 +29,7 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.concurrent.TimeUnit;
public class PluginConfig {
@ -37,6 +38,7 @@ public class PluginConfig {
private Collection<String> hiddenGameModes = Collections.emptyList();
private boolean hideInvisible = false;
private boolean hideSneaking = false;
private long fullUpdateIntervalMinutes = TimeUnit.HOURS.toMinutes(24);
public PluginConfig(ConfigurationNode node) {
@ -59,6 +61,9 @@ public PluginConfig(ConfigurationNode node) {
//hideSneaking
hideSneaking = node.node("hideSneaking").getBoolean(false);
//periodic map updates
fullUpdateIntervalMinutes = node.node("fullUpdateInterval").getLong(TimeUnit.HOURS.toMinutes(24));
}
public boolean isLiveUpdatesEnabled() {
@ -81,4 +86,8 @@ public boolean isHideSneaking() {
return this.hideSneaking;
}
public long getFullUpdateIntervalMinutes() {
return fullUpdateIntervalMinutes;
}
}

View File

@ -3,3 +3,4 @@ skinDownload: true
hiddenGameModes: []
hideInvisible: true
hideSneaking: false
fullUpdateInterval: 1440

View File

@ -25,3 +25,8 @@ hideInvisible: true
# If this is true, players that are sneaking will be hidden on the map.
# Default is false
hideSneaking: false
# The interval in minutes in which a full map-update will be triggered.
# This is additionally!! to the normal map-update process (in case that fails to detect any file-changes).
# Default is 1440 (24 hours)
fullUpdateInterval: 1440

View File

@ -3,3 +3,4 @@ skinDownload: true
hiddenGameModes: []
hideInvisible: true
hideSneaking: false
fullUpdateInterval: 1440

View File

@ -25,3 +25,8 @@ hideInvisible: true
# If this is true, players that are sneaking will be hidden on the map.
# Default is false
hideSneaking: false
# The interval in minutes in which a full map-update will be triggered.
# This is additionally!! to the normal map-update process (in case that fails to detect any file-changes).
# Default is 1440 (24 hours)
fullUpdateInterval: 1440

View File

@ -3,3 +3,4 @@ skinDownload: true
hiddenGameModes: []
hideInvisible: true
hideSneaking: false
fullUpdateInterval: 1440

View File

@ -25,3 +25,8 @@ hideInvisible: true
# If this is true, players that are sneaking will be hidden on the map.
# Default is false
hideSneaking: false
# The interval in minutes in which a full map-update will be triggered.
# This is additionally!! to the normal map-update process (in case that fails to detect any file-changes).
# Default is 1440 (24 hours)
fullUpdateInterval: 1440

View File

@ -3,3 +3,4 @@ skinDownload: true
hiddenGameModes: []
hideInvisible: true
hideSneaking: false
fullUpdateInterval: 1440

View File

@ -25,3 +25,8 @@ hideInvisible: true
# If this is true, players that are sneaking will be hidden on the map.
# Default is false
hideSneaking: false
# The interval in minutes in which a full map-update will be triggered.
# This is additionally!! to the normal map-update process (in case that fails to detect any file-changes).
# Default is 1440 (24 hours)
fullUpdateInterval: 1440

View File

@ -3,3 +3,4 @@ skinDownload: true
hiddenGameModes: []
hideInvisible: true
hideSneaking: false
fullUpdateInterval: 1440

View File

@ -25,3 +25,8 @@ hideInvisible: true
# If this is true, players that are sneaking will be hidden on the map.
# Default is false
hideSneaking: false
# The interval in minutes in which a full map-update will be triggered.
# This is additionally!! to the normal map-update process (in case that fails to detect any file-changes).
# Default is 1440 (24 hours)
fullUpdateInterval: 1440

View File

@ -3,3 +3,4 @@ skinDownload: true
hiddenGameModes: []
hideInvisible: true
hideSneaking: false
fullUpdateInterval: 1440

View File

@ -25,3 +25,8 @@ hideInvisible: true
# If this is true, players that are sneaking will be hidden on the map.
# Default is false
hideSneaking: false
# The interval in minutes in which a full map-update will be triggered.
# This is additionally!! to the normal map-update process (in case that fails to detect any file-changes).
# Default is 1440 (24 hours)
fullUpdateInterval: 1440

View File

@ -3,3 +3,4 @@ skinDownload: true
hiddenGameModes: []
hideInvisible: true
hideSneaking: false
fullUpdateInterval: 1440

View File

@ -25,3 +25,8 @@ hideInvisible: true
# If this is true, players that are sneaking will be hidden on the map.
# Default is false
hideSneaking: false
# The interval in minutes in which a full map-update will be triggered.
# This is additionally!! to the normal map-update process (in case that fails to detect any file-changes).
# Default is 1440 (24 hours)
fullUpdateInterval: 1440

View File

@ -3,3 +3,4 @@ skinDownload: true
hiddenGameModes: []
hideInvisible: true
hideSneaking: false
fullUpdateInterval: 1440

View File

@ -25,3 +25,8 @@ hideInvisible: true
# If this is true, players that are sneaking will be hidden on the map.
# Default is false
hideSneaking: false
# The interval in minutes in which a full map-update will be triggered.
# This is additionally!! to the normal map-update process (in case that fails to detect any file-changes).
# Default is 1440 (24 hours)
fullUpdateInterval: 1440

View File

@ -3,3 +3,4 @@ skinDownload: false
hiddenGameModes: []
hideInvisible: true
hideSneaking: false
fullUpdateInterval: 1440

View File

@ -25,3 +25,8 @@ hideInvisible: true
# If this is true, players that are sneaking will be hidden on the map.
# Default is false
hideSneaking: false
# The interval in minutes in which a full map-update will be triggered.
# This is additionally!! to the normal map-update process (in case that fails to detect any file-changes).
# Default is 1440 (24 hours)
fullUpdateInterval: 1440

View File

@ -3,3 +3,4 @@ skinDownload: false
hiddenGameModes: []
hideInvisible: true
hideSneaking: false
fullUpdateInterval: 1440

View File

@ -25,3 +25,8 @@ hideInvisible: true
# If this is true, players that are sneaking will be hidden on the map.
# Default is false
hideSneaking: false
# The interval in minutes in which a full map-update will be triggered.
# This is additionally!! to the normal map-update process (in case that fails to detect any file-changes).
# Default is 1440 (24 hours)
fullUpdateInterval: 1440