From df9d3494c3774d71da1a97d9c49115b5e57e4ca4 Mon Sep 17 00:00:00 2001 From: Mike Primm Date: Wed, 27 Jul 2011 08:04:53 -0500 Subject: [PATCH] Tighten up shutdown of zoom file processing during reload --- src/main/java/org/dynmap/DynmapWorld.java | 19 ++++++++++++++++--- .../dynmap/InternalClientUpdateComponent.java | 2 ++ .../dynmap/JsonFileClientUpdateComponent.java | 2 ++ src/main/java/org/dynmap/MapManager.java | 3 +++ 4 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/dynmap/DynmapWorld.java b/src/main/java/org/dynmap/DynmapWorld.java index 38241d7c..07593399 100644 --- a/src/main/java/org/dynmap/DynmapWorld.java +++ b/src/main/java/org/dynmap/DynmapWorld.java @@ -44,6 +44,7 @@ public class DynmapWorld { @SuppressWarnings("unchecked") private HashSet zoomoutupdates[] = new HashSet[0]; private boolean checkts = true; /* Check timestamps on first run with new configuration */ + private boolean cancelled; @SuppressWarnings("unchecked") public void setExtraZoomOutLevels(int lvl) { @@ -118,7 +119,7 @@ public class DynmapWorld { public void freshenZoomOutFiles() { boolean done = false; int last_done = 0; - for(int i = 0; (!done); i++) { + for(int i = 0; (!cancelled) && (!done); i++) { done = freshenZoomOutFilesByLevel(i); last_done = i; } @@ -129,6 +130,10 @@ public class DynmapWorld { checkts = false; /* Just handle queued updates after first scan */ } + public void cancelZoomOutFreshen() { + cancelled = true; + } + private static class PrefixData { int stepsize; int[] stepseq; @@ -153,6 +158,7 @@ public class DynmapWorld { if(checkts) { /* If doing timestamp based scan (initial) */ DirFilter df = new DirFilter(); for(String pfx : maptab.keySet()) { /* Walk through prefixes */ + if(cancelled) return true; PrefixData pd = maptab.get(pfx); if(pd.isbigmap) { /* If big world, next directories are map name specific */ File dname = new File(worldtilepath, pfx); @@ -160,6 +166,7 @@ public class DynmapWorld { String[] subdir = dname.list(df); if(subdir == null) continue; for(String s : subdir) { + if(cancelled) return true; File sdname = new File(dname, s); cnt += processZoomDirectory(sdname, pd); } @@ -175,9 +182,11 @@ public class DynmapWorld { HashMap toprocess = new HashMap(); /* Accumulate zoomed tiles to be processed (combine triggering subtiles) */ for(String p : paths) { + if(cancelled) return true; File f = new File(p); /* Make file */ /* Find matching prefix */ for(PrefixData pd : maptab.values()) { /* Walk through prefixes */ + if(cancelled) return true; ProcessTileRec tr = null; /* If big map and matches name pattern */ if(pd.isbigmap && f.getName().startsWith(pd.fnprefix) && @@ -198,6 +207,7 @@ public class DynmapWorld { } /* Do processing */ for(ProcessTileRec s : toprocess.values()) { + if(cancelled) return true; processZoomTile(s.pd, s.zf, s.zfname, s.x, s.y); } } @@ -412,12 +422,15 @@ public class DynmapWorld { } FileLockManager.getWriteLock(zf); try { - TileHashManager hashman = MapManager.mapman.hashman; + MapManager mm = MapManager.mapman; + if(mm == null) + return; + TileHashManager hashman = mm.hashman; long crc = hashman.calculateTileHash(kzIm.argb_buf); /* Get hash of tile */ int tilex = ztx/step/2; int tiley = zty/step/2; String key = world.getName()+".z"+pd.zoomprefix+pd.baseprefix; - if((!zf.exists()) || (crc != MapManager.mapman.hashman.getImageHashCode(key, null, tilex, tiley))) { + if((!zf.exists()) || (crc != mm.hashman.getImageHashCode(key, null, tilex, tiley))) { try { if(!zf.getParentFile().exists()) zf.getParentFile().mkdirs(); diff --git a/src/main/java/org/dynmap/InternalClientUpdateComponent.java b/src/main/java/org/dynmap/InternalClientUpdateComponent.java index 59436a7c..fd1c32f2 100644 --- a/src/main/java/org/dynmap/InternalClientUpdateComponent.java +++ b/src/main/java/org/dynmap/InternalClientUpdateComponent.java @@ -45,6 +45,8 @@ public class InternalClientUpdateComponent extends ClientUpdateComponent { } protected void webChat(String name, String message) { + if(plugin.mapManager == null) + return; // TODO: Change null to something meaningful. plugin.mapManager.pushUpdate(new Client.ChatMessage("web", null, name, message, null)); Log.info(unescapeString(plugin.configuration.getString("webprefix", "\u00A72[WEB] ")) + name + ": " + unescapeString(plugin.configuration.getString("websuffix", "\u00A7f")) + message); diff --git a/src/main/java/org/dynmap/JsonFileClientUpdateComponent.java b/src/main/java/org/dynmap/JsonFileClientUpdateComponent.java index 9d0ab90a..6ee45755 100644 --- a/src/main/java/org/dynmap/JsonFileClientUpdateComponent.java +++ b/src/main/java/org/dynmap/JsonFileClientUpdateComponent.java @@ -117,6 +117,7 @@ public class JsonFileClientUpdateComponent extends ClientUpdateComponent { protected void writeUpdates() { File outputFile; File outputTempFile; + if(plugin.mapManager == null) return; //Handles Updates for (DynmapWorld dynmapWorld : plugin.mapManager.getWorlds()) { World world = dynmapWorld.world; @@ -195,6 +196,7 @@ public class JsonFileClientUpdateComponent extends ClientUpdateComponent { } protected void webChat(String name, String message) { + if(plugin.mapManager == null) return; // TODO: Change null to something meaningful. plugin.mapManager.pushUpdate(new Client.ChatMessage("web", null, name, message, null)); Log.info(unescapeString(plugin.configuration.getString("webprefix", "\u00A2[WEB] ")) + name + ": " + unescapeString(plugin.configuration.getString("websuffix", "\u00A7f")) + message); diff --git a/src/main/java/org/dynmap/MapManager.java b/src/main/java/org/dynmap/MapManager.java index 5cf01cc8..90cd4be7 100644 --- a/src/main/java/org/dynmap/MapManager.java +++ b/src/main/java/org/dynmap/MapManager.java @@ -634,6 +634,9 @@ public class MapManager { } public void stopRendering() { + /* Tell all worlds to cancel any zoom out processing */ + for(DynmapWorld w: worlds) + w.cancelZoomOutFreshen(); render_pool.shutdown(); try { render_pool.awaitTermination(5, TimeUnit.SECONDS);