001package org.javasimon.jmx;
002
003import org.javasimon.Simon;
004import org.javasimon.Stopwatch;
005import org.javasimon.utils.SimonUtils;
006
007/**
008 * MX Bean representing a particular {@link org.javasimon.Stopwatch}. It is not created
009 * by default when JMX is activated - it must be created explicitely.
010 * {@link JmxRegisterCallback} can be used to automate this.
011 * <p/>
012 * Class can be subclassed to override default behavior if desired, {@link #stopwatch} is declared protected for this reason.
013 *
014 * @author <a href="mailto:virgo47@gmail.com">Richard "Virgo" Richter</a>
015 */
016public class StopwatchMXBeanImpl extends AbstractSimonMXBeanImpl implements StopwatchMXBean {
017
018        /** Wrapped {@link Stopwatch} instance - protected for subclasses. */
019        protected Stopwatch stopwatch;
020
021        /**
022         * Creates the MX bean for the provided Stopwatch.
023         *
024         * @param stopwatch wrapped Stopwatch
025         */
026        public StopwatchMXBeanImpl(Stopwatch stopwatch) {
027                this.stopwatch = stopwatch;
028        }
029
030        @Override
031        public long getTotal() {
032                return stopwatch.getTotal();
033        }
034
035        @Override
036        public final long getLast() {
037                return stopwatch.getLast();
038        }
039
040        @Override
041        public final String getLastAsString() {
042                return SimonUtils.presentNanoTime(getLast());
043        }
044
045        @Override
046        public long getCounter() {
047                return stopwatch.getCounter();
048        }
049
050        @Override
051        public long getMax() {
052                return stopwatch.getMax();
053        }
054
055        @Override
056        public long getMin() {
057                return stopwatch.getMin();
058        }
059
060        @Override
061        public long getMaxTimestamp() {
062                return stopwatch.getMaxTimestamp();
063        }
064
065        @Override
066        public long getMinTimestamp() {
067                return stopwatch.getMinTimestamp();
068        }
069
070        @Override
071        public long getActive() {
072                return stopwatch.getActive();
073        }
074
075        @Override
076        public long getMaxActive() {
077                return stopwatch.getMaxActive();
078        }
079
080        @Override
081        public long getMaxActiveTimestamp() {
082                return stopwatch.getMaxActiveTimestamp();
083        }
084
085        @Override
086        public double getMean() {
087                return stopwatch.getMean();
088        }
089
090        @Override
091        public double getStandardDeviation() {
092                return stopwatch.getStandardDeviation();
093        }
094
095        @Override
096        public double getVariance() {
097                return stopwatch.getVariance();
098        }
099
100        @Override
101        public double getVarianceN() {
102                return stopwatch.getVarianceN();
103        }
104
105        @Override
106        public final StopwatchSample sample() {
107                return new StopwatchSample(stopwatch.sample());
108        }
109
110        @Override
111        public StopwatchSample sampleIncrement(String key) {
112                return new StopwatchSample(stopwatch.sampleIncrement(key));
113        }
114
115        @Override
116        public final String getType() {
117                return SimonInfo.STOPWATCH;
118        }
119
120        @Override
121        public boolean stopIncrementalSampling(String key) {
122                return stopwatch.stopIncrementalSampling(key);
123        }
124
125        @Override
126        protected final Simon simon() {
127                return stopwatch;
128        }
129}