五、广播Admin MBean属性
管理和托管UserWeb Mbeans可以进行独立地设置-这给任何一个J2EE服务器一个本地化的AJAX响应。然而,一个普通操作,管理和支持(OA&M)支持模式将设置admin MBean的属性,然后使用通知模型把这些属性广播到远程应用程序服务器上的MBeans,以备随后的AJAX检索之用。
因为该UserWeb MBean是基于ApplicationMBean-它扩展了 javax.management.NotificationBroadcasterSupport,所以该基础结构正适合于由UserWeb MBean来通知所有的听者。因此,管理员设置相关的MBean属性(使用HTMLAdaptor)并且点击BroadcastState(见图2)。

图2 使用HTMLAdaptor看到的MBean视图
public void broadcastState() throws Exception {
try {
Notification n = new Notification("alert.broadcast", "ExampleApp:Name=UserWeb", 0);
n.setUserData(new UserWeb(this));
this.sendNotification(n);
}
catch (Exception e) {
throw e;
}
}
六、使用听者接收来自MBean Props的通知
所谓的事件听者就是ManagementListener Singleton。在管理服务器上的JMX通知框架远程调用ManagementListener中的handleNotification()方法- 该方法存在于每个OLTP簇JVMs(它们是在服务器启动时注册的)上的每一个听者之中:
public void handleNotification(Notification notification, Object handback) {
System.out.println("Received alert: " + notification.getType());
//取得来自通知的事件userdata
Object userData = notification.getUserData();
if (userData instanceof UserWeb) {
//来自于destin8 Web
UserWeb WebVo = (UserWeb)userData;
UserWebMBeanHelper helper = MBeanHelperFactory.getWebHelper();
//使用MbeanHelper从值对象获取数据并放入本地MBean中
helper.setAlertMessage(WebVo.getAlertMessage());
helper.setAlertStatus(WebVo.getAlertStatus());
helper.setCallBack(WebVo.getCallBack());
helper.setRefreshAlertStatus(WebVo.getRefreshAlertStatus());
}
}
