Skip to content

Commit

Permalink
IGNITE-49 Changed CacheMetrics and IgniteCacheMxBean API
Browse files Browse the repository at this point in the history
  • Loading branch information
niktikhonov committed Jan 23, 2015
1 parent 4277989 commit 669f3a9
Show file tree
Hide file tree
Showing 16 changed files with 313 additions and 115 deletions.
Expand Up @@ -25,14 +25,14 @@
* Implementation of {@link CacheMXBean}.
*
*/
public class CacheMXBeanImpl implements CacheMXBean {
public class CacheMxBeanImpl implements CacheMXBean {
/** */
private final Cache<?, ?> cache;

/**
* @param cache Cache.
*/
public CacheMXBeanImpl(Cache<?, ?> cache) {
public CacheMxBeanImpl(Cache<?, ?> cache) {
this.cache = cache;
}

Expand Down
7 changes: 7 additions & 0 deletions modules/core/src/main/java/org/apache/ignite/IgniteCache.java
Expand Up @@ -361,4 +361,11 @@ public interface IgniteCache<K, V> extends javax.cache.Cache<K, V>, IgniteAsyncS
* @return Cache metrics.
*/
public CacheMetrics metrics();

/**
* Gets MxBean for this cache.
*
* @return MxBean.
*/
public IgniteCacheMxBean mxBean();
}
Expand Up @@ -41,7 +41,7 @@ public class IgniteCacheManager implements CacheManager {
private static final String CACHE_CONFIGURATION = "CacheConfiguration";

/** */
private final Map<String, IgniteBiTuple<Ignite, CacheMXBeanImpl>> igniteMap = new HashMap<>();
private final Map<String, IgniteBiTuple<Ignite, CacheMxBeanImpl>> igniteMap = new HashMap<>();

/** */
private final URI uri;
Expand Down Expand Up @@ -147,7 +147,7 @@ public IgniteCacheManager(URI uri, CachingProvider cachingProvider, ClassLoader

res = ignite.jcache(cacheName);

igniteMap.put(cacheName, new T2<>(ignite, new CacheMXBeanImpl(res)));
igniteMap.put(cacheName, new T2<>(ignite, new CacheMxBeanImpl(res)));
}

if (((CompleteConfiguration)cacheCfg).isManagementEnabled())
Expand All @@ -163,7 +163,7 @@ public IgniteCacheManager(URI uri, CachingProvider cachingProvider, ClassLoader
* @param cacheName Cache name.
*/
private <K, V> IgniteCache<K, V> findCache(String cacheName) {
IgniteBiTuple<Ignite, CacheMXBeanImpl> tuple;
IgniteBiTuple<Ignite, CacheMxBeanImpl> tuple;

synchronized (igniteMap) {
tuple = igniteMap.get(cacheName);
Expand Down Expand Up @@ -229,7 +229,7 @@ private <K, V> IgniteCache<K, V> findCache(String cacheName) {
*/
public boolean isManagedIgnite(Ignite ignite) {
synchronized (igniteMap) {
for (IgniteBiTuple<Ignite, CacheMXBeanImpl> tuple : igniteMap.values()) {
for (IgniteBiTuple<Ignite, CacheMxBeanImpl> tuple : igniteMap.values()) {
if (ignite.equals(tuple.get1()))
return true;
}
Expand All @@ -245,7 +245,7 @@ public boolean isManagedIgnite(Ignite ignite) {
if (cacheName == null)
throw new NullPointerException();

IgniteBiTuple<Ignite, CacheMXBeanImpl> tuple;
IgniteBiTuple<Ignite, CacheMxBeanImpl> tuple;

synchronized (igniteMap) {
tuple = igniteMap.remove(cacheName);
Expand Down Expand Up @@ -290,7 +290,7 @@ private ObjectName getObjectName(String cacheName, String objectName) {
if (cacheName == null)
throw new NullPointerException();

IgniteBiTuple<Ignite, CacheMXBeanImpl> tuple;
IgniteBiTuple<Ignite, CacheMxBeanImpl> tuple;

synchronized (igniteMap) {
tuple = igniteMap.get(cacheName);
Expand Down Expand Up @@ -318,7 +318,7 @@ private ObjectName getObjectName(String cacheName, String objectName) {
if (cacheName == null)
throw new NullPointerException();

IgniteBiTuple<Ignite, CacheMXBeanImpl> tuple;
IgniteBiTuple<Ignite, CacheMxBeanImpl> tuple;

synchronized (igniteMap) {
tuple = igniteMap.get(cacheName);
Expand All @@ -333,7 +333,7 @@ private ObjectName getObjectName(String cacheName, String objectName) {
MBeanServer mBeanSrv = ignite.configuration().getMBeanServer();

if (enabled) {
registerCacheObject(mBeanSrv, cache.metrics(), cacheName, CACHE_STATISTICS);
registerCacheObject(mBeanSrv, cache.mxBean(), cacheName, CACHE_STATISTICS);

cfg.setStatisticsEnabled(true);
}
Expand Down Expand Up @@ -403,13 +403,13 @@ private void ensureNotClosed() throws IllegalStateException {
/** {@inheritDoc} */
@Override public void close() {
if (closed.compareAndSet(false, true)) {
IgniteBiTuple<Ignite, CacheMXBeanImpl>[] ignites;
IgniteBiTuple<Ignite, CacheMxBeanImpl>[] ignites;

synchronized (igniteMap) {
ignites = igniteMap.values().toArray(new IgniteBiTuple[igniteMap.values().size()]);
}

for (IgniteBiTuple<Ignite, CacheMXBeanImpl> tuple : ignites) {
for (IgniteBiTuple<Ignite, CacheMxBeanImpl> tuple : ignites) {
try {
tuple.get1().close();
}
Expand Down
Expand Up @@ -100,6 +100,18 @@ public GridCacheContext<K, V> context() {
}
}

/** {@inheritDoc} */
@Override public IgniteCacheMxBean mxBean() {
GridCacheProjectionImpl<K, V> prev = gate.enter(prj);

try {
return ctx.cache().mxBean();
}
finally {
gate.leave(prev);
}
}

/** {@inheritDoc} */
@Override public <C extends Configuration<K, V>> C getConfiguration(Class<C> clazz) {
CacheConfiguration cfg = ctx.config();
Expand Down
Expand Up @@ -24,11 +24,6 @@
* Use {@link IgniteCache#metrics()} to obtain metrics for a cache.
*/
public interface CacheMetrics {
/**
* Clears the statistics counters to 0 for the associated Cache.
*/
void clear();

/**
* The number of get requests that were satisfied by the cache.
*
Expand Down
Expand Up @@ -118,6 +118,14 @@ public interface GridCache<K, V> extends GridCacheProjection<K, V> {
*/
public CacheMetrics metrics();


/**
* Gets metrics (statistics) for this cache.
*
* @return Cache metrics.
*/
public IgniteCacheMxBean mxBean();

/**
* Gets size (in bytes) of all entries swapped to disk.
*
Expand Down
Expand Up @@ -27,7 +27,7 @@
/**
* Adapter for cache metrics.
*/
public class CacheMetricsImpl implements CacheMetrics, Externalizable {
public class CacheMetricsImpl implements CacheMetrics {
/** */
private static final long NANOS_IN_MICROSECOND = 1000L;

Expand Down Expand Up @@ -123,8 +123,10 @@ public void delegate(CacheMetricsImpl delegate) {
return txRollbacks.get();
}

/** {@inheritDoc} */
@Override public void clear() {
/**
* Clear metrics.
*/
public void clear() {
reads.set(0);
writes.set(0);
rmCnt.set(0);
Expand Down Expand Up @@ -361,42 +363,6 @@ public void addPutAndGetTimeNanos(long duration) {
delegate.addPutAndGetTimeNanos(duration);
}

/** {@inheritDoc} */
@Override public void writeExternal(ObjectOutput out) throws IOException {
out.writeLong(reads.get());
out.writeLong(writes.get());
out.writeLong(hits.get());
out.writeLong(misses.get());
out.writeLong(txCommits.get());
out.writeLong(txRollbacks.get());
out.writeLong(rmCnt.get());
out.writeLong(evictCnt.get());

out.writeLong(putTimeNanos.get());
out.writeLong(getTimeNanos.get());
out.writeLong(removeTimeNanos.get());
out.writeLong(commitTimeNanos.get());
out.writeLong(rollbackTimeNanos.get());
}

/** {@inheritDoc} */
@Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
reads = new AtomicLong(in.readLong());
writes = new AtomicLong(in.readLong());
hits = new AtomicLong(in.readLong());
misses = new AtomicLong(in.readLong());
txCommits = new AtomicLong(in.readLong());
txRollbacks = new AtomicLong(in.readLong());
rmCnt = new AtomicLong(in.readLong());
evictCnt = new AtomicLong(in.readLong());

putTimeNanos = new AtomicLong(in.readLong());
getTimeNanos = new AtomicLong(in.readLong());
removeTimeNanos = new AtomicLong(in.readLong());
commitTimeNanos = new AtomicLong(in.readLong());
rollbackTimeNanos = new AtomicLong(in.readLong());
}

/** {@inheritDoc} */
@Override public String toString() {
return S.toString(CacheMetricsImpl.class, this);
Expand Down

0 comments on commit 669f3a9

Please sign in to comment.