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

https://bitbucket.org/gabral6_gmailcom/hazelcast · Java · 108 lines · 74 code · 19 blank · 15 comment · 4 complexity · 254f94020d053f30d11ea224566fbbf6 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.LocalExecutorOperationStats;
  18. import java.io.DataInput;
  19. import java.io.DataOutput;
  20. import java.io.IOException;
  21. import java.util.concurrent.atomic.AtomicLong;
  22. public class LocalExecutorOperationStatsImpl extends LocalOperationStatsSupport implements LocalExecutorOperationStats {
  23. private String executorName;
  24. final AtomicLong pending = new AtomicLong(0);
  25. final AtomicLong started = new AtomicLong(0);
  26. final AtomicLong startLatency = new AtomicLong(0);
  27. final AtomicLong completed = new AtomicLong(0);
  28. final AtomicLong completionTime = new AtomicLong(0);
  29. final AtomicLong minCompletionTime = new AtomicLong(Long.MAX_VALUE);
  30. final AtomicLong maxCompletionTime = new AtomicLong(Long.MIN_VALUE);
  31. public LocalExecutorOperationStatsImpl(String executorName) {
  32. this.executorName = executorName;
  33. }
  34. public String getExecutorName() {
  35. return executorName;
  36. }
  37. public long getPending() {
  38. return pending.get();
  39. }
  40. public long getStarted() {
  41. return started.get();
  42. }
  43. public long getStartLatency() {
  44. return startLatency.get();
  45. }
  46. public long getAverageStartLatency() {
  47. if(started.get() == 0)
  48. return 0;
  49. return startLatency.get() / started.get();
  50. }
  51. public long getCompleted() {
  52. return completed.get();
  53. }
  54. public long getCompletionTime() {
  55. return completionTime.get();
  56. }
  57. public long getMinCompletionTime() {
  58. return minCompletionTime.get();
  59. }
  60. public long getAverageCompletionTime() {
  61. if(completed.get() == 0) {
  62. return 0;
  63. }
  64. return completionTime.get() / completed.get();
  65. }
  66. public long getMaxCompletionTime() {
  67. return maxCompletionTime.get();
  68. }
  69. public void writeDataInternal(DataOutput out) throws IOException {
  70. out.writeUTF(executorName);
  71. out.writeLong(pending.get());
  72. out.writeLong(started.get());
  73. out.writeLong(startLatency.get());
  74. out.writeLong(completed.get());
  75. out.writeLong(completionTime.get());
  76. out.writeLong(minCompletionTime.get());
  77. out.writeLong(maxCompletionTime.get());
  78. }
  79. public void readDataInternal(DataInput in) throws IOException {
  80. executorName = in.readUTF();
  81. pending.set(in.readLong());
  82. started.set(in.readLong());
  83. startLatency.set(in.readLong());
  84. completed.set(in.readLong());
  85. completionTime.set(in.readLong());
  86. minCompletionTime.set(in.readLong());
  87. maxCompletionTime.set(in.readLong());
  88. }
  89. }