Second version of JMX

This commit is contained in:
Willem 2022-02-06 15:49:32 +01:00
parent a69315adc0
commit a3f58468f5
32 changed files with 272 additions and 107 deletions

View file

@ -19,7 +19,7 @@ public interface BãßBȍőnCoffinOpenʸᴰ<T extends BãßBȍőnCoffinStoreKey
PUT_OBJ(key, new HashMap<>());
}
default void INIT_BOON(Object boon) {
default void BOON_INIT(Object boon) {
try {
for (Method m:boon.getClass().getMethods()) {
if (m.isAnnotationPresent(BãßBȍőnInitMethodʸᴰ.class)) {

View file

@ -1,10 +0,0 @@
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,
;
}

View file

@ -2,7 +2,7 @@ package love.distributedrebirth.bassboonyd;
@BãßBȍőnAuthorInfoʸᴰ(name = "willemtsade", copyright = "©Δ∞ 仙上主天")
@BãßBȍőnAnnotationInfoʸᴰ(required = {BãßBȍőnClassInfoʸᴰ.class, BãßBȍőnAuthorInfoʸᴰ.class})
public interface BãßBȍőnEnumʸᴰ<T> {
public interface BãßBȍőnEnumʸᴰ<T> extends DefaultAuthorInfoʸᴰ,DefaultClassInfoʸᴰ,DefaultPackageInfoʸᴰ {
String name();
@ -23,21 +23,6 @@ public interface BãßBȍőnEnumʸᴰ<T> {
}
}
default String BãßClassNaam() {
return getClass().getAnnotation(BãßBȍőnClassInfoʸᴰ.class).name();
}
default String BãßClassPurpose() {
return getClass().getAnnotation(BãßBȍőnClassInfoʸᴰ.class).purpose();
}
default String BãßAuthorNaam() {
return getClass().getAnnotation(BãßBȍőnAuthorInfoʸᴰ.class).name();
}
default String BãßAuthorCopyright() {
return getClass().getAnnotation(BãßBȍőnAuthorInfoʸᴰ.class).copyright();
}
default String BȍőnNaamI18N() {
return BãßClassNaam() + BãßBȍőnConstantsʸᴰ.STR_DOT + name();

View file

@ -0,0 +1,14 @@
package love.distributedrebirth.bassboonyd;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@BãßBȍőnAuthorInfoʸᴰ(name = "willemtsade", copyright = "©Δ∞ 仙上主天")
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE})
public @interface BãßBȍőnPackageInfoʸᴰ {
String name();
}

View file

@ -0,0 +1,14 @@
package love.distributedrebirth.bassboonyd;
@BãßBȍőnAuthorInfoʸᴰ(name = "willemtsade", copyright = "©Δ∞ 仙上主天")
@BãßBȍőnAnnotationInfoʸᴰ(required = {BãßBȍőnAuthorInfoʸᴰ.class})
public interface DefaultAuthorInfoʸᴰ {
default String BãßAuthorNaam() {
return getClass().getAnnotation(BãßBȍőnAuthorInfoʸᴰ.class).name();
}
default String BãßAuthorCopyright() {
return getClass().getAnnotation(BãßBȍőnAuthorInfoʸᴰ.class).copyright();
}
}

View file

@ -0,0 +1,14 @@
package love.distributedrebirth.bassboonyd;
@BãßBȍőnAuthorInfoʸᴰ(name = "willemtsade", copyright = "©Δ∞ 仙上主天")
@BãßBȍőnAnnotationInfoʸᴰ(required = {BãßBȍőnClassInfoʸᴰ.class})
public interface DefaultClassInfoʸᴰ {
default String BãßClassNaam() {
return getClass().getAnnotation(BãßBȍőnClassInfoʸᴰ.class).name();
}
default String BãßClassPurpose() {
return getClass().getAnnotation(BãßBȍőnClassInfoʸᴰ.class).purpose();
}
}

View file

@ -0,0 +1,10 @@
package love.distributedrebirth.bassboonyd;
@BãßBȍőnAuthorInfoʸᴰ(name = "willemtsade", copyright = "©Δ∞ 仙上主天")
@BãßBȍőnAnnotationInfoʸᴰ(required = {BãßBȍőnPackageInfoʸᴰ.class})
public interface DefaultPackageInfoʸᴰ {
default String BãßPackageNaam() {
return getClass().getAnnotation(BãßBȍőnPackageInfoʸᴰ.class).name();
}
}

View file

@ -0,0 +1,24 @@
package love.distributedrebirth.bassboonyd.jmx;
import love.distributedrebirth.bassboonyd.BãßBȍőnAuthorInfoʸᴰ;
@BãßBȍőnAuthorInfoʸᴰ(name = "willemtsade", copyright = "©Δ∞ 仙上主天")
abstract public class AbstractMBeanAttributeᴶᴹˣ implements MBeanAttributeᴶᴹˣ {
private final String name;
private final String description;
public AbstractMBeanAttributeᴶᴹˣ(String name, String description) {
this.name = name;
this.description = description;
}
@Override
public String getName() {
return name;
}
@Override
public String getDescription() {
return description;
}
}

View file

@ -0,0 +1,25 @@
package love.distributedrebirth.bassboonyd.jmx;
import love.distributedrebirth.bassboonyd.BãßBȍőnAuthorInfoʸᴰ;
@BãßBȍőnAuthorInfoʸᴰ(name = "willemtsade", copyright = "©Δ∞ 仙上主天")
@BãßBȍőnMBeanAttributeTypeʸᴰ(Boolean.class)
public class BooleanAttributeᴶᴹˣ extends AbstractMBeanAttributeᴶᴹˣ {
private Boolean value;
public BooleanAttributeᴶᴹˣ(String name, String description) {
super(name, description);
}
public void setValueBoolean(Boolean value) {
this.value = value;
}
public Boolean getValueBoolean() {
return value;
}
public Object getValue() {
return value;
}
}

View file

@ -1,4 +1,4 @@
package love.distributedrebirth.bassboonyd;
package love.distributedrebirth.bassboonyd.jmx;
import java.lang.management.ManagementFactory;
import java.util.List;
@ -18,58 +18,51 @@ import javax.management.MBeanServer;
import javax.management.ObjectName;
import javax.management.ReflectionException;
import love.distributedrebirth.bassboonyd.BãßBȍőnAnnotationInfoʸᴰ;
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ȍőnCoffinStoreKeyʸᴰ;
import love.distributedrebirth.bassboonyd.BãßBȍőnCoffinStoreʸᴰ;
import love.distributedrebirth.bassboonyd.BãßBȍőnEnumʸᴰ;
@BãßBȍőnAuthorInfoʸᴰ(name = "willemtsade", copyright = "©Δ∞ 仙上主天")
@BãßBȍőnAnnotationInfoʸᴰ(required = {BãßBȍőnClassInfoʸᴰ.class, BãßBȍőnAuthorInfoʸᴰ.class})
public interface BãßBȍőnEnumJmxʸᴰ<T,K extends BãßBȍőnCoffinStoreKeyʸᴰ> extends BãßBȍőnEnumʸᴰ<T>,BãßBȍőnCoffinStoreʸᴰ<K> {
@SuppressWarnings("unchecked")
default void initJmx(K key) {
default void BȍőnJmxInit(K key) {
BãßBȍőnCoffinOpenʸᴰ<K> 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");
ObjectName objectName1 = new ObjectName(BãßPackageNaam() + ":name=" + BãßClassNaam());
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ȍőnJmxInitGuageCounter(K key, String name) {
return BȍőnJmxInitGuageCounter(key,name,"");
}
default GuageCounter BȍőnInitGuage(K key, String name, String description) {
GuageCounter result = new GuageCounter(name, description);
default GuageCounterᴶᴹˣ BȍőnJmxInitGuageCounter(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;
}
default StringAttributeᴶᴹˣ BȍőnJmxInitStringAttribute(K key, String name, String description) {
StringAttributeᴶᴹˣ result = new StringAttributeᴶᴹˣ(name, description);
GET_BBC().GET_MAP_OBJ(key).put(name, result);
return result;
}
default BooleanAttributeᴶᴹˣ BȍőnJmxInitBooleanAttribute(K key, String name, String description) {
BooleanAttributeᴶᴹˣ result = new BooleanAttributeᴶᴹˣ(name, description);
GET_BBC().GET_MAP_OBJ(key).put(name, result);
return result;
}
class GuageDynamicMBean implements DynamicMBean {
@ -86,8 +79,8 @@ public interface BãßBȍőnEnumJmxʸᴰ<T,K extends BãßBȍőnCoffinStoreKeyʸ
List<String> 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(),
MBeanAttributeᴶᴹˣ gc = MBeanAttributeᴶᴹˣ.class.cast(guages.get(name));
dAttributes[i] = new MBeanAttributeInfo(gc.getName(), gc.BãßValueType().getSimpleName(),
gc.getDescription(), true, false, false);
}
return new MBeanInfo(this.getClass().getName(), null, dAttributes, null, null,
@ -96,8 +89,8 @@ public interface BãßBȍőnEnumJmxʸᴰ<T,K extends BãßBȍőnCoffinStoreKeyʸ
@Override
public Object getAttribute(String name) throws AttributeNotFoundException, MBeanException, ReflectionException {
GuageCounter gc = GuageCounter.class.cast(guages.get(name));
return gc.getCounter();
MBeanAttributeᴶᴹˣ gc = MBeanAttributeᴶᴹˣ.class.cast(guages.get(name));
return gc.getValue();
}
@Override

View file

@ -0,0 +1,16 @@
package love.distributedrebirth.bassboonyd.jmx;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import love.distributedrebirth.bassboonyd.BãßBȍőnAuthorInfoʸᴰ;
@BãßBȍőnAuthorInfoʸᴰ(name = "willemtsade", copyright = "©Δ∞ 仙上主天")
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE})
public @interface BãßBȍőnMBeanAttributeTypeʸᴰ {
Class<?> value();
}

View file

@ -0,0 +1,21 @@
package love.distributedrebirth.bassboonyd.jmx;
import love.distributedrebirth.bassboonyd.BãßBȍőnAuthorInfoʸᴰ;
@BãßBȍőnAuthorInfoʸᴰ(name = "willemtsade", copyright = "©Δ∞ 仙上主天")
@BãßBȍőnMBeanAttributeTypeʸᴰ(Long.class)
public class GuageCounterᴶᴹˣ extends AbstractMBeanAttributeᴶᴹˣ {
private volatile long counter;
public GuageCounterᴶᴹˣ(String name, String description) {
super(name, description);
}
public void increment() {
counter++;
}
public Object getValue() {
return Long.valueOf(counter);
}
}

View file

@ -0,0 +1,17 @@
package love.distributedrebirth.bassboonyd.jmx;
import love.distributedrebirth.bassboonyd.BãßBȍőnAuthorInfoʸᴰ;
@BãßBȍőnAuthorInfoʸᴰ(name = "willemtsade", copyright = "©Δ∞ 仙上主天")
public interface MBeanAttributeᴶᴹˣ {
default Class<?> BãßValueType() {
return getClass().getAnnotation(BãßBȍőnMBeanAttributeTypeʸᴰ.class).value();
}
Object getValue();
String getName();
String getDescription();
}

View file

@ -0,0 +1,13 @@
package love.distributedrebirth.bassboonyd.jmx;
import love.distributedrebirth.bassboonyd.BãßBȍőnAuthorInfoʸᴰ;
import love.distributedrebirth.bassboonyd.BãßBȍőnCoffinStoreKeyʸᴰ;
/**
* Only use when no other coffin keys are needed on instance or enum.
*/
@BãßBȍőnAuthorInfoʸᴰ(name = "willemtsade", copyright = "©Δ∞ 仙上主天")
public enum MBeanStoreKeyᴶᴹˣ implements BãßBȍőnCoffinStoreKeyʸᴰ {
JMX,
;
}

View file

@ -0,0 +1,25 @@
package love.distributedrebirth.bassboonyd.jmx;
import love.distributedrebirth.bassboonyd.BãßBȍőnAuthorInfoʸᴰ;
@BãßBȍőnAuthorInfoʸᴰ(name = "willemtsade", copyright = "©Δ∞ 仙上主天")
@BãßBȍőnMBeanAttributeTypeʸᴰ(String.class)
public class StringAttributeᴶᴹˣ extends AbstractMBeanAttributeᴶᴹˣ {
private String value;
public StringAttributeᴶᴹˣ(String name, String description) {
super(name, description);
}
public void setValueString(String value) {
this.value = value;
}
public String getValueString() {
return value;
}
public Object getValue() {
return value;
}
}