Search in sources :

Example 1 with JCacheStatisticsMXBean

use of org.redisson.jcache.bean.JCacheStatisticsMXBean in project redisson by redisson.

the class JCacheManager method enableStatistics.

@Override
public void enableStatistics(String cacheName, boolean enabled) {
    checkNotClosed();
    if (cacheName == null) {
        throw new NullPointerException();
    }
    JCache<?, ?> cache = caches.get(cacheName);
    if (cache == null) {
        throw new NullPointerException();
    }
    if (enabled) {
        JCacheStatisticsMXBean statBean = statBeans.get(cache);
        if (statBean == null) {
            statBean = new JCacheStatisticsMXBean();
            JCacheStatisticsMXBean oldBean = statBeans.putIfAbsent(cache, statBean);
            if (oldBean != null) {
                statBean = oldBean;
            }
        }
        try {
            ObjectName objectName = queryNames("Statistics", cache);
            if (!mBeanServer.isRegistered(objectName)) {
                mBeanServer.registerMBean(statBean, objectName);
            }
        } catch (MalformedObjectNameException e) {
            throw new CacheException(e);
        } catch (InstanceAlreadyExistsException e) {
            throw new CacheException(e);
        } catch (MBeanRegistrationException e) {
            throw new CacheException(e);
        } catch (NotCompliantMBeanException e) {
            throw new CacheException(e);
        }
    } else {
        unregisterStatisticsBean(cache);
    }
    cache.getConfiguration(JCacheConfiguration.class).setStatisticsEnabled(enabled);
}
Also used : MalformedObjectNameException(javax.management.MalformedObjectNameException) JCacheConfiguration(org.redisson.jcache.configuration.JCacheConfiguration) CacheException(javax.cache.CacheException) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) JCacheStatisticsMXBean(org.redisson.jcache.bean.JCacheStatisticsMXBean) MBeanRegistrationException(javax.management.MBeanRegistrationException) ObjectName(javax.management.ObjectName)

Aggregations

CacheException (javax.cache.CacheException)1 InstanceAlreadyExistsException (javax.management.InstanceAlreadyExistsException)1 MBeanRegistrationException (javax.management.MBeanRegistrationException)1 MalformedObjectNameException (javax.management.MalformedObjectNameException)1 NotCompliantMBeanException (javax.management.NotCompliantMBeanException)1 ObjectName (javax.management.ObjectName)1 JCacheStatisticsMXBean (org.redisson.jcache.bean.JCacheStatisticsMXBean)1 JCacheConfiguration (org.redisson.jcache.configuration.JCacheConfiguration)1