/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. package com.hazelcast.impl.monitor;
  17. import com.hazelcast.monitor.LocalAtomicNumberOperationStats;
  18. public class AtomicNumberOperationsCounter extends OperationsCounterSupport<LocalAtomicNumberOperationStats> {
  19. final private static LocalAtomicNumberOperationStats empty = new LocalAtomicNumberOperationStatsImpl();
  20. private OperationCounter modified = new OperationCounter();
  21. private OperationCounter nonModified = new OperationCounter();
  22. public AtomicNumberOperationsCounter() {
  23. super();
  24. }
  25. public AtomicNumberOperationsCounter(long interval) {
  26. super(interval);
  27. }
  28. public void incrementModified(long elapsed) {
  29. modified.count(elapsed);
  30. publishSubResult();
  31. }
  32. public void incrementNonModified(long elapsed) {
  33. nonModified.count(elapsed);
  34. publishSubResult();
  35. }
  36. LocalAtomicNumberOperationStats aggregateSubCounterStats() {
  37. LocalAtomicNumberOperationStatsImpl stats = new LocalAtomicNumberOperationStatsImpl();
  38. stats.periodStart = ((AtomicNumberOperationsCounter) listOfSubCounters.get(0)).startTime;
  39. for (Object obj : listOfSubCounters) {
  40. AtomicNumberOperationsCounter sub = (AtomicNumberOperationsCounter) obj;
  41. stats.modified.add(sub.modified.count.get(), sub.modified.totalLatency.get());
  42. stats.nonModified.add(sub.nonModified.count.get(), sub.nonModified.totalLatency.get());
  43. stats.periodEnd = sub.endTime;
  44. }
  45. return stats;
  46. }
  47. AtomicNumberOperationsCounter getAndReset() {
  48. AtomicNumberOperationsCounter newOne = new AtomicNumberOperationsCounter();
  49. newOne.modified.set(modified.copyAndReset());
  50. newOne.nonModified.set(nonModified.copyAndReset());
  51. newOne.startTime = this.startTime;
  52. newOne.endTime = now();
  53. this.startTime = newOne.endTime;
  54. return newOne;
  55. }
  56. LocalAtomicNumberOperationStats getThis() {
  57. LocalAtomicNumberOperationStatsImpl stats = new LocalAtomicNumberOperationStatsImpl();
  58. stats.periodStart = this.startTime;
  59. stats.modified = stats.new OperationStat(this.modified.count.get(), this.modified.totalLatency.get());
  60. stats.nonModified = stats.new OperationStat(this.nonModified.count.get(), this.nonModified.totalLatency.get());
  61. stats.periodEnd = now();
  62. return stats;
  63. }
  64. LocalAtomicNumberOperationStats getEmpty() {
  65. return empty;
  66. }
  67. }