Search in sources :

Example 1 with IgniteMBeanAware

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;
        }
    }
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteMBeanAware(org.apache.ignite.mxbean.IgniteMBeanAware) JMException(javax.management.JMException) GridTimeoutObject(org.apache.ignite.internal.processors.timeout.GridTimeoutObject) MBeanServer(javax.management.MBeanServer)

Example 2 with IgniteMBeanAware

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);
        }
    }
}
Also used : IgniteMBeanAware(org.apache.ignite.mxbean.IgniteMBeanAware) JMException(javax.management.JMException) MBeanServer(javax.management.MBeanServer)

Aggregations

JMException (javax.management.JMException)2 MBeanServer (javax.management.MBeanServer)2 IgniteMBeanAware (org.apache.ignite.mxbean.IgniteMBeanAware)2 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)1 GridTimeoutObject (org.apache.ignite.internal.processors.timeout.GridTimeoutObject)1