Search in sources :

Example 1 with CacheException

use of org.cache2k.CacheException in project cache2k by cache2k.

the class JmxSupport method managerCreated.

@Override
public void managerCreated(CacheManager m) {
    MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    ManagerMXBeanImpl _mBean = new ManagerMXBeanImpl((CacheManagerImpl) m);
    String _name = managerName(m);
    try {
        mbs.registerMBean(_mBean, new ObjectName(_name));
        m.getProperties().put(REGISTERED_FLAG, true);
        log.debug("Manager created and registered as: " + _name);
    } catch (InstanceAlreadyExistsException ignore) {
        log.debug("register failure, manager: " + m.getName(), ignore);
    } catch (Exception e) {
        throw new CacheException("register JMX bean, ObjectName: " + _name, e);
    }
}
Also used : CacheException(org.cache2k.CacheException) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) CacheException(org.cache2k.CacheException) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) InstanceNotFoundException(javax.management.InstanceNotFoundException) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName)

Example 2 with CacheException

use of org.cache2k.CacheException in project cache2k by cache2k.

the class JmxSupport method cacheCreated.

@Override
public void cacheCreated(Cache c) {
    InternalCache ic = (InternalCache) c;
    if (!ic.getCommonMetrics().isDisabled()) {
        MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
        String _name = standardName(c.getCacheManager(), c);
        try {
            mbs.registerMBean(new CacheMXBeanImpl(ic), new ObjectName(_name));
        } catch (InstanceAlreadyExistsException ignore) {
            log.debug("register failure, cache: " + c.getName(), ignore);
        } catch (Exception e) {
            throw new CacheException("register JMX bean, ObjectName: " + _name, e);
        }
    }
}
Also used : CacheException(org.cache2k.CacheException) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) InternalCache(org.cache2k.core.InternalCache) CacheException(org.cache2k.CacheException) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) InstanceNotFoundException(javax.management.InstanceNotFoundException) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName)

Example 3 with CacheException

use of org.cache2k.CacheException in project cache2k by cache2k.

the class JmxSupport method cacheDestroyed.

@Override
public void cacheDestroyed(Cache c) {
    MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    String _name = standardName(c.getCacheManager(), c);
    try {
        mbs.unregisterMBean(new ObjectName(_name));
    } catch (InstanceNotFoundException ignore) {
        log.debug("unregister failure, cache: " + c.getName(), ignore);
    } catch (Exception e) {
        throw new CacheException("unregister JMX bean, ObjectName: " + _name, e);
    }
}
Also used : CacheException(org.cache2k.CacheException) InstanceNotFoundException(javax.management.InstanceNotFoundException) CacheException(org.cache2k.CacheException) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) InstanceNotFoundException(javax.management.InstanceNotFoundException) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName)

Example 4 with CacheException

use of org.cache2k.CacheException in project cache2k by cache2k.

the class JmxSupport method managerDestroyed.

@Override
public void managerDestroyed(CacheManager m) {
    if (!m.getProperties().containsKey(REGISTERED_FLAG)) {
        return;
    }
    MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    String _name = managerName(m);
    try {
        mbs.unregisterMBean(new ObjectName(_name));
    } catch (Exception e) {
        throw new CacheException("Error unregister JMX bean, ObjectName: " + _name, e);
    }
}
Also used : CacheException(org.cache2k.CacheException) CacheException(org.cache2k.CacheException) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) InstanceNotFoundException(javax.management.InstanceNotFoundException) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName)

Aggregations

InstanceAlreadyExistsException (javax.management.InstanceAlreadyExistsException)4 InstanceNotFoundException (javax.management.InstanceNotFoundException)4 MBeanServer (javax.management.MBeanServer)4 ObjectName (javax.management.ObjectName)4 CacheException (org.cache2k.CacheException)4 InternalCache (org.cache2k.core.InternalCache)1