如何计算在Glassfish 3.1上部署的Web服务的调用

时间:2012-12-25 19:42:58

标签: web-services java-ee glassfish-3

如何计算部署在Glassfish 3.1上的Web服务的调用? 实际上我可以在控制台命令中得到我想要的东西?如下

asadmin get -m "server.applications.hello-jaxws2*" server.applications.hello-jaxws2.2.server.Hello.requestcount-count = 14

但我想知道是否有办法以编程方式获取Web服务的调用次数?

1 个答案:

答案 0 :(得分:2)

使用Glassfish 3.1.2作为示例。这里名为“NewWebService”的Web服务是一个代码提取,它检索该Web服务的请求数。

public static void showRequestCount(MBeanServerConnection mbs) throws Exception {
    ObjectName on = new ObjectName("amx:pp=/mon/server-mon[server],type=servlet-instance-mon,name=WebApplication1/server/NewWebService");
    final Set<ObjectInstance> mBeans = mbs.queryMBeans(on, null);
    for (ObjectInstance mbean : mBeans) {
        System.out.println("mbean: " + mbean);
        final MBeanInfo info = mbs.getMBeanInfo(on);
        final MBeanAttributeInfo[] attributes = info.getAttributes();
        for (int i = 0; i < attributes.length; i++) {
            MBeanAttributeInfo mBeanAttributeInfo = attributes[i];
            if (mBeanAttributeInfo.getName().equals("requestcount")) {
                final Object attribute = mbs.getAttribute(on, mBeanAttributeInfo.getName());
                CompositeDataSupport cds = (CompositeDataSupport) attribute;
                final Object requestCount = cds.get("count");
                System.out.println("Object name: " + on.getKeyProperty("name"));
                System.out.println("Request count: " + requestCount);
            }
        }
    }
}

结果是:

mbean: servlet-instance-mon[amx:pp=/mon/server-mon[server],type=servlet-instance-mon,name=WebApplication1/server/NewWebService]
Object name: WebApplication1/server/NewWebService
Request count: 18

请注意,MBean的ObjectName和/或其属性可能因Glassfish版本而异。