PageRenderTime 34ms CodeModel.GetById 13ms app.highlight 15ms RepoModel.GetById 2ms app.codeStats 0ms

/hazelcast/src/main/java/com/hazelcast/impl/monitor/AtomicNumberOperationsCounter.java

https://bitbucket.org/gabral6_gmailcom/hazelcast
Java | 80 lines | 52 code | 13 blank | 15 comment | 1 complexity | 07655dedd9d25660ad2e22aa825570c1 MD5 | raw file
 1/*
 2 * Copyright (c) 2008-2013, Hazelcast, Inc. All Rights Reserved.
 3 *
 4 * Licensed under the Apache License, Version 2.0 (the "License");
 5 * you may not use this file except in compliance with the License.
 6 * You may obtain a copy of the License at
 7 *
 8 * http://www.apache.org/licenses/LICENSE-2.0
 9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.hazelcast.impl.monitor;
18
19import com.hazelcast.monitor.LocalAtomicNumberOperationStats;
20
21public class AtomicNumberOperationsCounter extends OperationsCounterSupport<LocalAtomicNumberOperationStats> {
22
23    final private static LocalAtomicNumberOperationStats empty = new LocalAtomicNumberOperationStatsImpl();
24
25    private OperationCounter modified = new OperationCounter();
26    private OperationCounter nonModified = new OperationCounter();
27
28    public AtomicNumberOperationsCounter() {
29        super();
30    }
31
32    public AtomicNumberOperationsCounter(long interval) {
33        super(interval);
34    }
35
36    public void incrementModified(long elapsed) {
37        modified.count(elapsed);
38        publishSubResult();
39    }
40
41    public void incrementNonModified(long elapsed) {
42        nonModified.count(elapsed);
43        publishSubResult();
44    }
45
46    LocalAtomicNumberOperationStats aggregateSubCounterStats() {
47        LocalAtomicNumberOperationStatsImpl stats = new LocalAtomicNumberOperationStatsImpl();
48        stats.periodStart = ((AtomicNumberOperationsCounter) listOfSubCounters.get(0)).startTime;
49        for (Object obj : listOfSubCounters) {
50            AtomicNumberOperationsCounter sub = (AtomicNumberOperationsCounter) obj;
51            stats.modified.add(sub.modified.count.get(), sub.modified.totalLatency.get());
52            stats.nonModified.add(sub.nonModified.count.get(), sub.nonModified.totalLatency.get());
53            stats.periodEnd = sub.endTime;
54        }
55        return stats;
56    }
57
58    AtomicNumberOperationsCounter getAndReset() {
59        AtomicNumberOperationsCounter newOne = new AtomicNumberOperationsCounter();
60        newOne.modified.set(modified.copyAndReset());
61        newOne.nonModified.set(nonModified.copyAndReset());
62        newOne.startTime = this.startTime;
63        newOne.endTime = now();
64        this.startTime = newOne.endTime;
65        return newOne;
66    }
67
68    LocalAtomicNumberOperationStats getThis() {
69        LocalAtomicNumberOperationStatsImpl stats = new LocalAtomicNumberOperationStatsImpl();
70        stats.periodStart = this.startTime;
71        stats.modified = stats.new OperationStat(this.modified.count.get(), this.modified.totalLatency.get());
72        stats.nonModified = stats.new OperationStat(this.nonModified.count.get(), this.nonModified.totalLatency.get());
73        stats.periodEnd = now();
74        return stats;
75    }
76
77    LocalAtomicNumberOperationStats getEmpty() {
78        return empty;
79    }
80}