Search in sources :

Example 91 with NotCompliantMBeanException

use of javax.management.NotCompliantMBeanException in project flink by apache.

the class JMXReporter method notifyOfAddedMetric.

// ------------------------------------------------------------------------
// adding / removing metrics
// ------------------------------------------------------------------------
@Override
public void notifyOfAddedMetric(Metric metric, String metricName, MetricGroup group) {
    final String domain = generateJmxDomain(metricName, group);
    final Hashtable<String, String> table = generateJmxTable(group.getAllVariables());
    AbstractBean jmxMetric;
    ObjectName jmxName;
    try {
        jmxName = new ObjectName(domain, table);
    } catch (MalformedObjectNameException e) {
        /*
             * There is an implementation error on our side if this occurs. Either the domain was
             * modified and no longer conforms to the JMX domain rules or the table wasn't properly
             * generated.
             */
        LOG.debug("Implementation error. The domain or table does not conform to JMX rules.", e);
        return;
    }
    if (metric instanceof Gauge) {
        jmxMetric = new JmxGauge((Gauge<?>) metric);
    } else if (metric instanceof Counter) {
        jmxMetric = new JmxCounter((Counter) metric);
    } else if (metric instanceof Histogram) {
        jmxMetric = new JmxHistogram((Histogram) metric);
    } else if (metric instanceof Meter) {
        jmxMetric = new JmxMeter((Meter) metric);
    } else {
        LOG.error("Cannot add unknown metric type: {}. This indicates that the metric type " + "is not supported by this reporter.", metric.getClass().getName());
        return;
    }
    try {
        synchronized (this) {
            mBeanServer.registerMBean(jmxMetric, jmxName);
            registeredMetrics.put(metric, jmxName);
        }
    } catch (NotCompliantMBeanException e) {
        // implementation error on our side
        LOG.debug("Metric did not comply with JMX MBean rules.", e);
    } catch (InstanceAlreadyExistsException e) {
        LOG.warn("A metric with the name " + jmxName + " was already registered.", e);
    } catch (Throwable t) {
        LOG.warn("Failed to register metric", t);
    }
}
Also used : MalformedObjectNameException(javax.management.MalformedObjectNameException) Histogram(org.apache.flink.metrics.Histogram) Meter(org.apache.flink.metrics.Meter) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) ObjectName(javax.management.ObjectName) Gauge(org.apache.flink.metrics.Gauge) Counter(org.apache.flink.metrics.Counter)

Example 92 with NotCompliantMBeanException

use of javax.management.NotCompliantMBeanException in project genius by opendaylight.

the class PortNameMapping method registerPortMappingBean.

public static void registerPortMappingBean() {
    MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    ObjectName mbeanName = null;
    try {
        mbeanName = new ObjectName(beanName);
    } catch (MalformedObjectNameException e) {
        LOG.error("ObjectName instance creation failed for BEANAME {}", beanName, e);
    }
    try {
        if (!mbs.isRegistered(mbeanName)) {
            mbs.registerMBean(new PortNameMapping(), mbeanName);
            LOG.debug("Registered Mbean {} successfully", mbeanName);
        }
    } catch (InstanceAlreadyExistsException | MBeanRegistrationException | NotCompliantMBeanException e) {
        LOG.error("Registeration failed for Mbean {}", mbeanName, e);
    }
}
Also used : MalformedObjectNameException(javax.management.MalformedObjectNameException) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) MBeanRegistrationException(javax.management.MBeanRegistrationException) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName)

Example 93 with NotCompliantMBeanException

use of javax.management.NotCompliantMBeanException in project infrautils by opendaylight.

the class MBeanUtils method registerServerMBean.

public static MBeanServer registerServerMBean(Object mxBeanImplementor, String objNameStr) throws JMException {
    LOG.debug("register MBean for {}", objNameStr);
    MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    try {
        ObjectName objName = new ObjectName(objNameStr);
        mbs.registerMBean(mxBeanImplementor, objName);
        LOG.info("MBean registration for {} SUCCESSFUL.", objNameStr);
    } catch (InstanceAlreadyExistsException | MBeanRegistrationException | NotCompliantMBeanException | MalformedObjectNameException ex) {
        LOG.error("MBean registration for {} FAILED.", objNameStr, ex);
        throw ex;
    }
    return mbs;
}
Also used : MalformedObjectNameException(javax.management.MalformedObjectNameException) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) MBeanRegistrationException(javax.management.MBeanRegistrationException) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName)

