mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-07-20 03:04:08 +00:00
Loaders better verbose
This commit is contained in:
parent
b266b8b341
commit
36986d7ddd
@ -5,15 +5,20 @@ import com.volmit.iris.manager.IrisDataManager;
|
|||||||
import com.volmit.iris.object.IrisObject;
|
import com.volmit.iris.object.IrisObject;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
public class ObjectResourceLoader extends ResourceLoader<IrisObject>
|
public class ObjectResourceLoader extends ResourceLoader<IrisObject>
|
||||||
{
|
{
|
||||||
private ChronoLatch useFlip = new ChronoLatch(2863);
|
private ChronoLatch useFlip = new ChronoLatch(2222);
|
||||||
private KMap<String, Long> useCache = new KMap<>();
|
private KMap<String, Long> useCache = new KMap<>();
|
||||||
|
private ChronoLatch cl;
|
||||||
|
private AtomicInteger unload;
|
||||||
|
|
||||||
public ObjectResourceLoader(File root, IrisDataManager idm, String folderName, String resourceTypeName)
|
public ObjectResourceLoader(File root, IrisDataManager idm, String folderName, String resourceTypeName)
|
||||||
{
|
{
|
||||||
super(root, idm, folderName, resourceTypeName, IrisObject.class);
|
super(root, idm, folderName, resourceTypeName, IrisObject.class);
|
||||||
|
cl = new ChronoLatch(30000);
|
||||||
|
unload = new AtomicInteger(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getSize()
|
public int getSize()
|
||||||
@ -37,7 +42,7 @@ public class ObjectResourceLoader extends ResourceLoader<IrisObject>
|
|||||||
{
|
{
|
||||||
if(useFlip.flip())
|
if(useFlip.flip())
|
||||||
{
|
{
|
||||||
unloadLast(Iris.lowMemoryMode ? 60000 : (60000 * 5));
|
unloadLast(30000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -80,7 +85,20 @@ public class ObjectResourceLoader extends ResourceLoader<IrisObject>
|
|||||||
useCache.remove(v);
|
useCache.remove(v);
|
||||||
loadCache.remove(v);
|
loadCache.remove(v);
|
||||||
lock.unlock();
|
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)
|
public IrisObject loadFile(File j, String key, String name)
|
||||||
@ -91,7 +109,7 @@ public class ObjectResourceLoader extends ResourceLoader<IrisObject>
|
|||||||
IrisObject t = new IrisObject(0, 0, 0);
|
IrisObject t = new IrisObject(0, 0, 0);
|
||||||
t.read(j);
|
t.read(j);
|
||||||
loadCache.put(key, t);
|
loadCache.put(key, t);
|
||||||
J.a(() -> Iris.verbose("Loading " + resourceTypeName + ": " + j.getPath()));
|
logLoad(j);
|
||||||
t.setLoadKey(name);
|
t.setLoadKey(name);
|
||||||
t.setLoader(manager);
|
t.setLoader(manager);
|
||||||
t.setLoadFile(j);
|
t.setLoadFile(j);
|
||||||
|
@ -7,6 +7,7 @@ import com.volmit.iris.object.IrisRegistrant;
|
|||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
public class ResourceLoader<T extends IrisRegistrant>
|
public class ResourceLoader<T extends IrisRegistrant>
|
||||||
@ -22,11 +23,15 @@ public class ResourceLoader<T extends IrisRegistrant>
|
|||||||
protected IrisLock lock;
|
protected IrisLock lock;
|
||||||
protected String[] possibleKeys = null;
|
protected String[] possibleKeys = null;
|
||||||
protected IrisDataManager manager;
|
protected IrisDataManager manager;
|
||||||
|
protected AtomicInteger loads;
|
||||||
|
protected ChronoLatch sec;
|
||||||
|
|
||||||
public ResourceLoader(File root, IrisDataManager manager, String folderName, String resourceTypeName, Class<? extends T> objectClass)
|
public ResourceLoader(File root, IrisDataManager manager, String folderName, String resourceTypeName, Class<? extends T> objectClass)
|
||||||
{
|
{
|
||||||
lock = new IrisLock("Res");
|
lock = new IrisLock("Res");
|
||||||
this.manager = manager;
|
this.manager = manager;
|
||||||
|
sec = new ChronoLatch(5000);
|
||||||
|
loads = new AtomicInteger();
|
||||||
folderMapCache = new KMap<>();
|
folderMapCache = new KMap<>();
|
||||||
this.objectClass = objectClass;
|
this.objectClass = objectClass;
|
||||||
cname = objectClass.getCanonicalName();
|
cname = objectClass.getCanonicalName();
|
||||||
@ -36,6 +41,29 @@ public class ResourceLoader<T extends IrisRegistrant>
|
|||||||
loadCache = new KMap<>();
|
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()
|
public String[] getPossibleKeys()
|
||||||
{
|
{
|
||||||
if(possibleKeys != null)
|
if(possibleKeys != null)
|
||||||
@ -43,7 +71,7 @@ public class ResourceLoader<T extends IrisRegistrant>
|
|||||||
return possibleKeys;
|
return possibleKeys;
|
||||||
}
|
}
|
||||||
|
|
||||||
Iris.info("Building " + resourceTypeName + " Possibility Lists");
|
Iris.info("Building " + resourceTypeName + " Registry Lists");
|
||||||
KSet<String> m = new KSet<>();
|
KSet<String> m = new KSet<>();
|
||||||
|
|
||||||
for(File i : getFolders())
|
for(File i : getFolders())
|
||||||
@ -84,7 +112,7 @@ public class ResourceLoader<T extends IrisRegistrant>
|
|||||||
{
|
{
|
||||||
T t = new Gson().fromJson(IO.readAll(j), objectClass);
|
T t = new Gson().fromJson(IO.readAll(j), objectClass);
|
||||||
loadCache.put(key, t);
|
loadCache.put(key, t);
|
||||||
J.a(() -> Iris.verbose("Loading " + resourceTypeName + ": " + j.getPath()));
|
logLoad(j);
|
||||||
t.setLoadKey(name);
|
t.setLoadKey(name);
|
||||||
t.setLoadFile(j);
|
t.setLoadFile(j);
|
||||||
t.setLoader(manager);
|
t.setLoader(manager);
|
||||||
@ -95,7 +123,7 @@ public class ResourceLoader<T extends IrisRegistrant>
|
|||||||
catch(Throwable e)
|
catch(Throwable e)
|
||||||
{
|
{
|
||||||
lock.unlock();
|
lock.unlock();
|
||||||
J.a(() -> Iris.warn("Couldn't read " + resourceTypeName + " file: " + j.getPath() + ": " + e.getMessage()));
|
failLoad(j, e);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user