List of usage examples for javax.management.modelmbean InvalidTargetObjectTypeException getMessage
public String getMessage()
From source file:org.apache.servicemix.nmr.management.ManagementAgent.java
public void register(Object obj, ObjectName name, boolean forceRegistration) throws JMException { try {//from w w w . ja v a 2 s .c o m registerMBeanWithServer(obj, name, forceRegistration); } catch (NotCompliantMBeanException e) { // If this is not a "normal" MBean, then try to deploy it using JMX // annotations ModelMBeanInfo mbi = assembler.getMBeanInfo(obj, name.toString()); RequiredModelMBean mbean = (RequiredModelMBean) mbeanServer .instantiate(RequiredModelMBean.class.getName()); mbean.setModelMBeanInfo(mbi); try { mbean.setManagedResource(obj, "ObjectReference"); } catch (InvalidTargetObjectTypeException itotex) { throw new JMException(itotex.getMessage()); } registerMBeanWithServer(mbean, name, forceRegistration); } }
From source file:org.apache.camel.management.JmxMBeanAssembler.java
public RequiredModelMBean assemble(Object obj, ObjectName name) throws JMException { ModelMBeanInfo mbi = null;/* www . j a va 2 s . c om*/ // prefer to use the managed instance if it has been annotated with Spring JMX annotations if (obj instanceof ManagedInstance) { Object custom = ((ManagedInstance) obj).getInstance(); if (custom != null && ObjectHelper.hasAnnotation(custom.getClass().getAnnotations(), ManagedResource.class)) { if (LOG.isTraceEnabled()) { LOG.trace("Assembling MBeanInfo for: " + name.toString() + " from custom @ManagedResource object: " + custom); } // get the mbean info from the custom managed object mbi = assembler.getMBeanInfo(custom, name.toString()); // and let the custom object be registered in JMX obj = custom; } } if (mbi == null) { // use the default provided mbean which has been annotated with Spring JMX annotations if (LOG.isTraceEnabled()) { LOG.trace("Assembling MBeanInfo for: " + name.toString() + " from @ManagedResource object: " + obj); } mbi = assembler.getMBeanInfo(obj, name.toString()); } RequiredModelMBean mbean = (RequiredModelMBean) server.instantiate(RequiredModelMBean.class.getName()); mbean.setModelMBeanInfo(mbi); try { mbean.setManagedResource(obj, "ObjectReference"); } catch (InvalidTargetObjectTypeException e) { throw new JMException(e.getMessage()); } return mbean; }
From source file:org.springframework.jmx.export.MBeanExporter.java
/** * Registers the defined beans with the <code>MBeanServer</code>. Each bean is exposed * to the <code>MBeanServer</code> via a <code>ModelMBean</code>. The actual implemetation * of the <code>ModelMBean</code> interface used depends on the implementation of the * <code>ModelMBeanProvider</code> interface that is configured. By default the * <code>RequiredModelMBean</code> class that is supplied with all JMX implementations * is used./*from w ww.j a va 2 s. c om*/ * <p>The management interface produced for each bean is dependent on the * <code>MBeanInfoAssembler</code> implementation being used. * The <code>ObjectName</code> given to each bean is dependent on the implementation * of the <code>ObjectNamingStrategy</code> interface being used. */ protected void registerBeans() throws JMException { // If no server was provided then try to find one. // This is useful in an environment such as JDK 1.5, Tomcat // or JBoss where there is already an MBeanServer loaded. if (this.server == null) { this.server = JmxUtils.locateMBeanServer(); } // The beans property may be <code>null</code>, for example // if we are relying solely on autodetection. if (this.beans == null) { this.beans = new HashMap(); } // Perform autodetection, if desired. if (this.autodetect) { if (this.beanFactory == null) { throw new JMException("Cannot autodetect MBeans if not running in a BeanFactory"); } // Autodetect any beans that are already MBeans. logger.info("Autodetecting user-defined JMX MBeans"); autodetectMBeans(); // Allow the metadata assembler a chance to vote for bean inclusion. if (this.assembler instanceof AutodetectCapableMBeanInfoAssembler) { autodetectBeans((AutodetectCapableMBeanInfoAssembler) this.assembler); } } // Check we now have at least one bean. if (this.beans.isEmpty()) { throw new IllegalArgumentException("Must specify at least one bean for registration"); } this.registeredBeans = new HashSet(this.beans.size()); try { for (Iterator it = this.beans.entrySet().iterator(); it.hasNext();) { Map.Entry entry = (Map.Entry) it.next(); String beanKey = (String) entry.getKey(); Object value = entry.getValue(); ObjectName objectName = registerBeanNameOrInstance(value, beanKey); if (objectName != null) { this.registeredBeans.add(objectName); notifyListenersOfRegistration(objectName); } } } catch (InvalidTargetObjectTypeException ex) { // Unregister beans already registered by this exporter. unregisterBeans(); // We should never get this! throw new JMException("An invalid object type was used when specifying a managed resource. " + "This is a serious error and points to an error in the Spring JMX code. Root cause: " + ex.getMessage()); } catch (JMException ex) { // Unregister beans already registered by this exporter. unregisterBeans(); throw ex; } }