本文整理汇总了Java中javax.management.MBeanAttributeInfo.isWritable方法的典型用法代码示例。如果您正苦于以下问题:Java MBeanAttributeInfo.isWritable方法的具体用法?Java MBeanAttributeInfo.isWritable怎么用?Java MBeanAttributeInfo.isWritable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.management.MBeanAttributeInfo
的用法示例。
在下文中一共展示了MBeanAttributeInfo.isWritable方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: invokeAttribute
import javax.management.MBeanAttributeInfo; //导入方法依赖的package包/类
private Object invokeAttribute(PropertyDescriptor pd, MethodInvocation invocation)
throws JMException, IOException {
String attributeName = JmxUtils.getAttributeName(pd, this.useStrictCasing);
MBeanAttributeInfo inf = this.allowedAttributes.get(attributeName);
// If no attribute is returned, we know that it is not defined in the
// management interface.
if (inf == null) {
throw new InvalidInvocationException(
"Attribute '" + pd.getName() + "' is not exposed on the management interface");
}
if (invocation.getMethod().equals(pd.getReadMethod())) {
if (inf.isReadable()) {
return this.serverToUse.getAttribute(this.objectName, attributeName);
}
else {
throw new InvalidInvocationException("Attribute '" + attributeName + "' is not readable");
}
}
else if (invocation.getMethod().equals(pd.getWriteMethod())) {
if (inf.isWritable()) {
this.serverToUse.setAttribute(this.objectName, new Attribute(attributeName, invocation.getArguments()[0]));
return null;
}
else {
throw new InvalidInvocationException("Attribute '" + attributeName + "' is not writable");
}
}
else {
throw new IllegalStateException(
"Method [" + invocation.getMethod() + "] is neither a bean property getter nor a setter");
}
}
示例2: testMXBean
import javax.management.MBeanAttributeInfo; //导入方法依赖的package包/类
private static void testMXBean(MBeanServer mbs, ObjectName on)
throws Exception {
MBeanInfo mbi = mbs.getMBeanInfo(on);
MBeanAttributeInfo[] attrs = mbi.getAttributes();
int nattrs = attrs.length;
if (mbi.getAttributes().length != 1)
failure("wrong number of attributes: " + attrs);
else {
MBeanAttributeInfo mbai = attrs[0];
if (mbai.getName().equals("Ints")
&& mbai.isReadable() && !mbai.isWritable()
&& mbai.getDescriptor().getFieldValue("openType")
.equals(new ArrayType<int[]>(SimpleType.INTEGER, true))
&& attrs[0].getType().equals("[I"))
success("MBeanAttributeInfo");
else
failure("MBeanAttributeInfo: " + mbai);
}
int[] ints = (int[]) mbs.getAttribute(on, "Ints");
if (equal(ints, new int[] {1, 2, 3}, null))
success("getAttribute");
else
failure("getAttribute: " + Arrays.toString(ints));
ExplicitMXBean proxy =
JMX.newMXBeanProxy(mbs, on, ExplicitMXBean.class);
int[] pints = proxy.getInts();
if (equal(pints, new int[] {1, 2, 3}, null))
success("getAttribute through proxy");
else
failure("getAttribute through proxy: " + Arrays.toString(pints));
}