KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > resource > statistic > pool > JBossDefaultSubPoolStatisticFormatter


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.resource.statistic.pool;
23
24 import java.util.Collection JavaDoc;
25 import java.util.Iterator JavaDoc;
26
27 import org.jboss.resource.statistic.JBossStatistics;
28 import org.jboss.resource.statistic.formatter.StatisticsFormatter;
29
30
31 /**
32  * A DefaultStatisticsFormatter.
33  *
34  * @author <a HREF="weston.price@jboss.com">Weston Price</a>
35  * @version $Revision: 44968 $
36  */

37 public class JBossDefaultSubPoolStatisticFormatter implements StatisticsFormatter
38 {
39
40    private static final String JavaDoc POOL_SEPERATOR = "------------------------------------------------------";
41
42    public Object JavaDoc formatSubPoolStatistics(Collection JavaDoc subPoolStatistics)
43    {
44       final StringBuffer JavaDoc statBuff = formatHeader(subPoolStatistics.size());
45       
46       for(Iterator JavaDoc iter = subPoolStatistics.iterator(); iter.hasNext();){
47          
48          JBossSubPoolStatistics stat = (JBossSubPoolStatistics)iter.next();
49          statBuff.append(stat);
50          statBuff.append("\n");
51          statBuff.append(POOL_SEPERATOR);
52          statBuff.append("\n\n");
53          
54       }
55       
56       return statBuff.toString();
57    }
58    
59    
60    public Object JavaDoc formatSubPoolStatistics(final ManagedConnectionPoolStatistics stats)
61    {
62       return formatSubPoolStatistics(stats.getSubPools());
63       
64    }
65
66    private static StringBuffer JavaDoc formatHeader(int count)
67    {
68
69       StringBuffer JavaDoc headerBuff = new StringBuffer JavaDoc();
70       headerBuff.append("Sub Pool Statistics: \n");
71       headerBuff.append("Sub Pool Count: " + count + "\n");
72       headerBuff.append(POOL_SEPERATOR);
73       headerBuff.append("\n\n");
74
75       return headerBuff;
76
77    }
78
79
80    public Object JavaDoc formatStatistics(JBossStatistics stats)
81    {
82       if(!(stats instanceof ManagedConnectionPoolStatistics)){
83
84          throw new IllegalArgumentException JavaDoc("Error: invalid statistics implementaiton for formatter.");
85          
86       }
87       
88       final ManagedConnectionPoolStatistics poolStats = (ManagedConnectionPoolStatistics)stats;
89       return formatSubPoolStatistics(poolStats);
90       
91    }
92
93 }
94
Popular Tags