本文整理匯總了Java中javax.management.MBeanServerConnection.getAttributes方法的典型用法代碼示例。如果您正苦於以下問題:Java MBeanServerConnection.getAttributes方法的具體用法?Java MBeanServerConnection.getAttributes怎麽用?Java MBeanServerConnection.getAttributes使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.management.MBeanServerConnection
的用法示例。
在下文中一共展示了MBeanServerConnection.getAttributes方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getProcessCpuLoad
import javax.management.MBeanServerConnection; //導入方法依賴的package包/類
public static double getProcessCpuLoad(MBeanServerConnection mbs)
throws MalformedObjectNameException, NullPointerException, InstanceNotFoundException,
ReflectionException, IOException {
ObjectName name = ObjectName.getInstance("java.lang:type=OperatingSystem");
AttributeList list = mbs.getAttributes(name, new String[]{"ProcessCpuLoad"});
if (list.isEmpty()) {
return 0.0;
}
Attribute att = (Attribute) list.get(0);
Double value = (Double) att.getValue();
// usually takes a couple of seconds before we get real values
if (value == -1.0) {
return 0.0;
}
// returns a percentage value with 1 decimal point precision
return ((int) (value * 1000) / 10.0);
}
示例2: getMeterMetric
import javax.management.MBeanServerConnection; //導入方法依賴的package包/類
private MeterMetric getMeterMetric(MBeanServerConnection mbsc, ObjectName objectName) {
String[] attributes = {"Count", "MeanRate", "OneMinuteRate", "FiveMinuteRate", "FifteenMinuteRate"};
AttributeList attributeList = null;
try {
attributeList = mbsc.getAttributes(objectName, attributes);
} catch (Exception e) {
LOG.warn("getMeterMetric failed! " + e.getMessage());
return new MeterMetric(0L, 0D, 0D, 0D, 0D);
}
return new MeterMetric(getLongValue(attributeList, attributes[0]), getDoubleValue(attributeList, attributes[1]),
getDoubleValue(attributeList, attributes[2]), getDoubleValue(attributeList, attributes[3]),
getDoubleValue(attributeList, attributes[4]));
}