java-发出JMX通知的最佳实践

在定义发出通知的MBean(特别是关于通知类型)的过程中要寻找指导. Oracle网站上的JMX Best Practices表示以下内容.但这是Java6之前的旧版本.

Notifications should be instances of javax.management.Notification or one of the subclasses from the javax.management namespace. Information that does not fit into one of those subclasses should be conveyed by attaching a CompositeData to the notification using the setUserData method.

同样在Oracle网站上,我看到Weblogic定义了一些自己的子类,例如WebLogicLogNotification.其Best Practices状态:

All JMX notification objects extend the javax.management.Notification object type. JMX and WebLogic Server define additional notification object types, such as javax.management.AttributeChangeNotification. The additional object types contain specialized sets of information that are appropriate for different types of events.

我们的通知不适合任何标准子类,因此像WLS一样,考虑使用自定义getter定义我们自己的子类,以获取我们希望随通知一起传达的信息.还是坚持使用基本javax.management.Notification并仅将我们的信息附加到通用setUserData(Object)上会更好?如果我们做后者,我想对象应该是一个JMX类型,例如CompositeData,看起来不太好.从消费者的角度考虑哪个更好?

编辑:从使用者的角度来看,我想自定义子类的缺点是他们必须将其包括在应用程序/类路径中.

解决方法:

在jmx中使用自定义数据类型几乎总是一个坏主意.这是非常有限的.坚持开放类型,您的数据就可以被任何jmx客户端(Java或其他方式)使用.

请注意,您始终可以提供一些帮助程序类,以执行某种“自定义bean”<->. “开放式”转换.可以访问帮助程序类的类可以利用这些便捷方法(例如ThreadInfo.from()),而外部和非Java代码仍然可以使用数据.

上一篇:java – 在生产时连接jmx时出错


下一篇:java – 强制Spring的MBeanExporter使用特定的MBeanServer