1
18 package net.bull.javamelody.internal.model;
19
20 import java.io.Serializable;
21
22
26 public class CounterRequestRumData implements Serializable, Cloneable {
27 private static final long serialVersionUID = 745110095604593659L;
28
29
30 private static final long ABERRANT_VALUE = 5 * 60 * 1000;
31
32 private long hits;
33 private long networkTimeSum;
34 private long domProcessingSum;
35 private long pageRenderingSum;
36
37 public long getHits() {
38 return hits;
39 }
40
41 public int getNetworkTimeMean() {
42 if (hits > 0) {
43 return (int) (networkTimeSum / hits);
44 }
45 return -1;
46 }
47
48 public int getDomProcessingMean() {
49 if (hits > 0) {
50 return (int) (domProcessingSum / hits);
51 }
52 return -1;
53 }
54
55 public int getPageRenderingMean() {
56 if (hits > 0) {
57 return (int) (pageRenderingSum / hits);
58 }
59 return -1;
60 }
61
62 void addHit(long networkTime, long domProcessing, long pageRendering) {
63 if (networkTime < 0 || networkTime > ABERRANT_VALUE || domProcessing < 0
64 || domProcessing > ABERRANT_VALUE || pageRendering < 0
65 || pageRendering > ABERRANT_VALUE) {
66
67 return;
68 }
69
70 networkTimeSum += networkTime;
71 domProcessingSum += domProcessing;
72 pageRenderingSum += pageRendering;
73 hits++;
74 }
75
76 void addHits(CounterRequestRumData rumData) {
77 if (rumData.hits != 0) {
78 hits += rumData.hits;
79 networkTimeSum += rumData.networkTimeSum;
80 domProcessingSum += rumData.domProcessingSum;
81 pageRenderingSum += rumData.pageRenderingSum;
82 }
83 }
84
85 void removeHits(CounterRequestRumData rumData) {
86 if (rumData.hits != 0) {
87 hits -= rumData.hits;
88 networkTimeSum -= rumData.networkTimeSum;
89 domProcessingSum -= rumData.domProcessingSum;
90 pageRenderingSum -= rumData.pageRenderingSum;
91 }
92 }
93
94
95 @Override
96 public CounterRequestRumData clone() {
97 try {
98 return (CounterRequestRumData) super.clone();
99 } catch (final CloneNotSupportedException e) {
100
101 throw new IllegalStateException(e);
102 }
103 }
104
105
106 @Override
107 public String toString() {
108 return getClass().getSimpleName() + "[hits=" + hits + ']';
109 }
110 }
111