package NET.worlds.console; import NET.worlds.core.Std; import java.awt.List; public class StatMemNode extends StatMan implements MainCallback { private static StatMemNode _singleInstance = new StatMemNode(); private int _lastTime; private static final int TITLE = 0; private static final int BLANK1 = 1; private static final int TOTMEM = 2; private static final int FREEMEM = 3; private static final int BLANK2 = 4; private static final int TOTPHYSMEM = 5; private static final int AVAILPHYSMEM = 6; private static final int SWAPUSED = 7; private static final int AVAILVIRTMEM = 8; private static final int TOTUSED = 9; private long _lastTotMem; public int _totPhysMem; public int _availPhysMem; public int _totPageMem; public int _availPageMem; static { nativeInit(); } public static StatMemNode getNode() { return _singleInstance; } private StatMemNode() { StatisticsRoot.getNode().addChild(this); } public static void nativeInit() { } @Override public String toString() { return "System Memory"; } @Override synchronized void grabList(List list) { super.grabList(list); Main.register(this); } @Override synchronized void releaseList(boolean terminalCallback) { if (!terminalCallback) { Main.unregister(this); } super.releaseList(terminalCallback); } @Override public synchronized void mainCallback() { int thisTime = Std.getFastTime(); if (thisTime - this._lastTime > 1000) { this.updateList(); this._lastTime = thisTime; } } public int getVMAvail() { this.updateMemoryStatus(); return this._availPageMem; } @Override void createList() { this._grabbedList.add("System Memory Stats", 0); this._grabbedList.add("", 1); this._lastTotMem = Runtime.getRuntime().totalMemory(); this._grabbedList.add("Total " + Std.getProductName() + " Memory Available: " + this._lastTotMem + " bytes", 2); this.updateMemoryStatus(); this._grabbedList.add(" Free " + Std.getProductName() + " Memory Available: " + Runtime.getRuntime().freeMemory() + " bytes", 3); this._grabbedList.add("", 4); this._grabbedList.add("Total System Physical Memory: " + this._totPhysMem + " bytes", 5); this._grabbedList.add("Available System Physical Memory: " + this._availPhysMem + " bytes", 6); this._grabbedList.add("Total System Swapfile Usage: " + (this._totPageMem - this._availPageMem) + " bytes", 7); this._grabbedList.add("Available Virtual Memory: " + this._availPageMem + " bytes", 8); } @Override void updateList() { long thisTotMem = Runtime.getRuntime().totalMemory(); if (thisTotMem != this._lastTotMem) { this._lastTotMem = thisTotMem; this._grabbedList.replaceItem("Total " + Std.getProductName() + " Memory Available: " + this._lastTotMem + " bytes", 2); } this.updateMemoryStatus(); this._grabbedList.replaceItem(" Free " + Std.getProductName() + " Memory Available: " + Runtime.getRuntime().freeMemory() + " bytes", 3); this._grabbedList.replaceItem("Total System Physical Memory: " + this._totPhysMem + " bytes", 5); this._grabbedList.replaceItem("Available System Physical Memory: " + this._availPhysMem + " bytes", 6); this._grabbedList.replaceItem("Total System Swapfile Usage: " + (this._totPageMem - this._availPageMem) + " bytes", 7); this._grabbedList.replaceItem("Available Virtual Memory: " + this._availPageMem + " bytes", 8); } public void updateMemoryStatus() { Runtime runtime = Runtime.getRuntime(); this._totPhysMem = (int)runtime.maxMemory(); this._availPhysMem = (int)runtime.freeMemory(); this._totPageMem = (int)runtime.totalMemory(); this._availPageMem = (int)(runtime.maxMemory() - (runtime.totalMemory() - runtime.freeMemory())); } }