1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27 package org.apache.hc.core5.benchmark;
28
29 import java.util.concurrent.atomic.AtomicInteger;
30 import java.util.concurrent.atomic.AtomicLong;
31 import java.util.concurrent.atomic.AtomicReference;
32
33 import org.apache.hc.core5.http.ProtocolVersion;
34
35
36
37
38
39
40 public class Stats {
41
42 private final AtomicInteger successCount = new AtomicInteger();
43 private final AtomicInteger failureCount = new AtomicInteger();
44 private final AtomicInteger keepAliveCount = new AtomicInteger();
45 private final AtomicLong totalBytesRecv = new AtomicLong();
46 private final AtomicLong totalBytesSent = new AtomicLong();
47 private final AtomicLong contentLength = new AtomicLong();
48 private final AtomicLong totalContentLength = new AtomicLong();
49 private final AtomicReference<String> serverNameRef = new AtomicReference<>();
50 private final AtomicReference<ProtocolVersion> versionRef = new AtomicReference<>();
51
52 public void incSuccessCount() {
53 this.successCount.incrementAndGet();
54 }
55
56 public int getSuccessCount() {
57 return this.successCount.get();
58 }
59
60 public void incFailureCount() {
61 this.failureCount.incrementAndGet();
62 }
63
64 public int getFailureCount() {
65 return this.failureCount.get();
66 }
67
68 public void incKeepAliveCount() {
69 this.keepAliveCount.incrementAndGet();
70 }
71
72 public int getKeepAliveCount() {
73 return this.keepAliveCount.get();
74 }
75
76 public void incTotalBytesRecv(final int n) {
77 this.totalBytesRecv.addAndGet(n);
78 }
79
80 public long getTotalBytesRecv() {
81 return this.totalBytesRecv.get();
82 }
83
84 public void incTotalBytesSent(final int n) {
85 this.totalBytesSent.addAndGet(n);
86 }
87
88 public long getTotalBytesSent() {
89 return this.totalBytesSent.get();
90 }
91
92 public void setContentLength(final long n) {
93 this.contentLength.set(n);
94 }
95
96 public void incTotalContentLength(final long n) {
97 this.totalContentLength.addAndGet(n);
98 }
99
100 public long getContentLength() {
101 return this.contentLength.get();
102 }
103
104 public long getTotalContentLength() {
105 return this.totalContentLength.get();
106 }
107
108 public void setServerName(final String serverName) {
109 this.serverNameRef.set(serverName);
110 }
111
112 public String getServerName() {
113 return this.serverNameRef.get();
114 }
115
116 public ProtocolVersion getVersion() {
117 return versionRef.get();
118 }
119
120 public void setVersion(final ProtocolVersion version) {
121 this.versionRef.set(version);
122 }
123
124 @Override
125 public String toString() {
126 return "Stats{" +
127 "successCount=" + successCount +
128 ", failureCount=" + failureCount +
129 ", keepAliveCount=" + keepAliveCount +
130 ", serverName=" + serverNameRef.get() +
131 ", totalBytesRecv=" + totalBytesRecv +
132 ", totalBytesSent=" + totalBytesSent +
133 ", contentLength=" + contentLength +
134 '}';
135 }
136
137 }