001 /**
002 * $Id: JamonMonitor.java,v 1.4 2014/04/28 17:36:37 oboehm Exp $
003 *
004 * Copyright (c) 2008 by Oliver Boehm
005 *
006 * Licensed under the Apache License, Version 2.0 (the "License");
007 * you may not use this file except in compliance with the License.
008 * You may obtain a copy of the License at
009 *
010 * http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express orimplied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 *
018 * (c)reated 25.12.2008 by oliver (ob@oasd.de)
019 */
020 package patterntesting.runtime.monitor;
021
022 import java.util.Date;
023
024 import patterntesting.runtime.annotation.UnsupportedOperation;
025
026 import com.jamonapi.*;
027
028 /**
029 * This is a thin wrapper for com.jamonapi.Monitor
030 *
031 * @see com.jamonapi.Monitor
032 * @author <a href="boehm@javatux.de">oliver</a>
033 * @since 25.12.2008
034 * @version $Revision: 1.4 $
035 */
036 public final class JamonMonitor extends AbstractProfileMonitor {
037
038 private final Monitor monitor;
039
040 /**
041 * Instantiates a new monitor.
042 *
043 * @param monitor the monitor
044 */
045 public JamonMonitor(final Monitor monitor) {
046 this.monitor = monitor;
047 }
048
049 /**
050 * @param arg0 argument
051 * @see com.jamonapi.Monitor#add(double)
052 */
053 public void add(final double arg0) {
054 monitor.add(arg0);
055 }
056
057 /**
058 * Disable.
059 *
060 * @see com.jamonapi.Monitor#disable()
061 */
062 public void disable() {
063 monitor.disable();
064 }
065
066 /**
067 * @see com.jamonapi.Monitor#enable()
068 */
069 public void enable() {
070 monitor.enable();
071 }
072
073 /**
074 * Tests if given object is equal.
075 *
076 * @param other the other object to compare
077 * @return true if objects are equal
078 * @see java.lang.Object#equals(java.lang.Object)
079 */
080 @Override
081 public boolean equals(final Object other) {
082 if (other == null) {
083 return false;
084 }
085 try {
086 return equals((JamonMonitor) other);
087 } catch (ClassCastException cce) {
088 return true;
089 }
090 }
091
092 /**
093 * Tests if given object is equal.
094 *
095 * @param other the other object to compare
096 * @return true if objects are equal
097 * @see java.lang.Object#equals(java.lang.Object)
098 */
099 public boolean equals(final JamonMonitor other) {
100 return this.monitor.equals(other.monitor);
101 }
102
103 /**
104 * Gets the active.
105 *
106 * @return active
107 *
108 * @see com.jamonapi.Monitor#getActive()
109 */
110 public double getActive() {
111 return monitor.getActive();
112 }
113
114 /**
115 * Gets the average
116 *
117 * @return average
118 *
119 * @see com.jamonapi.Monitor#getAvg()
120 */
121 public double getAvg() {
122 return monitor.getAvg();
123 }
124
125 /**
126 * Gets the active average
127 *
128 * @return average active
129 *
130 * @see com.jamonapi.Monitor#getAvgActive()
131 */
132 public double getAvgActive() {
133 return monitor.getAvgActive();
134 }
135
136 /**
137 * Gets the global active average
138 *
139 * @return average global active
140 *
141 * @see com.jamonapi.Monitor#getAvgGlobalActive()
142 */
143 public double getAvgGlobalActive() {
144 return monitor.getAvgGlobalActive();
145 }
146
147 /**
148 * Gets the primary active average.
149 *
150 * @return average primary active
151 *
152 * @see com.jamonapi.Monitor#getAvgPrimaryActive()
153 */
154 public double getAvgPrimaryActive() {
155 return monitor.getAvgPrimaryActive();
156 }
157
158 /**
159 * Gets the first access.
160 *
161 * @return first access
162 *
163 * @see com.jamonapi.Monitor#getFirstAccess()
164 */
165 public Date getFirstAccess() {
166 return monitor.getFirstAccess();
167 }
168
169 /**
170 * Gets the hits.
171 *
172 * @return number of hits
173 *
174 * @see com.jamonapi.Monitor#getHits()
175 */
176 public int getHits() {
177 return (int) monitor.getHits();
178 }
179
180 /**
181 * Gets the label.
182 *
183 * @return label
184 *
185 * @see com.jamonapi.Monitor#getLabel()
186 */
187 public String getLabel() {
188 return monitor.getLabel();
189 }
190
191 /**
192 * Gets the last access.
193 *
194 * @return last access
195 *
196 * @see com.jamonapi.Monitor#getLastAccess()
197 */
198 public Date getLastAccess() {
199 return monitor.getLastAccess();
200 }
201
202 /**
203 * Gets the last value.
204 *
205 * @return last value
206 *
207 * @see com.jamonapi.Monitor#getLastValue()
208 */
209 public double getLastValue() {
210 return monitor.getLastValue();
211 }
212
213 /**
214 * Gets the listener type.
215 *
216 * @param listenerType the listener type
217 *
218 * @return listener type
219 *
220 * @see com.jamonapi.Monitor#getListenerType(java.lang.String)
221 */
222 public ListenerType getListenerType(final String listenerType) {
223 return monitor.getListenerType(listenerType);
224 }
225
226 /**
227 * Gets the max.
228 *
229 * @return maximum
230 *
231 * @see com.jamonapi.Monitor#getMax()
232 */
233 public double getMax() {
234 return monitor.getMax();
235 }
236
237 /**
238 * Gets the max active.
239 *
240 * @return maximal active
241 *
242 * @see com.jamonapi.Monitor#getMaxActive()
243 */
244 public double getMaxActive() {
245 return monitor.getMaxActive();
246 }
247
248 /**
249 * Gets the min.
250 *
251 * @return minimum
252 *
253 * @see com.jamonapi.Monitor#getMin()
254 */
255 public double getMin() {
256 return monitor.getMin();
257 }
258
259 /**
260 * Gets the monitors.
261 *
262 * @return monitors
263 *
264 * @see com.jamonapi.MonitorComposite#getMonitors()
265 */
266 @UnsupportedOperation
267 public ProfileMonitor[] getMonitors() {
268 return null;
269 }
270
271 /**
272 * Gets the mon key.
273 *
274 * @return monitor key
275 *
276 * @see com.jamonapi.Monitor#getMonKey()
277 */
278 public MonKey getMonKey() {
279 return monitor.getMonKey();
280 }
281
282 /**
283 * Gets the range.
284 *
285 * @return range
286 *
287 * @see com.jamonapi.Monitor#getRange()
288 */
289 public Range getRange() {
290 return monitor.getRange();
291 }
292
293 /**
294 * Gets the std dev.
295 *
296 * @return standard dev
297 *
298 * @see com.jamonapi.Monitor#getStdDev()
299 */
300 public double getStdDev() {
301 return monitor.getStdDev();
302 }
303
304 /**
305 * Gets the total.
306 *
307 * @return total
308 *
309 * @see com.jamonapi.Monitor#getTotal()
310 */
311 public double getTotal() {
312 return monitor.getTotal();
313 }
314
315 /**
316 * Gets the units.
317 *
318 * @return units
319 *
320 * @see com.jamonapi.Monitor#getUnits()
321 */
322 public String getUnits() {
323 return monitor.getUnits();
324 }
325
326 /**
327 * Hash code.
328 *
329 * @return hash code
330 *
331 * @see java.lang.Object#hashCode()
332 */
333 @Override
334 public int hashCode() {
335 return monitor.hashCode();
336 }
337
338 /**
339 * Checks for listeners.
340 *
341 * @return true if object has listeners
342 *
343 * @see com.jamonapi.Monitor#hasListeners()
344 */
345 public boolean hasListeners() {
346 return monitor.hasListeners();
347 }
348
349 /**
350 * Checks if is activity tracking.
351 *
352 * @return activity tracking
353 *
354 * @see com.jamonapi.Monitor#isActivityTracking()
355 */
356 public boolean isActivityTracking() {
357 return monitor.isActivityTracking();
358 }
359
360 /**
361 * Checks if is enabled.
362 *
363 * @return true if enabled
364 *
365 * @see com.jamonapi.Monitor#isEnabled()
366 */
367 public boolean isEnabled() {
368 return monitor.isEnabled();
369 }
370
371 /**
372 * Checks if is primary.
373 *
374 * @return true if primary
375 *
376 * @see com.jamonapi.Monitor#isPrimary()
377 */
378 public boolean isPrimary() {
379 return monitor.isPrimary();
380 }
381
382 /**
383 * Reset.
384 *
385 * @see com.jamonapi.Monitor#reset()
386 */
387 public void reset() {
388 monitor.reset();
389 }
390
391 /**
392 * Sets the access stats.
393 *
394 * @param now the now
395 *
396 * @see com.jamonapi.Monitor#setAccessStats(long)
397 */
398 public void setAccessStats(final long now) {
399 monitor.setAccessStats(now);
400 }
401
402 /**
403 * Sets the active.
404 *
405 * @param arg0 the arg0
406 *
407 * @see com.jamonapi.Monitor#setActive(double)
408 */
409 public void setActive(final double arg0) {
410 monitor.setActive(arg0);
411 }
412
413 /**
414 * Sets the activity tracking.
415 *
416 * @param arg0 the arg0
417 *
418 * @see com.jamonapi.Monitor#setActivityTracking(boolean)
419 */
420 public void setActivityTracking(final boolean arg0) {
421 monitor.setActivityTracking(arg0);
422 }
423
424 /**
425 * Sets the first access.
426 *
427 * @param arg0 the arg0
428 *
429 * @see com.jamonapi.Monitor#setFirstAccess(java.util.Date)
430 */
431 public void setFirstAccess(final Date arg0) {
432 monitor.setFirstAccess(arg0);
433 }
434
435 /**
436 * Sets the hits.
437 *
438 * @param arg0 the arg0
439 *
440 * @see com.jamonapi.Monitor#setHits(double)
441 */
442 public void setHits(final double arg0) {
443 monitor.setHits(arg0);
444 }
445
446 /**
447 * Sets the last access.
448 *
449 * @param arg0 the arg0
450 *
451 * @see com.jamonapi.Monitor#setLastAccess(java.util.Date)
452 */
453 public void setLastAccess(final Date arg0) {
454 monitor.setLastAccess(arg0);
455 }
456
457 /**
458 * Sets the last value.
459 *
460 * @param arg0 the arg0
461 *
462 * @see com.jamonapi.Monitor#setLastValue(double)
463 */
464 public void setLastValue(final double arg0) {
465 monitor.setLastValue(arg0);
466 }
467
468 /**
469 * Sets the max.
470 *
471 * @param arg0 the arg0
472 *
473 * @see com.jamonapi.Monitor#setMax(double)
474 */
475 public void setMax(final double arg0) {
476 monitor.setMax(arg0);
477 }
478
479 /**
480 * Sets the max active.
481 *
482 * @param arg0 the arg0
483 *
484 * @see com.jamonapi.Monitor#setMaxActive(double)
485 */
486 public void setMaxActive(final double arg0) {
487 monitor.setMaxActive(arg0);
488 }
489
490 /**
491 * Sets the min.
492 *
493 * @param arg0 the arg0
494 *
495 * @see com.jamonapi.Monitor#setMin(double)
496 */
497 public void setMin(final double arg0) {
498 monitor.setMin(arg0);
499 }
500
501 /**
502 * Sets the primary.
503 *
504 * @param arg0 the arg0
505 *
506 * @see com.jamonapi.Monitor#setPrimary(boolean)
507 */
508 public void setPrimary(final boolean arg0) {
509 monitor.setPrimary(arg0);
510 }
511
512 /**
513 * Sets the total.
514 *
515 * @param arg0 the arg0
516 *
517 * @see com.jamonapi.Monitor#setTotal(double)
518 */
519 public void setTotal(final double arg0) {
520 monitor.setTotal(arg0);
521 }
522
523 /**
524 * Sets the total active.
525 *
526 * @param arg0 the arg0
527 *
528 * @see com.jamonapi.Monitor#setTotalActive(double)
529 */
530 public void setTotalActive(final double arg0) {
531 monitor.setTotalActive(arg0);
532 }
533
534 /**
535 * Start.
536 *
537 * @see com.jamonapi.Monitor#start()
538 */
539 public void start() {
540 monitor.start();
541 }
542
543 /**
544 * Stop.
545 *
546 * @see com.jamonapi.Monitor#stop()
547 */
548 public void stop() {
549 monitor.stop();
550 }
551
552 /**
553 * To string.
554 *
555 * @return e.g. "JAMon Label=void patterntesting.runtime.monitor.ProfileTest.testProfiler(), Units=ms.:"
556 * + " (LastValue=8.0, Hits=1.0, Avg=8.0, Total=8.0, Min=8.0, Max=8.0, Active=1.0, Avg Active=3.0,"
557 * + " Max Active=2.0, First Access=Sat Dec 27 17:31:09 CET 2008, Last Access=Sat Dec 27 17:31:09 CET 2008)"
558 *
559 * @see com.jamonapi.Monitor#toString()
560 */
561 @Override
562 public String toString() {
563 return monitor.toString();
564 }
565
566 /**
567 * @see patterntesting.runtime.monitor.ProfileMonitor#toShortString()
568 */
569 public String toShortString() {
570 return "Hits=" + (long) monitor.getHits() + ", Avg=" + monitor.getAvg()
571 + ", Total=" + monitor.getTotal() + ", Max=" + monitor.getMax()
572 + ", Unit=" + monitor.getUnits();
573 }
574
575 /**
576 * @see patterntesting.runtime.monitor.ProfileMonitor#toCsvHeadline()
577 */
578 public String toCsvHeadline() {
579 return "Label; Unit; LastValue; Hits; Avg; Total; Min; Max; Active; Avg Active; Max Active; First Access; Last Access;";
580 }
581
582 /**
583 * @see patterntesting.runtime.monitor.ProfileMonitor#toCsvString()
584 */
585 public String toCsvString() {
586 return '"' + monitor.getLabel() + "\"; " + monitor.getUnits() + "; "
587 + monitor.getLastValue() + "; " + (long) monitor.getHits()
588 + "; " + monitor.getAvg() + "; " + monitor.getTotal() + "; "
589 + monitor.getMin() + "; " + monitor.getMax() + "; "
590 + monitor.getActive() + "; " + monitor.getAvgActive() + "; "
591 + monitor.getMaxActive() + "; " + monitor.getFirstAccess()
592 + "; " + monitor.getLastAccess() + ";";
593 }
594
595 }
596
597 /**
598 * $Log: JamonMonitor.java,v $
599 * Revision 1.4 2014/04/28 17:36:37 oboehm
600 * label is now quoted by dumpStatistic...
601 *
602 * Revision 1.3 2010/06/08 21:32:53 oboehm
603 * nearly half of the checkstyle warnings fixed
604 *
605 * Revision 1.2 2010/04/22 18:27:19 oboehm
606 * code cleanup of src/main/java
607 *
608 * Revision 1.1 2010/01/05 13:26:17 oboehm
609 * begin with 1.0
610 *
611 * Revision 1.13 2009/12/28 10:07:23 oboehm
612 * missing Javadocs completed
613 *
614 * Revision 1.12 2009/12/20 15:18:10 oboehm
615 * FindBugs and Checkstyle warnings fixed
616 * ready for delivery
617 *
618 * Revision 1.11 2009/12/19 22:34:09 oboehm
619 * trailing spaces removed
620 *
621 * Revision 1.10 2009/12/05 22:46:29 oboehm
622 * RunTestsParallel annotation added
623 *
624 * Revision 1.9 2009/11/26 21:19:25 oboehm
625 * some findbugs fixed
626 *
627 * Revision 1.8 2009/09/25 14:49:43 oboehm
628 * javadocs completed with the help of JAutodoc
629 *
630 * Revision 1.7 2009/09/18 13:54:52 oboehm
631 * javadoc warnings fixed
632 *
633 * Revision 1.6 2009/09/03 14:10:06 oboehm
634 * support for JAMon 2.7 added
635 *
636 * $Source: /cvsroot/patterntesting/PatternTesting10/patterntesting-rt/src/main/java/patterntesting/runtime/monitor/JamonMonitor.java,v $
637 */