Search in sources :

Example 61 with MalformedObjectNameException

use of javax.management.MalformedObjectNameException in project com.revolsys.open by revolsys.

the class JmxUtil method getMBeanAttributes.

@SuppressWarnings("unchecked")
public static Map<String, MBeanAttributeInfo[]> getMBeanAttributes(final MBeanServerConnection connection, final String objectNameString) {
    Map<String, MBeanAttributeInfo[]> attributesMap = null;
    Set<ObjectName> objectNames;
    try {
        objectNames = connection.queryNames(new ObjectName(objectNameString), null);
        attributesMap = new TreeMap<>();
        for (final ObjectName objectName : objectNames) {
            MBeanInfo mBeanInfo;
            mBeanInfo = connection.getMBeanInfo(objectName);
            final MBeanAttributeInfo[] attributes = mBeanInfo.getAttributes();
            attributesMap.put(objectName.getCanonicalName(), attributes);
        }
    } catch (final InstanceNotFoundException e) {
        e.printStackTrace();
    } catch (final IntrospectionException e) {
        e.printStackTrace();
    } catch (final ReflectionException e) {
        e.printStackTrace();
    } catch (final MalformedObjectNameException e) {
        e.printStackTrace();
    } catch (final NullPointerException e) {
        e.printStackTrace();
    } catch (final IOException e) {
        e.printStackTrace();
    }
    return attributesMap;
}
Also used : ReflectionException(javax.management.ReflectionException) MalformedObjectNameException(javax.management.MalformedObjectNameException) MBeanInfo(javax.management.MBeanInfo) InstanceNotFoundException(javax.management.InstanceNotFoundException) IntrospectionException(javax.management.IntrospectionException) IOException(java.io.IOException) MBeanAttributeInfo(javax.management.MBeanAttributeInfo) ObjectName(javax.management.ObjectName)

Example 62 with MalformedObjectNameException

use of javax.management.MalformedObjectNameException in project jmeter-plugins by undera.

the class JMXMonSampler method generateSamples.

public void generateSamples(JMXMonSampleGenerator collector) {
    try {
        if (hasFailed && !canRetry) {
            return;
        }
        // Construct the fully qualified name of the bean.
        ObjectName beanName = new ObjectName(objectName);
        MBeanServerConnection activeRemote = null;
        if (remote == null) {
            activeRemote = pool.getConnection(url.getStringValue(), connectionAttributes);
            if (activeRemote == null) {
                hasFailed = true;
            }
        } else {
            activeRemote = remote;
        }
        final double val;
        if (activeRemote != null) {
            Object o = activeRemote.getAttribute(beanName, attribute);
            if (o instanceof CompositeDataSupport) {
                if (key == null || "".equals(key)) {
                    log.error("Got composite object from JMX, but no key specified ");
                    return;
                }
                CompositeDataSupport cds = (CompositeDataSupport) o;
                // log.info("CDS: " + cds.toString());
                val = Double.parseDouble(cds.get(key).toString());
            } else {
                if (key != null && !key.equals("")) {
                    log.error("key specified, but didnt get composite object from JMX. Will continue anyway.");
                }
                val = Double.parseDouble(o.toString());
            }
        } else {
            val = 0;
        }
        if (sampleDeltaValue) {
            if (!Double.isNaN(oldValue)) {
                collector.generateSample(val - oldValue, metricName);
            }
            oldValue = val;
        } else {
            collector.generateSample(val, metricName);
        }
    } catch (MalformedURLException ex) {
        log.error(ex.getMessage());
    } catch (ConnectException ex) {
        log.warn("Connection lost", ex);
        pool.notifyConnectionDirty(url.getStringValue());
        if (sampleDeltaValue) {
            if (!Double.isNaN(oldValue)) {
                collector.generateSample(0 - oldValue, metricName);
            }
            oldValue = 0;
        } else {
            collector.generateSample(0, metricName);
        }
    } catch (IOException ex) {
        log.error(ex.getMessage());
    } catch (ReflectionException ex) {
        log.error(ex.getMessage());
    } catch (MalformedObjectNameException ex) {
        log.error(ex.getMessage());
    } catch (NullPointerException ex) {
        log.error(ex.getMessage());
    } catch (MBeanException ex) {
        log.error(ex.getMessage());
    } catch (AttributeNotFoundException ex) {
        log.error(ex.getMessage());
    } catch (InstanceNotFoundException ex) {
        log.error(ex.getMessage());
    }
}
Also used : ReflectionException(javax.management.ReflectionException) MalformedURLException(java.net.MalformedURLException) MalformedObjectNameException(javax.management.MalformedObjectNameException) AttributeNotFoundException(javax.management.AttributeNotFoundException) CompositeDataSupport(javax.management.openmbean.CompositeDataSupport) InstanceNotFoundException(javax.management.InstanceNotFoundException) IOException(java.io.IOException) ObjectName(javax.management.ObjectName) MBeanException(javax.management.MBeanException) MBeanServerConnection(javax.management.MBeanServerConnection) ConnectException(java.rmi.ConnectException)

Example 63 with MalformedObjectNameException

use of javax.management.MalformedObjectNameException in project jspwiki by apache.

the class DefaultAdminBeanManager method actionPerformed.

/* (non-Javadoc)
	 * @see org.apache.wiki.ui.admin.AdminBeanManager#actionPerformed(org.apache.wiki.event.WikiEvent)
	 */
