View Javadoc
1   /*
2    * ====================================================================
3    * Licensed to the Apache Software Foundation (ASF) under one
4    * or more contributor license agreements.  See the NOTICE file
5    * distributed with this work for additional information
6    * regarding copyright ownership.  The ASF licenses this file
7    * to you under the Apache License, Version 2.0 (the
8    * "License"); you may not use this file except in compliance
9    * with the License.  You may obtain a copy of the License at
10   *
11   *   http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing,
14   * software distributed under the License is distributed on an
15   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16   * KIND, either express or implied.  See the License for the
17   * specific language governing permissions and limitations
18   * under the License.
19   * ====================================================================
20   *
21   * This software consists of voluntary contributions made by many
22   * individuals on behalf of the Apache Software Foundation.  For more
23   * information on the Apache Software Foundation, please see
24   * <http://www.apache.org/>.
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   * Statistics for an {@link HttpBenchmark HttpBenchmark}.
37   *
38   * @since 4.0
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 }