1 18 package org.apache.activemq.management; 19 20 import javax.management.j2ee.statistics.Statistic ; 21 26 public class StatisticImpl implements Statistic , Resettable { 27 private String name; 28 private String unit; 29 private String description; 30 private long startTime; 31 private long lastSampleTime; 32 protected boolean enabled= false; 33 34 public StatisticImpl(String name, String unit, String description) { 35 this.name = name; 36 this.unit = unit; 37 this.description = description; 38 startTime = System.currentTimeMillis(); 39 lastSampleTime = startTime; 40 } 41 42 public synchronized void reset() { 43 startTime = System.currentTimeMillis(); 44 lastSampleTime = startTime; 45 } 46 47 protected synchronized void updateSampleTime() { 48 lastSampleTime = System.currentTimeMillis(); 49 } 50 51 public synchronized String toString() { 52 StringBuffer buffer = new StringBuffer (); 53 buffer.append(name); 54 buffer.append("{"); 55 appendFieldDescription(buffer); 56 buffer.append(" }"); 57 return buffer.toString(); 58 } 59 60 public String getName() { 61 return name; 62 } 63 64 public String getUnit() { 65 return unit; 66 } 67 68 public String getDescription() { 69 return description; 70 } 71 72 public synchronized long getStartTime() { 73 return startTime; 74 } 75 76 public synchronized long getLastSampleTime() { 77 return lastSampleTime; 78 } 79 80 83 public boolean isEnabled(){ 84 return this.enabled; 85 } 86 87 90 public void setEnabled(boolean enabled){ 91 this.enabled=enabled; 92 } 93 94 protected synchronized void appendFieldDescription(StringBuffer buffer) { 95 buffer.append(" unit: "); 96 buffer.append(unit); 97 buffer.append(" startTime: "); 98 buffer.append(startTime); 100 buffer.append(" lastSampleTime: "); 101 buffer.append(lastSampleTime); 103 buffer.append(" description: "); 104 buffer.append(description); 105 } 106 107 108 109 } 110 | Popular Tags |