1 18 package org.apache.activemq.management; 19 20 import java.util.ArrayList ; 21 import java.util.Iterator ; 22 23 import javax.management.j2ee.statistics.CountStatistic ; 24 25 30 public class PollCountStatisticImpl extends StatisticImpl implements CountStatistic { 31 32 private PollCountStatisticImpl parent; 33 private ArrayList children; 34 35 public PollCountStatisticImpl(PollCountStatisticImpl parent, String name, String description) { 36 this(name, description); 37 setParent(parent); 38 } 39 40 public PollCountStatisticImpl(String name, String description) { 41 this(name, "count", description); 42 } 43 44 public PollCountStatisticImpl(String name, String unit, String description) { 45 super(name, unit, description); 46 } 47 48 public PollCountStatisticImpl getParent() { 49 return parent; 50 } 51 52 public void setParent(PollCountStatisticImpl parent) { 53 if( this.parent !=null ) { 54 this.parent.removeChild(this); 55 } 56 this.parent = parent; 57 if( this.parent !=null ) { 58 this.parent.addChild(this); 59 } 60 } 61 62 synchronized private void removeChild(PollCountStatisticImpl child) { 63 if( children!=null ) 64 children.remove(child); 65 } 66 67 synchronized private void addChild(PollCountStatisticImpl child) { 68 if( children==null ) 69 children = new ArrayList (); 70 children.add(child); 71 } 72 73 synchronized public long getCount() { 74 if ( children == null ) 75 return 0; 76 long count=0; 77 for (Iterator iter = children.iterator(); iter.hasNext();) { 78 PollCountStatisticImpl child = (PollCountStatisticImpl) iter.next(); 79 count += child.getCount(); 80 } 81 return count; 82 } 83 84 protected void appendFieldDescription(StringBuffer buffer) { 85 buffer.append(" count: "); 86 buffer.append(Long.toString(getCount())); 87 super.appendFieldDescription(buffer); 88 } 89 90 93 public double getPeriod() { 94 double count = getCount(); 95 if( count == 0 ) 96 return 0; 97 double time = (System.currentTimeMillis() - getStartTime()); 98 return (time/(count*1000.0)); 99 } 100 101 104 public double getFrequency() { 105 double count = getCount(); 106 double time = (System.currentTimeMillis() - getStartTime()); 107 return (count*1000.0/time); 108 } 109 110 } 111 | Popular Tags |