use of org.apache.ignite.mxbean.IgniteMBeanAware in project ignite by apache.
the class GridCacheProcessor method registerMbean.
/**
* Registers MBean for cache components.
*
* @param obj Cache component.
* @param cacheName Cache name.
* @param near Near flag.
* @throws IgniteCheckedException If registration failed.
*/
@SuppressWarnings("unchecked")
private void registerMbean(Object obj, @Nullable String cacheName, boolean near) throws IgniteCheckedException {
assert obj != null;
MBeanServer srvr = ctx.config().getMBeanServer();
assert srvr != null;
cacheName = U.maskName(cacheName);
cacheName = near ? cacheName + "-near" : cacheName;
final Object mbeanImpl = (obj instanceof IgniteMBeanAware) ? ((IgniteMBeanAware) obj).getMBean() : obj;
for (Class<?> itf : mbeanImpl.getClass().getInterfaces()) {
if (itf.getName().endsWith("MBean") || itf.getName().endsWith("MXBean")) {
try {
U.registerCacheMBean(srvr, ctx.igniteInstanceName(), cacheName, obj.getClass().getName(), mbeanImpl, (Class<Object>) itf);
} catch (JMException e) {
throw new IgniteCheckedException("Failed to register MBean for component: " + obj, e);
}
break;
}
}
}
use of org.apache.ignite.mxbean.IgniteMBeanAware in project ignite by apache.
the class GridCacheProcessor method unregisterMbean.
/**
* Unregisters MBean for cache components.
*
* @param o Cache component.
* @param cacheName Cache name.
* @param near Near flag.
*/
private void unregisterMbean(Object o, @Nullable String cacheName, boolean near) {
assert o != null;
MBeanServer srvr = ctx.config().getMBeanServer();
assert srvr != null;
cacheName = U.maskName(cacheName);
cacheName = near ? cacheName + "-near" : cacheName;
boolean needToUnregister = o instanceof IgniteMBeanAware;
if (!needToUnregister) {
for (Class<?> itf : o.getClass().getInterfaces()) {
if (itf.getName().endsWith("MBean") || itf.getName().endsWith("MXBean")) {
needToUnregister = true;
break;
}
}
}
if (needToUnregister) {
try {
srvr.unregisterMBean(U.makeCacheMBeanName(ctx.igniteInstanceName(), cacheName, o.getClass().getName()));
} catch (JMException e) {
U.error(log, "Failed to unregister MBean for component: " + o, e);
}
}
}
Aggregations