diff --git a/demo4d-bassboonyd/src/main/love/distributedrebirth/bassboonyd/BãßBȍőnEnumJmxKeyʸᴰ.java b/demo4d-bassboonyd/src/main/love/distributedrebirth/bassboonyd/BãßBȍőnEnumJmxKeyʸᴰ.java new file mode 100644 index 00000000..2edfadb1 --- /dev/null +++ b/demo4d-bassboonyd/src/main/love/distributedrebirth/bassboonyd/BãßBȍőnEnumJmxKeyʸᴰ.java @@ -0,0 +1,10 @@ +package love.distributedrebirth.bassboonyd; + +/** + * Only use when no other keys are needed on instance enum. + */ +@BãßBȍőnAuthorInfoʸᴰ(name = "willemtsade", copyright = "©Δ∞ 仙上主天") +public enum BãßBȍőnEnumJmxKeyʸᴰ implements BãßBȍőnCoffinStoreKeyʸᴰ { + JMX, + ; +} diff --git a/demo4d-bassboonyd/src/main/love/distributedrebirth/bassboonyd/BãßBȍőnEnumJmxʸᴰ.java b/demo4d-bassboonyd/src/main/love/distributedrebirth/bassboonyd/BãßBȍőnEnumJmxʸᴰ.java new file mode 100644 index 00000000..31034551 --- /dev/null +++ b/demo4d-bassboonyd/src/main/love/distributedrebirth/bassboonyd/BãßBȍőnEnumJmxʸᴰ.java @@ -0,0 +1,123 @@ +package love.distributedrebirth.bassboonyd; + +import java.lang.management.ManagementFactory; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +import javax.management.Attribute; +import javax.management.AttributeList; +import javax.management.AttributeNotFoundException; +import javax.management.DynamicMBean; +import javax.management.InvalidAttributeValueException; +import javax.management.MBeanAttributeInfo; +import javax.management.MBeanException; +import javax.management.MBeanInfo; +import javax.management.MBeanNotificationInfo; +import javax.management.MBeanServer; +import javax.management.ObjectName; +import javax.management.ReflectionException; + +@BãßBȍőnAuthorInfoʸᴰ(name = "willemtsade", copyright = "©Δ∞ 仙上主天") +@BãßBȍőnAnnotationInfoʸᴰ(required = {BãßBȍőnClassInfoʸᴰ.class, BãßBȍőnAuthorInfoʸᴰ.class}) +public interface BãßBȍőnEnumJmxʸᴰ extends BãßBȍőnEnumʸᴰ,BãßBȍőnCoffinStoreʸᴰ { + + @SuppressWarnings("unchecked") + default void initJmx(K key) { + BãßBȍőnCoffinOpenʸᴰ coffin = BãßBȍőnCoffinOpenʸᴰ.class.cast(GET_BBC()); + coffin.PUT_MAP(key); + try { + MBeanServer server = ManagementFactory.getPlatformMBeanServer(); + ObjectName objectName1 = new ObjectName(BȍőnNaamI18N() + ":name=counters"); + server.registerMBean(new GuageDynamicMBean(GET_BBC().GET_MAP_OBJ(key)), objectName1); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + default GuageCounter BȍőnInitGuage(K key, String name) { + return BȍőnInitGuage(key,name,""); + } + + default GuageCounter BȍőnInitGuage(K key, String name, String description) { + GuageCounter result = new GuageCounter(name, description); + GET_BBC().GET_MAP_OBJ(key).put(name, result); + return result; + } + + public class GuageCounter { + private volatile long counter; + private final String name; + private final String description; + + public GuageCounter(String name, String description) { + this.name = name; + this.description = description; + } + + public void increment() { + counter++; + } + + public long getCounter() { + return counter; + } + + public String getName() { + return name; + } + + public String getDescription() { + return description; + } + } + + class GuageDynamicMBean implements DynamicMBean { + + private final Map guages; + + public GuageDynamicMBean(Map guages) { + this.guages = guages; + } + + @Override + public MBeanInfo getMBeanInfo() { + MBeanAttributeInfo[] dAttributes = new MBeanAttributeInfo[guages.keySet().size()]; + List keySet = guages.keySet().stream().collect(Collectors.toList()); + for (int i = 0; i < dAttributes.length; i++) { + String name = keySet.get(i); + GuageCounter gc = GuageCounter.class.cast(guages.get(name)); + dAttributes[i] = new MBeanAttributeInfo(gc.getName(), Long.class.getSimpleName(), + gc.getDescription(), true, false, false); + } + return new MBeanInfo(this.getClass().getName(), null, dAttributes, null, null, + new MBeanNotificationInfo[0]); + } + + @Override + public Object getAttribute(String name) throws AttributeNotFoundException, MBeanException, ReflectionException { + GuageCounter gc = GuageCounter.class.cast(guages.get(name)); + return gc.getCounter(); + } + + @Override + public AttributeList getAttributes(String[] arg0) { + return null; + } + + @Override + public Object invoke(String arg0, Object[] arg1, String[] arg2) throws MBeanException, ReflectionException { + return null; + } + + @Override + public void setAttribute(Attribute arg0) + throws AttributeNotFoundException, InvalidAttributeValueException, MBeanException, ReflectionException { + } + + @Override + public AttributeList setAttributes(AttributeList arg0) { + return null; + } + } +} diff --git a/demo4d-numberxd/src/main/love/distributedrebirth/numberxd/base2t/part/warp/TOSWarpCore.java b/demo4d-numberxd/src/main/love/distributedrebirth/numberxd/base2t/part/warp/TOSWarpCore.java index bb2dc509..5a0023e9 100644 --- a/demo4d-numberxd/src/main/love/distributedrebirth/numberxd/base2t/part/warp/TOSWarpCore.java +++ b/demo4d-numberxd/src/main/love/distributedrebirth/numberxd/base2t/part/warp/TOSWarpCore.java @@ -4,20 +4,38 @@ import java.util.HashMap; import java.util.Map; import love.distributedrebirth.bassboonyd.BãßBȍőnAuthorInfoʸᴰ; +import love.distributedrebirth.bassboonyd.BãßBȍőnClassInfoʸᴰ; import love.distributedrebirth.bassboonyd.BãßBȍőnCoffinOpenʸᴰ; +import love.distributedrebirth.bassboonyd.BãßBȍőnCoffinʸᴰ; import love.distributedrebirth.bassboonyd.BãßBȍőnEnumInstanceʸᴰ; +import love.distributedrebirth.bassboonyd.BãßBȍőnEnumJmxKeyʸᴰ; +import love.distributedrebirth.bassboonyd.BãßBȍőnEnumJmxʸᴰ; import love.distributedrebirth.numberxd.base2t.BasePartFactory; import love.distributedrebirth.numberxd.base2t.part.BãßBȍőnPartKeyʸᴰ; import love.distributedrebirth.numberxd.base2t.part.BãßBȍőnPartʸᴰ; @BãßBȍőnAuthorInfoʸᴰ(name = "willemtsade", copyright = "©Δ∞ 仙上主天") -public enum TOSWarpCore implements BãßBȍőnEnumInstanceʸᴰ { +@BãßBȍőnClassInfoʸᴰ(name = "TOSWarpCore", purpose = "The warpcore writer and armor manager.") +public enum TOSWarpCore implements BãßBȍőnEnumInstanceʸᴰ,BãßBȍőnEnumJmxʸᴰ { INSTANCE; + private final BãßBȍőnCoffinOpenʸᴰ BBC = BãßBȍőnCoffinOpenʸᴰ.newInstance(); + public BãßBȍőnCoffinʸᴰ GET_BBC() { return BBC; } + private String armedWarpCipherName; private String armedWarpCipherDescription; + private final GuageCounter readCounter; + private final GuageCounter writeCounter; + + private TOSWarpCore() { + BBC.INIT_BOON(this); + initJmx(BãßBȍőnEnumJmxKeyʸᴰ.JMX); + readCounter = BȍőnInitGuage(BãßBȍőnEnumJmxKeyʸᴰ.JMX, "reads", "The amount of warpcore reads."); + writeCounter = BȍőnInitGuage(BãßBȍőnEnumJmxKeyʸᴰ.JMX, "writes", "The amount of warpcore writes."); + } + public void BãßLockWarpCipher() { for (int base:BasePartFactory.INSTANCE.BãßBases()) { for (BãßBȍőnPartʸᴰ part:BasePartFactory.INSTANCE.BãßBuildPartsByBase(base)) { @@ -27,6 +45,7 @@ public enum TOSWarpCore implements BãßBȍőnEnumInstanceʸᴰ { } public WaterBucket BãßCurrentWarpCore() { + readCounter.increment(); WaterCipher warpCipher = new WaterCipher(); if (armedWarpCipherName == null) { warpCipher.setName("default"); @@ -58,6 +77,7 @@ public enum TOSWarpCore implements BãßBȍőnEnumInstanceʸᴰ { } public void BãßArmWarpCore(WaterBucket warpBucket) { + writeCounter.increment(); armedWarpCipherName = warpBucket.theWater().getName(); armedWarpCipherDescription = warpBucket.theWater().getDescription(); for (WaterCipherHeart heart:warpBucket.theWater().getCipherHearts()) {