From c3d36dfbf23db2960b298f7bef15e6a23eae0418 Mon Sep 17 00:00:00 2001 From: Mike Primm Date: Tue, 1 Mar 2022 08:56:50 -0600 Subject: [PATCH] Use concurrentmap for dirty_worlds --- .../dynmap/markers/impl/MarkerAPIImpl.java | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/DynmapCore/src/main/java/org/dynmap/markers/impl/MarkerAPIImpl.java b/DynmapCore/src/main/java/org/dynmap/markers/impl/MarkerAPIImpl.java index c314564a..39e8f2dc 100644 --- a/DynmapCore/src/main/java/org/dynmap/markers/impl/MarkerAPIImpl.java +++ b/DynmapCore/src/main/java/org/dynmap/markers/impl/MarkerAPIImpl.java @@ -342,7 +342,7 @@ public class MarkerAPIImpl implements MarkerAPI, Event.Listener { } private boolean stop = false; - private Set dirty_worlds = new HashSet(); + private ConcurrentHashMap dirty_worlds = new ConcurrentHashMap(); private boolean dirty_markers = false; private class DoFileWrites implements Runnable { @@ -350,18 +350,19 @@ public class MarkerAPIImpl implements MarkerAPI, Event.Listener { if(stop) return; lock.readLock().lock(); + Set dirty = new HashSet(dirty_worlds.keySet()); + dirty_worlds.clear(); try { /* Write markers first - drives JSON updates too */ - if(dirty_markers) { + if (dirty_markers) { doSaveMarkers(); dirty_markers = false; } /* Process any dirty worlds */ - if(!dirty_worlds.isEmpty()) { - for(String world : dirty_worlds) { + if (!dirty.isEmpty()) { + for(String world : dirty) { writeMarkersFile(world); } - dirty_worlds.clear(); } } finally { lock.readLock().unlock(); @@ -872,7 +873,7 @@ public class MarkerAPIImpl implements MarkerAPI, Event.Listener { private void freshenMarkerFiles() { if(MapManager.mapman != null) { for(DynmapWorld w : MapManager.mapman.worlds) { - dirty_worlds.add(w.getName()); + dirty_worlds.put(w.getName(),""); } } } @@ -931,7 +932,7 @@ public class MarkerAPIImpl implements MarkerAPI, Event.Listener { static void markerUpdated(MarkerImpl marker, MarkerUpdate update) { /* Freshen marker file for the world for this marker */ if(api != null) - api.dirty_worlds.add(marker.getNormalizedWorld()); + api.dirty_worlds.put(marker.getNormalizedWorld(),""); /* Enqueue client update */ if(MapManager.mapman != null) MapManager.mapman.pushUpdate(marker.getNormalizedWorld(), new MarkerUpdated(marker, update == MarkerUpdate.DELETED)); @@ -944,7 +945,7 @@ public class MarkerAPIImpl implements MarkerAPI, Event.Listener { static void areaMarkerUpdated(AreaMarkerImpl marker, MarkerUpdate update) { /* Freshen marker file for the world for this marker */ if(api != null) - api.dirty_worlds.add(marker.getNormalizedWorld()); + api.dirty_worlds.put(marker.getNormalizedWorld(),""); /* Enqueue client update */ if(MapManager.mapman != null) MapManager.mapman.pushUpdate(marker.getNormalizedWorld(), new AreaMarkerUpdated(marker, update == MarkerUpdate.DELETED)); @@ -957,7 +958,7 @@ public class MarkerAPIImpl implements MarkerAPI, Event.Listener { static void polyLineMarkerUpdated(PolyLineMarkerImpl marker, MarkerUpdate update) { /* Freshen marker file for the world for this marker */ if(api != null) - api.dirty_worlds.add(marker.getNormalizedWorld()); + api.dirty_worlds.put(marker.getNormalizedWorld(),""); /* Enqueue client update */ if(MapManager.mapman != null) MapManager.mapman.pushUpdate(marker.getNormalizedWorld(), new PolyLineMarkerUpdated(marker, update == MarkerUpdate.DELETED)); @@ -970,7 +971,7 @@ public class MarkerAPIImpl implements MarkerAPI, Event.Listener { static void circleMarkerUpdated(CircleMarkerImpl marker, MarkerUpdate update) { /* Freshen marker file for the world for this marker */ if(api != null) - api.dirty_worlds.add(marker.getNormalizedWorld()); + api.dirty_worlds.put(marker.getNormalizedWorld(),""); /* Enqueue client update */ if(MapManager.mapman != null) MapManager.mapman.pushUpdate(marker.getNormalizedWorld(), new CircleMarkerUpdated(marker, update == MarkerUpdate.DELETED)); @@ -3458,7 +3459,7 @@ public class MarkerAPIImpl implements MarkerAPI, Event.Listener { @Override public void triggered(DynmapWorld t) { /* Update markers for now-active world */ - dirty_worlds.add(t.getName()); + dirty_worlds.put(t.getName(),""); } /* Remove icon */