OffHeapManagementDUnitTest.java 文件源码

java
阅读 15 收藏 0 点赞 0 评论 0

项目:monarch 作者:
/**
 * Creates and adds a generic GaugeMonitor for an attribute of the MemberMXBean.
 * 
 * @param attribute the attribute to monitor.
 * @param highThreshold the high threshold trigger.
 * @param lowThreshold the low threshold trigger.
 */
protected void setupOffHeapMonitor(String attribute, long highThreshold, long lowThreshold) {
  ObjectName memberMBeanObjectName = MBeanJMXAdapter.getMemberMBeanName(
      InternalDistributedSystem.getConnectedInstance().getDistributedMember());
  assertNotNull(memberMBeanObjectName);

  try {
    ObjectName offHeapMonitorName = new ObjectName("monitors:type=Gauge,attr=" + attribute);
    mbeanServer.createMBean("javax.management.monitor.GaugeMonitor", offHeapMonitorName);

    AttributeList al = new AttributeList();
    al.add(new Attribute("ObservedObject", memberMBeanObjectName));
    al.add(new Attribute("GranularityPeriod", 500));
    al.add(new Attribute("ObservedAttribute", attribute));
    al.add(new Attribute("Notify", true));
    al.add(new Attribute("NotifyHigh", true));
    al.add(new Attribute("NotifyLow", true));
    al.add(new Attribute("HighTheshold", highThreshold));
    al.add(new Attribute("LowThreshold", lowThreshold));

    mbeanServer.setAttributes(offHeapMonitorName, al);
    mbeanServer.addNotificationListener(offHeapMonitorName, notificationListener, null, null);
    mbeanServer.invoke(offHeapMonitorName, "start", new Object[] {}, new String[] {});
  } catch (Exception e) {
    fail(e.getMessage());
  }
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号