1 17 18 package com.whirlycott.cache; 19 20 import java.io.Serializable ; 21 22 27 public class RecordKeeper implements Serializable { 28 29 32 private static final long serialVersionUID = -8354128118267818665L; 33 34 35 private volatile long hits; 36 37 38 private final Object hitLock = new Object (); 39 40 41 private volatile long totalOperations; 42 43 44 private final Object operationLock = new Object (); 45 46 private long totalOperationsStartTuneCycle; 47 48 private long queriesPerSecond; 49 50 53 public long getHits() { 54 return hits; 55 } 56 57 61 public void setHits(final long hits) { 62 this.hits = hits; 63 } 64 65 68 public long getTotalOperations() { 69 return totalOperations; 70 } 71 72 73 public void incrementTotalOperations() { 74 synchronized (operationLock) { 75 totalOperations++; 76 } 77 } 78 79 80 public void incrementHits() { 81 synchronized (hitLock) { 82 hits++; 83 } 84 } 85 86 public void startTuneCycle() { 87 totalOperationsStartTuneCycle = totalOperations; 88 } 89 90 public void calculateQueriesPerSecond(final long sleepTime) { 91 if (sleepTime > 0L) { 92 queriesPerSecond = (totalOperations - totalOperationsStartTuneCycle) / (sleepTime / 1000L); 93 } else { 94 queriesPerSecond = 0; 95 } 96 } 97 98 public long getQueriesPerSecond() { 99 return queriesPerSecond; 100 } 101 102 105 public void reset() { 106 totalOperations = 0L; 107 hits = 0L; 108 } 109 } 110 | Popular Tags |