@Override
public void actionPerformed(WikiEvent event) {
    if (event instanceof WikiEngineEvent) {
        if (((WikiEngineEvent) event).getType() == WikiEngineEvent.SHUTDOWN) {
            for (Iterator<AdminBean> i = m_allBeans.iterator(); i.hasNext(); ) {
                try {
                    AdminBean ab = i.next();
                    ObjectName on = getObjectName(ab);
                    if (m_mbeanServer.isRegistered(on)) {
                        m_mbeanServer.unregisterMBean(on);
                        log.info("Unregistered AdminBean " + ab.getTitle());
                    }
                } catch (MalformedObjectNameException e) {
                    log.error("Malformed object name when unregistering", e);
                } catch (InstanceNotFoundException e) {
                    log.error("Object was registered; yet claims that it's not there", e);
                } catch (MBeanRegistrationException e) {
                    log.error("Registration exception while unregistering", e);
                }
            }
        }
    }
}
Also used : WikiEngineEvent(org.apache.wiki.event.WikiEngineEvent) MalformedObjectNameException(javax.management.MalformedObjectNameException) InstanceNotFoundException(javax.management.InstanceNotFoundException) MBeanRegistrationException(javax.management.MBeanRegistrationException) ObjectName(javax.management.ObjectName)

Example 64 with MalformedObjectNameException

use of javax.management.MalformedObjectNameException in project jspwiki by apache.

the class DefaultAdminBeanManager method registerAdminBean.

/**
 *  Register an AdminBean.  If the AdminBean is also a JMX MBean, it also gets registered to the MBeanServer
 *  we've found.
 *
 *  @param ab AdminBean to register.
 */
private void registerAdminBean(AdminBean ab) {
    try {
        if (ab instanceof DynamicMBean && m_mbeanServer != null) {
            ObjectName name = getObjectName(ab);
            if (!m_mbeanServer.isRegistered(name)) {
                m_mbeanServer.registerMBean(ab, name);
            }
        }
        m_allBeans.add(ab);
        log.info("Registered new admin bean " + ab.getTitle());
    } catch (InstanceAlreadyExistsException e) {
        log.error("Admin bean already registered to JMX", e);
    } catch (MBeanRegistrationException e) {
        log.error("Admin bean cannot be registered to JMX", e);
    } catch (NotCompliantMBeanException e) {
        log.error("Your admin bean is not very good", e);
    } catch (MalformedObjectNameException e) {
        log.error("Your admin bean name is not very good", e);
    } catch (NullPointerException e) {
        log.error("Evil NPE occurred", e);
    }
}
Also used : DynamicMBean(javax.management.DynamicMBean) MalformedObjectNameException(javax.management.MalformedObjectNameException) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) MBeanRegistrationException(javax.management.MBeanRegistrationException) ObjectName(javax.management.ObjectName)

Example 65 with MalformedObjectNameException

use of javax.management.MalformedObjectNameException in project alliance by codice.

the class SourcesToQuery method registerMbean.

private void registerMbean() {
    try {
        objectName = new ObjectName(SourcesToQuery.class.getName() + ":service=stream");
        mBeanServer = ManagementFactory.getPlatformMBeanServer();
    } catch (MalformedObjectNameException e) {
        LOGGER.error("Unable to create Sources to Query Helper MBean.", e);
    }
    if (mBeanServer == null) {
        return;
    }
    try {
        try {
            mBeanServer.registerMBean(this, objectName);
            LOGGER.info("Registered Sources to Query Helper MBean under object name: {}", objectName);
        } catch (InstanceAlreadyExistsException e) {
            mBeanServer.unregisterMBean(objectName);
            mBeanServer.registerMBean(this, objectName);
            LOGGER.info("Re-registered Sources to Query Helper MBean");
        }
    } catch (MBeanRegistrationException | InstanceNotFoundException | InstanceAlreadyExistsException | NotCompliantMBeanException e) {
        LOGGER.error("Could not register MBean [{}].", objectName.toString(), e);
    }
}
Also used : MalformedObjectNameException(javax.management.MalformedObjectNameException) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) InstanceNotFoundException(javax.management.InstanceNotFoundException) MBeanRegistrationException(javax.management.MBeanRegistrationException) ObjectName(javax.management.ObjectName)

Aggregations

MalformedObjectNameException (javax.management.MalformedObjectNameException)309 ObjectName (javax.management.ObjectName)285 InstanceNotFoundException (javax.management.InstanceNotFoundException)88 MBeanServer (javax.management.MBeanServer)80 MBeanRegistrationException (javax.management.MBeanRegistrationException)75 NotCompliantMBeanException (javax.management.NotCompliantMBeanException)63 InstanceAlreadyExistsException (javax.management.InstanceAlreadyExistsException)59 IOException (java.io.IOException)53 ArrayList (java.util.ArrayList)45 ReflectionException (javax.management.ReflectionException)30 MBeanException (javax.management.MBeanException)23 Test (org.testng.annotations.Test)23 CompositeData (javax.management.openmbean.CompositeData)18 Notification (javax.management.Notification)15 MBeanInfo (javax.management.MBeanInfo)14 AttributeNotFoundException (javax.management.AttributeNotFoundException)13 HashMap (java.util.HashMap)11 Map (java.util.Map)11 IntrospectionException (javax.management.IntrospectionException)11 MalformedURLException (java.net.MalformedURLException)10