E - public interface DynamicMBeanOperation<E>
实现程序范例:
public class MyClass
{
// 获取属性的实际操作方法
public String getVal(String val)
{
return val;
}
// 设置属性的实际操作方法
public void setVal(String val)
{
}
// 操作的实际操作代码
public boolean oper1()
{
return true;
}
// 初始化MBean
public void initMBean()
{
new TestMBean(this).registerMBean();
}
// 属性处理枚举类
public enum MyClassMBeanAttribute
implements DynamicMBeanAttribute
{
attr1
{
// 属性名称
public String getName()
{
return this.name();
}
// 获取属性MBean信息
public MBeanAttributeInfo getMBeanAttributeInfo()
{
return new MBeanAttributeInfo(getName(),
"java.lang.String",
"测试属性1",
true,
true,
false);
}
// 获取属性值
public Object getAttribute(MyClass owner)
throws AttributeNotFoundException, MBeanException,
ReflectionException
{
return owner.getVal("测试1");
}
// 设置属性值
public void setAttribute(MyClass owner,
Object val)
{
owner.setVal(String.valueOf(val));
}
},
attr2 // 第二个属性
{
public String getName()
{
return this.name();
}
public MBeanAttributeInfo getMBeanAttributeInfo()
{
return new MBeanAttributeInfo(getName(),
"java.lang.String",
"测试属性2",
true,
true,
false);
}
public Object getAttribute(MyClass owner)
throws AttributeNotFoundException, MBeanException,
ReflectionException
{
return owner.getVal("测试1");
}
public void setAttribute(MyClass owner,
Object val)
{
owner.setVal(String.valueOf(val));
}
};
}
// 操作枚举类
public enum MyClassMBeanOperation
implements DynamicMBeanOperation
{
oper1
{
// 操作名称
public String getName()
{
return this.name();
}
// 获取操作MBean信息
public MBeanOperationInfo getMBeanOperationInfo()
{
return new MBeanOperationInfo(getName(),
"测试方法1",
null,
"boolean",
MBeanOperationInfo.INFO);
}
// 调用操作处理
public Object invoke(MyClass owner,
Object[] params, String[] signature)
throws MBeanException, ReflectionException
{
return owner.oper1();
}
},
// 带参数方法
oper2
{
// 操作名称
public String getName()
{
return this.name();
}
// 获取操作MBean信息
public MBeanOperationInfo getMBeanOperationInfo()
{
MBeanParameterInfo[] params;
params = new MBeanParameterInfo[]
{ new MBeanParameterInfo("beanName",
"java.lang.String",
"获取指定名称的对象") };
return new MBeanOperationInfo(getName(),
"测试方法2",
params,
"boolean",
MBeanOperationInfo.INFO);
}
// 调用操作处理
public Object invoke(MyClass owner,
Object[] params, String[] signature)
throws MBeanException, ReflectionException
{
return owner.oper1();
}
}
}
// MBean类
public class TestMBean extends
DynamicMBeanAbstract2
{
public TestMBean(MyClass owner)
{
super(owner);
}
public TestMBean(MyClass owner,
String name,
String desc)
{
super(owner, name, desc);
} | 限定符和类型 | 方法和说明 |
|---|---|
javax.management.MBeanOperationInfo |
getMBeanOperationInfo()
获取方法信息。
|
java.lang.String |
getName()
获取方法名称。
|
java.lang.Object |
invoke(E owner,
java.lang.Object[] params,
java.lang.String[] signature)
调用方法。
|
java.lang.String getName()
javax.management.MBeanOperationInfo getMBeanOperationInfo()
java.lang.Object invoke(E owner, java.lang.Object[] params, java.lang.String[] signature) throws javax.management.MBeanException, javax.management.ReflectionException
owner - params - signature - javax.management.MBeanExceptionjavax.management.ReflectionExceptionCopyright © 2001-2014 hynnet.com