hefeixia
2021-02-18 5b8c95c760840f09910730943b21391e47187315
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
package chat.server.moquette;
 
import java.util.concurrent.atomic.AtomicLong;
 
public class BytesMetricsCollector {
 
    private AtomicLong readBytes = new AtomicLong();
    private AtomicLong wroteBytes = new AtomicLong();
 
    public Metrics computeMetrics() {
        Metrics allMetrics = new Metrics();
        allMetrics.incrementRead(readBytes.get());
        allMetrics.incrementWrote(wroteBytes.get());
        return allMetrics;
    }
 
    public void sumReadBytes(long count) {
        readBytes.getAndAdd(count);
    }
 
    public void sumWroteBytes(long count) {
        wroteBytes.getAndAdd(count);
    }
}