http://www.cnblogs.com/allenny/articles/179163.html

使用通知(notification)
通知其实就是一个监听器,我们可以为MBean注册一个监听器,当满足一定的条件时,MBean会发消息给监听器,然后监听器进行必要的处理。
一个MBean可以通过两种方法实现notification。
1:实现javax.management.NotificationBroadcaster接口
2:扩展javax.management.NotificationBroadcasterSupport类(这个类也实现了上面的接口)


要编写监听器,必须实现javax.management。NotificationListener接口
下面看一个简单的通知的例子,利用方式2实现
MBean的代码:

[转]JMX指南(二)import java.io.*;
[转]JMX指南(二)import javax.management.
*;
[转]JMX指南(二)


上面的代码仅仅用了一个最简单的通知类:Notification

[转]JMX指南(二)public Notification(java.lang.String type, java.lang.Object source,
[转]JMX指南(二)
long sequenceNumber,long timeStamp, 
[转]JMX指南(二)java.lang.String message)


type用来标示通知, source为产生通知的MBean,sequenceNumber为一系列通知中的序号,timeStamp为通知创建的时间,message为具体的通知消息。
由于从javax.management.NotificationBroadcasterSupport继承,所以编写起来容易些。

下面看agent类

[转]JMX指南(二)import javax.management.*;
[转]JMX指南(二)import com.sun.jdmk.comm.HtmlAdaptorServer;
[转]JMX指南(二)
[转]JMX指南(二)
public class HelloAgent implements NotificationListener
[转]JMX指南(二)

在agent类中
hw.addNotificationListener( this, null, null );将agent作为helloworld MBean的监听器,并且agent类实现了NotificationListener 接口,方法handleNotification处理具体的通知到达的情况。

http://www.cnblogs.com/allenny/articles/179208.html

相关文章:

  • 2021-12-16
  • 2022-12-23
  • 2021-11-18
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-05-25
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-26
  • 2021-12-06
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案