Example 94 with NotCompliantMBeanException

use of javax.management.NotCompliantMBeanException in project infrautils by opendaylight.

the class AbstractMXBean method registerMBean.

/**
 * Registers this bean with the platform MBean server with the domain defined by
 * {@link #BASE_JMX_PREFIX}.
 *
 * @return true is successfully registered, false otherwise.
 */
protected final boolean registerMBean() {
    @Var boolean registered = false;
    try {
        // Object to identify MBean
        ObjectName mbeanObjectName = this.getMBeanObjectName();
        LOG.debug("Register MBean {}", mbeanObjectName);
        // unregistered if already registered
        if (server.isRegistered(mbeanObjectName)) {
            LOG.debug("MBean {} found to be already registered", mbeanObjectName);
            try {
                unregisterMBean(mbeanObjectName);
            } catch (MBeanRegistrationException | InstanceNotFoundException e) {
                LOG.warn("unregister mbean {} caused exception", mbeanObjectName, e);
            }
        }
        server.registerMBean(this, mbeanObjectName);
        registered = true;
        LOG.debug("MBean {} registered successfully", mbeanObjectName.getCanonicalName());
    } catch (InstanceAlreadyExistsException | MBeanRegistrationException | NotCompliantMBeanException | MalformedObjectNameException e) {
        LOG.error("MBean {} registration failed", mbeanName, e);
    }
    return registered;
}
Also used : MalformedObjectNameException(javax.management.MalformedObjectNameException) Var(com.google.errorprone.annotations.Var) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) InstanceNotFoundException(javax.management.InstanceNotFoundException) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) MBeanRegistrationException(javax.management.MBeanRegistrationException) ObjectName(javax.management.ObjectName)

Example 95 with NotCompliantMBeanException

use of javax.management.NotCompliantMBeanException in project jvm-tools by aragozin.

the class HotspotInternalMBeanEnabler method start.

@Override
public void start(Properties agentProps, String agentArgs, Instrumentation inst) throws InstanceAlreadyExistsException, MBeanRegistrationException, NotCompliantMBeanException {
    try {
        String mname = "sun.management:type=HotspotThreading";
        MBeanInfo info = ManagementFactory.getPlatformMBeanServer().getMBeanInfo(new ObjectName(mname));
        if (info != null) {
            // bean is present
            agentProps.put(this.getClass().getName() + ".enabled", "true");
            return;
        }
    } catch (Exception e) {
    // ignore
    }
    HotspotInternal hi = new HotspotInternal();
    ManagementFactory.getPlatformMBeanServer().registerMBean(hi, null);
    agentProps.put(this.getClass().getName() + ".enabled", "true");
}
Also used : HotspotInternal(sun.management.HotspotInternal) MBeanInfo(javax.management.MBeanInfo) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) MBeanRegistrationException(javax.management.MBeanRegistrationException) ObjectName(javax.management.ObjectName)

Aggregations

NotCompliantMBeanException (javax.management.NotCompliantMBeanException)106 ObjectName (javax.management.ObjectName)73 InstanceAlreadyExistsException (javax.management.InstanceAlreadyExistsException)71 MBeanRegistrationException (javax.management.MBeanRegistrationException)71 MalformedObjectNameException (javax.management.MalformedObjectNameException)59 MBeanServer (javax.management.MBeanServer)39 InstanceNotFoundException (javax.management.InstanceNotFoundException)23 StandardMBean (javax.management.StandardMBean)20 MBeanException (javax.management.MBeanException)8 ReflectionException (javax.management.ReflectionException)8 IOException (java.io.IOException)7 ObjectInstance (javax.management.ObjectInstance)5 AttributeNotFoundException (javax.management.AttributeNotFoundException)4 InvalidAttributeValueException (javax.management.InvalidAttributeValueException)4 ListenerNotFoundException (javax.management.ListenerNotFoundException)4 Logger (org.apache.aries.jmx.Logger)4 MalformedURLException (java.net.MalformedURLException)3 DynamicMBean (javax.management.DynamicMBean)3 IntrospectionException (javax.management.IntrospectionException)3 JMRuntimeException (javax.management.JMRuntimeException)3