From 36986d7ddd9456e1b24973795eb0cf2d82ff0835 Mon Sep 17 00:00:00 2001 From: Daniel Mills Date: Mon, 11 Jan 2021 17:05:11 -0500 Subject: [PATCH] Loaders better verbose --- .../iris/util/ObjectResourceLoader.java | 26 +++++++++++--- .../com/volmit/iris/util/ResourceLoader.java | 34 +++++++++++++++++-- 2 files changed, 53 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/volmit/iris/util/ObjectResourceLoader.java b/src/main/java/com/volmit/iris/util/ObjectResourceLoader.java index 6c50ac4de..d6c3b9049 100644 --- a/src/main/java/com/volmit/iris/util/ObjectResourceLoader.java +++ b/src/main/java/com/volmit/iris/util/ObjectResourceLoader.java @@ -5,15 +5,20 @@ import com.volmit.iris.manager.IrisDataManager; import com.volmit.iris.object.IrisObject; import java.io.File; +import java.util.concurrent.atomic.AtomicInteger; public class ObjectResourceLoader extends ResourceLoader { - private ChronoLatch useFlip = new ChronoLatch(2863); + private ChronoLatch useFlip = new ChronoLatch(2222); private KMap useCache = new KMap<>(); + private ChronoLatch cl; + private AtomicInteger unload; public ObjectResourceLoader(File root, IrisDataManager idm, String folderName, String resourceTypeName) { super(root, idm, folderName, resourceTypeName, IrisObject.class); + cl = new ChronoLatch(30000); + unload = new AtomicInteger(0); } public int getSize() @@ -37,7 +42,7 @@ public class ObjectResourceLoader extends ResourceLoader { if(useFlip.flip()) { - unloadLast(Iris.lowMemoryMode ? 60000 : (60000 * 5)); + unloadLast(30000); } } @@ -80,7 +85,20 @@ public class ObjectResourceLoader extends ResourceLoader useCache.remove(v); loadCache.remove(v); lock.unlock(); - J.a(() -> Iris.verbose("Unloaded Object: " + v)); + unload.getAndIncrement(); + + if(unload.get() == 1) + { + cl.flip(); + } + + if(cl.flip()) + { + J.a(() -> { + Iris.verbose("Unloaded " + C.WHITE + unload.get() +" " + resourceTypeName + (unload.get() == 1 ? "" : "s") + C.GRAY + " to optimize memory usage." + " (" + Form.f(getLoadCache().size() )+ " " + resourceTypeName + (loadCache.size() == 1 ? "" : "s")+ " Loaded)"); + unload.set(0); + }); + } } public IrisObject loadFile(File j, String key, String name) @@ -91,7 +109,7 @@ public class ObjectResourceLoader extends ResourceLoader IrisObject t = new IrisObject(0, 0, 0); t.read(j); loadCache.put(key, t); - J.a(() -> Iris.verbose("Loading " + resourceTypeName + ": " + j.getPath())); + logLoad(j); t.setLoadKey(name); t.setLoader(manager); t.setLoadFile(j); diff --git a/src/main/java/com/volmit/iris/util/ResourceLoader.java b/src/main/java/com/volmit/iris/util/ResourceLoader.java index aa1c5a2d9..10fb224f3 100644 --- a/src/main/java/com/volmit/iris/util/ResourceLoader.java +++ b/src/main/java/com/volmit/iris/util/ResourceLoader.java @@ -7,6 +7,7 @@ import com.volmit.iris.object.IrisRegistrant; import lombok.Data; import java.io.File; +import java.util.concurrent.atomic.AtomicInteger; @Data public class ResourceLoader @@ -22,11 +23,15 @@ public class ResourceLoader protected IrisLock lock; protected String[] possibleKeys = null; protected IrisDataManager manager; + protected AtomicInteger loads; + protected ChronoLatch sec; public ResourceLoader(File root, IrisDataManager manager, String folderName, String resourceTypeName, Class objectClass) { lock = new IrisLock("Res"); this.manager = manager; + sec = new ChronoLatch(5000); + loads = new AtomicInteger(); folderMapCache = new KMap<>(); this.objectClass = objectClass; cname = objectClass.getCanonicalName(); @@ -36,6 +41,29 @@ public class ResourceLoader loadCache = new KMap<>(); } + public void logLoad(File path) + { + loads.getAndIncrement(); + + if(loads.get() == 1) + { + sec.flip(); + } + + if(sec.flip()) + { + J.a(() -> { + Iris.verbose("Loaded " + C.WHITE + loads.get() + " " + resourceTypeName + (loads.get() == 1 ? "" : "s") + C.GRAY + " (" + Form.f(getLoadCache().size() ) + " " + resourceTypeName + (loadCache.size() == 1 ? "" : "s") + " Loaded)"); + loads.set(0); + }); + } + } + + public void failLoad(File path, Throwable e) + { + J.a(() -> Iris.warn("Couldn't Load " + resourceTypeName + " file: " + path.getPath() + ": " + e.getMessage())); + } + public String[] getPossibleKeys() { if(possibleKeys != null) @@ -43,7 +71,7 @@ public class ResourceLoader return possibleKeys; } - Iris.info("Building " + resourceTypeName + " Possibility Lists"); + Iris.info("Building " + resourceTypeName + " Registry Lists"); KSet m = new KSet<>(); for(File i : getFolders()) @@ -84,7 +112,7 @@ public class ResourceLoader { T t = new Gson().fromJson(IO.readAll(j), objectClass); loadCache.put(key, t); - J.a(() -> Iris.verbose("Loading " + resourceTypeName + ": " + j.getPath())); + logLoad(j); t.setLoadKey(name); t.setLoadFile(j); t.setLoader(manager); @@ -95,7 +123,7 @@ public class ResourceLoader catch(Throwable e) { lock.unlock(); - J.a(() -> Iris.warn("Couldn't read " + resourceTypeName + " file: " + j.getPath() + ": " + e.getMessage())); + failLoad(j, e); return null; } }