Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
com.hazelcast.monitor.impl.LocalMapStatsImpl Maven / Gradle / Ivy
/*
* Copyright (c) 2008-2015, Hazelcast, Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.hazelcast.monitor.impl;
import com.hazelcast.com.hazelcast.com.eclipsesource.json.JsonObject;
import com.hazelcast.com.hazelcast.com.eclipsesource.json.JsonValue;
import com.hazelcast.monitor.LocalMapStats;
import com.hazelcast.util.Clock;
import java.util.concurrent.atomic.AtomicLongFieldUpdater;
import static com.hazelcast.util.JsonUtil.getInt;
import static com.hazelcast.util.JsonUtil.getLong;
/**
* Default implementation of {@link LocalMapStats}
*/
public class LocalMapStatsImpl implements LocalMapStats {
private static final AtomicLongFieldUpdater LAST_ACCESS_TIME_UPDATER = AtomicLongFieldUpdater
.newUpdater(LocalMapStatsImpl.class, "lastAccessTime");
private static final AtomicLongFieldUpdater LAST_UPDATE_TIME_UPDATER = AtomicLongFieldUpdater
.newUpdater(LocalMapStatsImpl.class, "lastUpdateTime");
private static final AtomicLongFieldUpdater NUMBER_OF_OTHER_OPERATIONS_UPDATER = AtomicLongFieldUpdater
.newUpdater(LocalMapStatsImpl.class, "numberOfOtherOperations");
private static final AtomicLongFieldUpdater NUMBER_OF_EVENTS_UPDATER = AtomicLongFieldUpdater
.newUpdater(LocalMapStatsImpl.class, "numberOfEvents");
private static final AtomicLongFieldUpdater GET_COUNT_UPDATER = AtomicLongFieldUpdater
.newUpdater(LocalMapStatsImpl.class, "getCount");
private static final AtomicLongFieldUpdater PUT_COUNT_UPDATER = AtomicLongFieldUpdater
.newUpdater(LocalMapStatsImpl.class, "putCount");
private static final AtomicLongFieldUpdater REMOVE_COUNT_UPDATER = AtomicLongFieldUpdater
.newUpdater(LocalMapStatsImpl.class, "removeCount");
private static final AtomicLongFieldUpdater TOTAL_GET_LATENCIES_UPDATER = AtomicLongFieldUpdater
.newUpdater(LocalMapStatsImpl.class, "totalGetLatencies");
private static final AtomicLongFieldUpdater TOTAL_PUT_LATENCIES_UPDATER = AtomicLongFieldUpdater
.newUpdater(LocalMapStatsImpl.class, "totalPutLatencies");
private static final AtomicLongFieldUpdater TOTAL_REMOVE_LATENCIES_UPDATER = AtomicLongFieldUpdater
.newUpdater(LocalMapStatsImpl.class, "totalRemoveLatencies");
private static final AtomicLongFieldUpdater MAX_GET_LATENCY_UPDATER = AtomicLongFieldUpdater
.newUpdater(LocalMapStatsImpl.class, "maxGetLatency");
private static final AtomicLongFieldUpdater MAX_PUT_LATENCY_UPDATER = AtomicLongFieldUpdater
.newUpdater(LocalMapStatsImpl.class, "maxPutLatency");
private static final AtomicLongFieldUpdater MAX_REMOVE_LATENCY_UPDATER = AtomicLongFieldUpdater
.newUpdater(LocalMapStatsImpl.class, "maxRemoveLatency");
// These fields are only accessed through the updaters
private volatile long lastAccessTime;
private volatile long lastUpdateTime;
private volatile long hits;
private volatile long numberOfOtherOperations;
private volatile long numberOfEvents;
private volatile long getCount;
private volatile long putCount;
private volatile long removeCount;
private volatile long totalGetLatencies;
private volatile long totalPutLatencies;
private volatile long totalRemoveLatencies;
private volatile long maxGetLatency;
private volatile long maxPutLatency;
private volatile long maxRemoveLatency;
private volatile long creationTime;
private volatile long ownedEntryCount;
private volatile long backupEntryCount;
private volatile long ownedEntryMemoryCost;
private volatile long backupEntryMemoryCost;
/**
* Holds total heap cost of map & near-cache & backups.
*/
private volatile long heapCost;
private volatile long lockedEntryCount;
private volatile long dirtyEntryCount;
private volatile int backupCount;
private volatile NearCacheStatsImpl nearCacheStats;
public LocalMapStatsImpl() {
creationTime = Clock.currentTimeMillis();
}
@Override
public long getOwnedEntryCount() {
return ownedEntryCount;
}
public void setOwnedEntryCount(long ownedEntryCount) {
this.ownedEntryCount = ownedEntryCount;
}
@Override
public long getBackupEntryCount() {
return backupEntryCount;
}
public void setBackupEntryCount(long backupEntryCount) {
this.backupEntryCount = backupEntryCount;
}
@Override
public int getBackupCount() {
return backupCount;
}
public void setBackupCount(int backupCount) {
this.backupCount = backupCount;
}
@Override
public long getOwnedEntryMemoryCost() {
return ownedEntryMemoryCost;
}
public void setOwnedEntryMemoryCost(long ownedEntryMemoryCost) {
this.ownedEntryMemoryCost = ownedEntryMemoryCost;
}
@Override
public long getBackupEntryMemoryCost() {
return backupEntryMemoryCost;
}
public void setBackupEntryMemoryCost(long backupEntryMemoryCost) {
this.backupEntryMemoryCost = backupEntryMemoryCost;
}
@Override
public long getCreationTime() {
return creationTime;
}
@Override
public long getLastAccessTime() {
return lastAccessTime;
}
public void setLastAccessTime(long lastAccessTime) {
LAST_ACCESS_TIME_UPDATER.set(this, Math.max(this.lastAccessTime, lastAccessTime));
}
@Override
public long getLastUpdateTime() {
return lastUpdateTime;
}
public void setLastUpdateTime(long lastUpdateTime) {
LAST_UPDATE_TIME_UPDATER.set(this, Math.max(this.lastUpdateTime, lastUpdateTime));
}
@Override
public long getHits() {
return hits;
}
public void setHits(long hits) {
this.hits = hits;
}
@Override
public long getLockedEntryCount() {
return lockedEntryCount;
}
public void setLockedEntryCount(long lockedEntryCount) {
this.lockedEntryCount = lockedEntryCount;
}
@Override
public long getDirtyEntryCount() {
return dirtyEntryCount;
}
public void setDirtyEntryCount(long dirtyEntryCount) {
this.dirtyEntryCount = dirtyEntryCount;
}
@Override
public long total() {
return putCount + getCount + removeCount + numberOfOtherOperations;
}
@Override
public long getPutOperationCount() {
return putCount;
}
public void incrementPuts(long latency) {
PUT_COUNT_UPDATER.incrementAndGet(this);
TOTAL_PUT_LATENCIES_UPDATER.addAndGet(this, latency);
MAX_PUT_LATENCY_UPDATER.set(this, Math.max(maxPutLatency, latency));
}
@Override
public long getGetOperationCount() {
return getCount;
}
public void incrementGets(long latency) {
GET_COUNT_UPDATER.incrementAndGet(this);
TOTAL_GET_LATENCIES_UPDATER.addAndGet(this, latency);
MAX_GET_LATENCY_UPDATER.set(this, Math.max(maxGetLatency, latency));
}
@Override
public long getRemoveOperationCount() {
return removeCount;
}
public void incrementRemoves(long latency) {
REMOVE_COUNT_UPDATER.incrementAndGet(this);
TOTAL_REMOVE_LATENCIES_UPDATER.addAndGet(this, latency);
MAX_REMOVE_LATENCY_UPDATER.set(this, Math.max(maxRemoveLatency, latency));
}
@Override
public long getTotalPutLatency() {
return totalPutLatencies;
}
@Override
public long getTotalGetLatency() {
return totalGetLatencies;
}
@Override
public long getTotalRemoveLatency() {
return totalRemoveLatencies;
}
@Override
public long getMaxPutLatency() {
return maxPutLatency;
}
@Override
public long getMaxGetLatency() {
return maxGetLatency;
}
@Override
public long getMaxRemoveLatency() {
return maxRemoveLatency;
}
@Override
public long getOtherOperationCount() {
return numberOfOtherOperations;
}
public void incrementOtherOperations() {
NUMBER_OF_OTHER_OPERATIONS_UPDATER.incrementAndGet(this);
}
@Override
public long getEventOperationCount() {
return numberOfEvents;
}
public void incrementReceivedEvents() {
NUMBER_OF_EVENTS_UPDATER.incrementAndGet(this);
}
@Override
public long getHeapCost() {
return heapCost;
}
public void setHeapCost(long heapCost) {
this.heapCost = heapCost;
}
@Override
public NearCacheStatsImpl getNearCacheStats() {
return nearCacheStats;
}
public void setNearCacheStats(NearCacheStatsImpl nearCacheStats) {
this.nearCacheStats = nearCacheStats;
}
@Override
public JsonObject toJson() {
JsonObject root = new JsonObject();
root.add("getCount", getCount);
root.add("putCount", putCount);
root.add("removeCount", removeCount);
root.add("numberOfOtherOperations", numberOfOtherOperations);
root.add("numberOfEvents", numberOfEvents);
root.add("lastAccessTime", lastAccessTime);
root.add("lastUpdateTime", lastUpdateTime);
root.add("hits", hits);
root.add("ownedEntryCount", ownedEntryCount);
root.add("backupEntryCount", backupEntryCount);
root.add("backupCount", backupCount);
root.add("ownedEntryMemoryCost", ownedEntryMemoryCost);
root.add("backupEntryMemoryCost", backupEntryMemoryCost);
root.add("creationTime", creationTime);
root.add("lockedEntryCount", lockedEntryCount);
root.add("dirtyEntryCount", dirtyEntryCount);
root.add("totalGetLatencies", totalGetLatencies);
root.add("totalPutLatencies", totalPutLatencies);
root.add("totalRemoveLatencies", totalRemoveLatencies);
root.add("maxGetLatency", maxGetLatency);
root.add("maxPutLatency", maxPutLatency);
root.add("maxRemoveLatency", maxRemoveLatency);
root.add("heapCost", heapCost);
if (nearCacheStats != null) {
root.add("nearCacheStats", nearCacheStats.toJson());
}
return root;
}
@Override
public void fromJson(JsonObject json) {
getCount = getLong(json, "getCount", -1L);
putCount = getLong(json, "putCount", -1L);
removeCount = getLong(json, "removeCount", -1L);
numberOfOtherOperations = getLong(json, "numberOfOtherOperations", -1L);
numberOfEvents = getLong(json, "numberOfEvents", -1L);
lastAccessTime = getLong(json, "lastAccessTime", -1L);
lastUpdateTime = getLong(json, "lastUpdateTime", -1L);
totalGetLatencies = getLong(json, "totalGetLatencies", -1L);
totalPutLatencies = getLong(json, "totalPutLatencies", -1L);
totalRemoveLatencies = getLong(json, "totalRemoveLatencies", -1L);
maxGetLatency = getLong(json, "maxGetLatency", -1L);
maxPutLatency = getLong(json, "maxPutLatency", -1L);
maxRemoveLatency = getLong(json, "maxRemoveLatency", -1L);
hits = getLong(json, "hits", -1L);
ownedEntryCount = getLong(json, "ownedEntryCount", -1L);
backupEntryCount = getLong(json, "backupEntryCount", -1L);
backupCount = getInt(json, "backupCount", -1);
ownedEntryMemoryCost = getLong(json, "ownedEntryMemoryCost", -1L);
backupEntryMemoryCost = getLong(json, "backupEntryMemoryCost", -1L);
creationTime = getLong(json, "creationTime", -1L);
lockedEntryCount = getLong(json, "lockedEntryCount", -1L);
dirtyEntryCount = getLong(json, "dirtyEntryCount", -1L);
heapCost = getLong(json, "heapCost", -1L);
JsonValue jsonNearCacheStats = json.get("nearCacheStats");
if (jsonNearCacheStats != null) {
nearCacheStats = new NearCacheStatsImpl();
nearCacheStats.fromJson(jsonNearCacheStats.asObject());
}
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
LocalMapStatsImpl that = (LocalMapStatsImpl) o;
if (lastAccessTime != that.lastAccessTime) {
return false;
}
if (lastUpdateTime != that.lastUpdateTime) {
return false;
}
if (hits != that.hits) {
return false;
}
if (numberOfOtherOperations != that.numberOfOtherOperations) {
return false;
}
if (numberOfEvents != that.numberOfEvents) {
return false;
}
if (getCount != that.getCount) {
return false;
}
if (putCount != that.putCount) {
return false;
}
if (removeCount != that.removeCount) {
return false;
}
if (totalGetLatencies != that.totalGetLatencies) {
return false;
}
if (totalPutLatencies != that.totalPutLatencies) {
return false;
}
if (totalRemoveLatencies != that.totalRemoveLatencies) {
return false;
}
if (maxGetLatency != that.maxGetLatency) {
return false;
}
if (maxPutLatency != that.maxPutLatency) {
return false;
}
if (maxRemoveLatency != that.maxRemoveLatency) {
return false;
}
if (creationTime != that.creationTime) {
return false;
}
if (ownedEntryCount != that.ownedEntryCount) {
return false;
}
if (backupEntryCount != that.backupEntryCount) {
return false;
}
if (ownedEntryMemoryCost != that.ownedEntryMemoryCost) {
return false;
}
if (backupEntryMemoryCost != that.backupEntryMemoryCost) {
return false;
}
if (heapCost != that.heapCost) {
return false;
}
if (lockedEntryCount != that.lockedEntryCount) {
return false;
}
if (dirtyEntryCount != that.dirtyEntryCount) {
return false;
}
if (backupCount != that.backupCount) {
return false;
}
if (nearCacheStats != null ? !nearCacheStats.equals(that.nearCacheStats) : that.nearCacheStats != null) {
return false;
}
return true;
}
@Override
public int hashCode() {
int result = (int) (lastAccessTime ^ (lastAccessTime >>> 32));
result = 31 * result + (int) (lastUpdateTime ^ (lastUpdateTime >>> 32));
result = 31 * result + (int) (hits ^ (hits >>> 32));
result = 31 * result + (int) (numberOfOtherOperations ^ (numberOfOtherOperations >>> 32));
result = 31 * result + (int) (numberOfEvents ^ (numberOfEvents >>> 32));
result = 31 * result + (int) (getCount ^ (getCount >>> 32));
result = 31 * result + (int) (putCount ^ (putCount >>> 32));
result = 31 * result + (int) (removeCount ^ (removeCount >>> 32));
result = 31 * result + (int) (totalGetLatencies ^ (totalGetLatencies >>> 32));
result = 31 * result + (int) (totalPutLatencies ^ (totalPutLatencies >>> 32));
result = 31 * result + (int) (totalRemoveLatencies ^ (totalRemoveLatencies >>> 32));
result = 31 * result + (int) (maxGetLatency ^ (maxGetLatency >>> 32));
result = 31 * result + (int) (maxPutLatency ^ (maxPutLatency >>> 32));
result = 31 * result + (int) (maxRemoveLatency ^ (maxRemoveLatency >>> 32));
result = 31 * result + (int) (creationTime ^ (creationTime >>> 32));
result = 31 * result + (int) (ownedEntryCount ^ (ownedEntryCount >>> 32));
result = 31 * result + (int) (backupEntryCount ^ (backupEntryCount >>> 32));
result = 31 * result + (int) (ownedEntryMemoryCost ^ (ownedEntryMemoryCost >>> 32));
result = 31 * result + (int) (backupEntryMemoryCost ^ (backupEntryMemoryCost >>> 32));
result = 31 * result + (int) (heapCost ^ (heapCost >>> 32));
result = 31 * result + (int) (lockedEntryCount ^ (lockedEntryCount >>> 32));
result = 31 * result + (int) (dirtyEntryCount ^ (dirtyEntryCount >>> 32));
result = 31 * result + backupCount;
result = 31 * result + (nearCacheStats != null ? nearCacheStats.hashCode() : 0);
return result;
}
@Override
public String toString() {
return "LocalMapStatsImpl{"
+ "lastAccessTime=" + lastAccessTime
+ ", lastUpdateTime=" + lastUpdateTime
+ ", hits=" + hits
+ ", numberOfOtherOperations=" + numberOfOtherOperations
+ ", numberOfEvents=" + numberOfEvents
+ ", getCount=" + getCount
+ ", putCount=" + putCount
+ ", removeCount=" + removeCount
+ ", totalGetLatencies=" + totalGetLatencies
+ ", totalPutLatencies=" + totalPutLatencies
+ ", totalRemoveLatencies=" + totalRemoveLatencies
+ ", ownedEntryCount=" + ownedEntryCount
+ ", backupEntryCount=" + backupEntryCount
+ ", backupCount=" + backupCount
+ ", ownedEntryMemoryCost=" + ownedEntryMemoryCost
+ ", backupEntryMemoryCost=" + backupEntryMemoryCost
+ ", creationTime=" + creationTime
+ ", lockedEntryCount=" + lockedEntryCount
+ ", dirtyEntryCount=" + dirtyEntryCount
+ ", heapCost=" + heapCost
+ '}';
}
}