Search in sources :

Example 46 with JMException

use of javax.management.JMException in project geode by apache.

the class MBeanUtil method registerServerNotificationListener.

static void registerServerNotificationListener() {
    if (mbeanServer == null) {
        return;
    }
    try {
        // the MBeanServerDelegate name is spec'ed as the following...
        ObjectName delegate = ObjectName.getInstance("JMImplementation:type=MBeanServerDelegate");
        mbeanServer.addNotificationListener(delegate, new NotificationListener() {

            public void handleNotification(Notification notification, Object handback) {
                MBeanServerNotification serverNotification = (MBeanServerNotification) notification;
                if (MBeanServerNotification.UNREGISTRATION_NOTIFICATION.equals(serverNotification.getType())) {
                    ObjectName objectName = serverNotification.getMBeanName();
                    synchronized (MBeanUtil.managedResources) {
                        Object entry = MBeanUtil.managedResources.get(objectName);
                        if (entry == null)
                            return;
                        if (!(entry instanceof ManagedResource)) {
                            throw new ClassCastException(LocalizedStrings.MBeanUtil_0_IS_NOT_A_MANAGEDRESOURCE.toLocalizedString(new Object[] { entry.getClass().getName() }));
                        }
                        ManagedResource resource = (ManagedResource) entry;
                        {
                            // call cleanup on managedResource
                            cleanupResource(resource);
                        }
                    }
                }
            }
        }, null, null);
    } catch (JMException e) {
        logStackTrace(Level.WARN, e, LocalizedStrings.MBeanUtil_FAILED_TO_REGISTER_SERVERNOTIFICATIONLISTENER.toLocalizedString());
    } catch (JMRuntimeException e) {
        logStackTrace(Level.WARN, e, LocalizedStrings.MBeanUtil_FAILED_TO_REGISTER_SERVERNOTIFICATIONLISTENER.toLocalizedString());
    }
}
Also used : MBeanServerNotification(javax.management.MBeanServerNotification) JMException(javax.management.JMException) JMRuntimeException(javax.management.JMRuntimeException) Notification(javax.management.Notification) MBeanServerNotification(javax.management.MBeanServerNotification) ObjectName(javax.management.ObjectName) NotificationListener(javax.management.NotificationListener)

Example 47 with JMException

use of javax.management.JMException 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)

Example 48 with JMException

use of javax.management.JMException in project ignite by apache.

the class IgniteCacheDatabaseSharedManager method stop0.

/** {@inheritDoc} */
@Override
protected void stop0(boolean cancel) {
    if (memPlcMap != null) {
        for (MemoryPolicy memPlc : memPlcMap.values()) {
            memPlc.pageMemory().stop();
            memPlc.evictionTracker().stop();
            IgniteConfiguration cfg = cctx.gridConfig();
            try {
                cfg.getMBeanServer().unregisterMBean(U.makeMBeanName(cfg.getIgniteInstanceName(), "MemoryMetrics", memPlc.memoryMetrics().getName()));
            } catch (JMException e) {
                U.error(log, "Failed to unregister MBean for memory metrics: " + memPlc.memoryMetrics().getName(), e);
            }
        }
    }
}
Also used : IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) JMException(javax.management.JMException)

Example 49 with JMException

use of javax.management.JMException in project ignite by apache.

the class IgniteUtils method jmException.

/**
     * Utility method creating {@link JMException} with given cause.
     *
     * @param e Cause exception.
     * @return Newly created {@link JMException}.
     */
public static JMException jmException(Throwable e) {
    JMException x = new JMException();
    x.initCause(e);
    return x;
}
Also used : JMException(javax.management.JMException)

Aggregations

JMException (javax.management.JMException)49 ObjectName (javax.management.ObjectName)29 MBeanServer (javax.management.MBeanServer)18 IOException (java.io.IOException)10 SnmpStatusException (com.sun.management.snmp.SnmpStatusException)7 HashMap (java.util.HashMap)6 Map (java.util.Map)6 StandardMBean (javax.management.StandardMBean)4 RequiredModelMBean (javax.management.modelmbean.RequiredModelMBean)4 JvmCoreException (org.talend.designer.runtime.visualization.JvmCoreException)4 Date (java.util.Date)3 InstanceAlreadyExistsException (javax.management.InstanceAlreadyExistsException)3 MalformedObjectNameException (javax.management.MalformedObjectNameException)3 InvalidTargetObjectTypeException (javax.management.modelmbean.InvalidTargetObjectTypeException)3 ModelMBeanInfo (javax.management.modelmbean.ModelMBeanInfo)3 MalformedURLException (java.net.MalformedURLException)2 UnknownHostException (java.net.UnknownHostException)2 Set (java.util.Set)2 Attribute (javax.management.Attribute)2 MBeanAttributeInfo (javax.management.MBeanAttributeInfo)2