1 22 package org.jboss.resource.statistic.pool; 23 24 import java.util.Collection ; 25 import java.util.Iterator ; 26 27 import org.jboss.resource.statistic.JBossStatistics; 28 import org.jboss.resource.statistic.formatter.StatisticsFormatter; 29 30 31 37 public class JBossDefaultSubPoolStatisticFormatter implements StatisticsFormatter 38 { 39 40 private static final String POOL_SEPERATOR = "------------------------------------------------------"; 41 42 public Object formatSubPoolStatistics(Collection subPoolStatistics) 43 { 44 final StringBuffer statBuff = formatHeader(subPoolStatistics.size()); 45 46 for(Iterator 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 formatSubPoolStatistics(final ManagedConnectionPoolStatistics stats) 61 { 62 return formatSubPoolStatistics(stats.getSubPools()); 63 64 } 65 66 private static StringBuffer formatHeader(int count) 67 { 68 69 StringBuffer headerBuff = new StringBuffer (); 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 formatStatistics(JBossStatistics stats) 81 { 82 if(!(stats instanceof ManagedConnectionPoolStatistics)){ 83 84 throw new IllegalArgumentException ("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 |