📄 clickmeterdyn.java
字号:
package dwjmxservice.basic;import javax.management.MBeanInfo;import javax.management.DynamicMBean;import javax.management.Attribute;import javax.management.AttributeList;import javax.management.MBeanInfo;import javax.management.MBeanAttributeInfo;import javax.management.MBeanConstructorInfo;import javax.management.MBeanOperationInfo;public class ClickMeterDyn extends ClickMeterInstrm implements DynamicMBean { public ClickMeterDyn() { } public static void main(String[] args) { setLandF(); ClickMeterDyn cms = new ClickMeterDyn(); // can use standard MBean agent - same logic BaseStdAgent myAgent = new BaseStdAgent(); myAgent.startAgent((Object) cms); }// implements the dynamic MBean interfacepublic Object getAttribute(String inAttrName) { if (inAttrName.equals("PanelValue")) return ((Object) getPanelValue()); else return null;} public void setAttribute(Attribute attribute) { if (attribute.getName().equals("PanelValue")) setPanelValue((Integer) attribute.getValue());} public AttributeList getAttributes(String[] attributeNames) { AttributeList resultList = new AttributeList(); for (int i=0 ; i<attributeNames.length ; i++){ try { resultList.add(new Attribute(attributeNames[i], (Object) getAttribute( (String) attributeNames[i]) )); } catch (Exception e) { e.printStackTrace(); } } return(resultList); } public AttributeList setAttributes(AttributeList attributes) { AttributeList resultList = new AttributeList(); for (int i = 0; i<attributes.size(); i++) { Attribute attr = (Attribute) attributes.get(i); try { setAttribute(attr); String name = attr.getName(); resultList.add(new Attribute(name, (Object) getAttribute(name))); } catch(Exception e) { e.printStackTrace(); } } return(resultList); } public Object invoke(String opName, Object params[], String signature[]) { if (opName.equals("incPanelValue")){ incPanelValue(); } else { if (opName.equals("decPanelValue")) { decPanelValue(); } } return null; } public MBeanInfo getMBeanInfo() { MBeanAttributeInfo [] mbai = new MBeanAttributeInfo[1]; mbai[0] = new MBeanAttributeInfo("PanelValue", "java.lang.Integer", "The Panel Value", true, true, false); MBeanConstructorInfo [] mbci = new MBeanConstructorInfo[1]; mbci[0] = new MBeanConstructorInfo("ClickMeterDyn", "Dynamic MBean Click Meter", null); MBeanOperationInfo [] mboi = new MBeanOperationInfo[2]; mboi[0] = new MBeanOperationInfo("incPanelValue", "increment the meter value", null, "void", MBeanOperationInfo.ACTION); mboi[1] = new MBeanOperationInfo("decPanelValue", "decrement the meter value", null, "void", MBeanOperationInfo.ACTION); return new MBeanInfo("dwjmxservice.basic.ClickMeterDyn", "MBean:Click Meter", mbai, mbci, mboi, null); } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -