JBoss MBean实现方法
原文: http://yushangshare.spaces.live.com/blog/cns!28d8381b4d4289dc!145.entry
这篇文章不错:http://www.blogjava.net/chengang/archive/2006/03/07/34091.html JBoss MBean实现方法
JBoss下的MBean有几种实现方法
1,XX和XXMBean public interface XXMBean {...} public class XX extends ServiceMBeanSupport implements XXMBean { ...} 在XX注册为MBean时,服务器会自动查找是否实现XXMBean接口,XX引出 的管理接口就是XXMBean接口 2,继承StandardMBean public class XX extends StandardMBean implements SomeIntf { ...} jboss-service.xml中的配置项 <mbean code="XX" interface="SomeIntf">...</mbean> 这样MBean就引出了SomeIntf管理接口,实现的接口不必遵循 XX+MBean的模式 3,任意的Java类,通过*-xmbean.xml文件来定义管理接口 public class XX extends ServiceMBeanSupport {...} jboss-service.xml配置项 <mbean code="XX" xmbean-dd="resource:xmdesc/XX-xmbean.xml">...</mbean> XX-xmbean.xml内容 <mbean> <description>Demo</description> <descriptors> <interceptors> <interceptor code="test.MyInterceptor"/> </interceptors> </descriptors> <class>XX</class> //这个值设成什么都无所谓,XMBean在解析xml文件时调用的是 //public XMLMetaData(String mmbClassName, String resourceClassName, URL url) //函数,已经传入了resourceClassName值,这个值就是jboss-service.xml中mbean的code 管理接口(属性、方法)的申明... //在这里申明什么接口,系统就会引出什么接口,当然系统不会去校验的 </mbean> 三种方法中,最后一种最灵活,主要的是可以加入客户化的interceptor 一个例子如下: package test; import org.jboss.mx.interceptor.AbstractInterceptor; import org.jboss.mx.interceptor.Interceptor; import org.jboss.mx.server.Invocation; public class MyInterceptor extends AbstractInterceptor { public Object invoke(Invocation invocation) throws Throwable { log.info("Invocation: " + invocation); AbstractInterceptor ic = invocation.nextInterceptor(); if( ic == null ) { return invocation.dispatch(); } else { long start = System.currentTimeMillis(); try{ return ic.invoke( invocation ); }catch(Exception e){ e.printStackTrace(); return null; } //I can wrapp some exception finally { log.info("call time : " + ( System.currentTimeMillis() - start ) ); } } } } 这样就可以捕获MBean方法调用了,这个例子是显示MBean方法的调用时间 |