1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package com.ebay.carad.os.vitalsigns.dataretrievers;
22
23 import org.apache.log4j.Logger;
24
25
26 /***
27 * <p>Takes the output of a simple one-cell query (column name "data") from the DB and logs
28 * the DIFFERENCE between the last time the query was run and the current run. The first
29 * time it is invoked it does not log anything.</p>
30 *
31 * <p>Data that is logged = <tt>CurrentCount - LastCount</tt></p>
32 *
33 * @author Jeremy Kraybill
34 * @author Jeremy Thomerson
35 * @version $Id$
36 */
37 public class DifferenceQueryLogger extends QueryLogger {
38
39 private static final Logger LOGGER = Logger.getLogger(DifferenceQueryLogger.class);
40 private Float lastCount = null;
41
42 /***
43 * Basic constructor.
44 */
45 public DifferenceQueryLogger() {
46 super();
47 }
48
49 /***
50 * @see DifferenceQueryLogger class comment for details
51 * @see com.ebay.carad.os.vitalsigns.dataretrievers.QueryLogger#getValue()
52 */
53 public Float getValue() {
54 Float diff = null;
55 if (lastCount == null) {
56 lastCount = super.getValue();
57 } else {
58 Float curCount = super.getValue();
59 diff = new Float(curCount.floatValue() - lastCount.floatValue());
60 lastCount = curCount;
61 }
62 return diff;
63 }
64
65 public Float getData() {
66 Float value = ZERO;
67 try {
68 value = getValue();
69 } catch (Exception e) {
70 LOGGER.error(e);
71 }
72 return value;
73 }
74 }