KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > jca > statistics > StatisticsHelper


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * published by the Free Software Foundation; either version 2.1 of
10   * the License, or (at your option) any later version.
11   *
12   * This software is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this software; if not, write to the Free
19   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21   */

22 package org.jboss.test.jca.statistics;
23
24 import javax.management.Attribute JavaDoc;
25 import javax.management.MBeanServerConnection JavaDoc;
26 import javax.management.ObjectName JavaDoc;
27
28 import org.jboss.mx.util.ObjectNameFactory;
29 import org.jboss.resource.statistic.formatter.StatisticsFormatter;
30
31 /**
32  * A StatisticsHelper.
33  *
34  * @author <a HREF="weston.price@jboss.com">Weston Price</a>
35  * @version $Revision: 44973 $
36  */

37 public class StatisticsHelper
38 {
39    
40    private static final String JavaDoc DEFAULT_FORMATTER = "org.jboss.resource.statistic.pool.JBossDefaultSubPoolStatisticFormatter";
41    private static final String JavaDoc XML_FORMATTER = "org.jboss.resource.statistic.pool.JBossXmlSubPoolStatisticFormatter";
42    
43    private static final ObjectName JavaDoc POOL_NAME = ObjectNameFactory.create("jboss.jca:service=ManagedConnectionPool,name=StatsDS");
44    private static final String JavaDoc ATTRIBUTE_NAME = "StatisticsFormatter";
45    private static final String JavaDoc RAW_STATS_METHOD = "listStatistics";
46    private static final String JavaDoc FORMATTED_STATS_METHOD = "listFormattedSubPoolStatistics";
47    
48    //Pool values
49

50    public static final int DEFAULT_MIN_SIZE = 0;
51    public static final int DEFAULT_MAX_SIZE = 20;
52    public static final int DEFAULT_BLOCK_TIMEOUT = 30000;
53    public static final int DEFAULT_IDLE_TIMEOUT = 15;
54    
55    
56    
57    
58    public static Object JavaDoc listRawStatistics(MBeanServerConnection JavaDoc server) throws Exception JavaDoc{
59       
60       return server.invoke(POOL_NAME, RAW_STATS_METHOD, new Object JavaDoc[0], new String JavaDoc[0]);
61             
62    }
63    
64    public static void setStatisticsFormatter(MBeanServerConnection JavaDoc server, String JavaDoc formatter) throws Exception JavaDoc{
65       
66       server.setAttribute(POOL_NAME, new Attribute JavaDoc(ATTRIBUTE_NAME, formatter));
67       
68    }
69
70    public static String JavaDoc getStatisticsFormatter(MBeanServerConnection JavaDoc server) throws Exception JavaDoc{
71    
72       return (String JavaDoc)server.getAttribute(POOL_NAME, ATTRIBUTE_NAME);
73       
74    }
75    
76    public static String JavaDoc listFormattedStatistics(MBeanServerConnection JavaDoc server) throws Exception JavaDoc{
77       
78       return (String JavaDoc)server.invoke(POOL_NAME, FORMATTED_STATS_METHOD, new Object JavaDoc[0], new String JavaDoc[0]);
79       
80    }
81    
82    public static StatisticsFormatter getDefaultFormatter() throws Exception JavaDoc{
83       
84       Class JavaDoc clazz = Class.forName(DEFAULT_FORMATTER);
85       return (StatisticsFormatter)clazz.newInstance();
86       
87    }
88 }
89
Popular Tags