/** * Create a model mbean from an object using the description given in the * Jmx annotation if present. Only operations are supported so far, no * attributes, constructors, or notifications * * @param o The object to create an MBean for * @return The ModelMBean for the given object */ public static ModelMBean createModelMBean(Object o) { try { ModelMBean mbean = new RequiredModelMBean(); JmxManaged annotation = o.getClass().getAnnotation(JmxManaged.class); String description = annotation == null ? "" : annotation.description(); ModelMBeanInfo info = new ModelMBeanInfoSupport(o.getClass().getName(), description, extractAttributeInfo(o), new ModelMBeanConstructorInfo[0], extractOperationInfo(o), new ModelMBeanNotificationInfo[0]); mbean.setModelMBeanInfo(info); mbean.setManagedResource(o, "ObjectReference"); return mbean; } catch(MBeanException e) { throw new VoldemortException(e); } catch(InvalidTargetObjectTypeException e) { throw new VoldemortException(e); } catch(InstanceNotFoundException e) { throw new VoldemortException(e); } }
public void updateAttributeInfo(Descriptor attrDesc) throws MBeanException { ModelMBeanInfoSupport minfo = (ModelMBeanInfoSupport) info; minfo.setDescriptor(attrDesc, ModelMBeanConstants.ATTRIBUTE_DESCRIPTOR); }
public void updateAttributeInfo(Descriptor attrDesc) throws MBeanException { ModelMBeanInfoSupport minfo = (ModelMBeanInfoSupport) info; minfo.setDescriptor(attrDesc, ModelMBeanConstants.ATTRIBUTE_DESCRIPTOR); }
@Test public void testRegisterExistingMBeanWithUserSuppliedObjectName() throws Exception { ObjectName objectName = ObjectNameManager.getInstance("spring:name=Foo"); ModelMBeanInfo info = new ModelMBeanInfoSupport("myClass", "myDescription", null, null, null, null); RequiredModelMBean bean = new RequiredModelMBean(info); MBeanExporter exporter = new MBeanExporter(); exporter.setServer(getServer()); exporter.registerManagedResource(bean, objectName); MBeanInfo infoFromServer = getServer().getMBeanInfo(objectName); assertEquals(info, infoFromServer); }
minfo.setDescriptor(descriptor, ModelMBeanConstants.OPERATION_DESCRIPTOR);
/** * Create an instance of the {@code ModelMBeanInfoSupport} class supplied with all * JMX implementations and populates the metadata through calls to the subclass. * @param managedBean the bean that will be exposed (might be an AOP proxy) * @param beanKey the key associated with the managed bean * @return the populated ModelMBeanInfo instance * @throws JMException in case of errors * @see #getDescription(Object, String) * @see #getAttributeInfo(Object, String) * @see #getConstructorInfo(Object, String) * @see #getOperationInfo(Object, String) * @see #getNotificationInfo(Object, String) * @see #populateMBeanDescriptor(javax.management.Descriptor, Object, String) */ @Override public ModelMBeanInfo getMBeanInfo(Object managedBean, String beanKey) throws JMException { checkManagedBean(managedBean); ModelMBeanInfo info = new ModelMBeanInfoSupport( getClassName(managedBean, beanKey), getDescription(managedBean, beanKey), getAttributeInfo(managedBean, beanKey), getConstructorInfo(managedBean, beanKey), getOperationInfo(managedBean, beanKey), getNotificationInfo(managedBean, beanKey)); Descriptor desc = info.getMBeanDescriptor(); populateMBeanDescriptor(desc, managedBean, beanKey); info.setMBeanDescriptor(desc); return info; }
minfo.setDescriptor(descriptor, ModelMBeanConstants.OPERATION_DESCRIPTOR);
/** * Create an instance of the {@code ModelMBeanInfoSupport} class supplied with all * JMX implementations and populates the metadata through calls to the subclass. * @param managedBean the bean that will be exposed (might be an AOP proxy) * @param beanKey the key associated with the managed bean * @return the populated ModelMBeanInfo instance * @throws JMException in case of errors * @see #getDescription(Object, String) * @see #getAttributeInfo(Object, String) * @see #getConstructorInfo(Object, String) * @see #getOperationInfo(Object, String) * @see #getNotificationInfo(Object, String) * @see #populateMBeanDescriptor(javax.management.Descriptor, Object, String) */ @Override public ModelMBeanInfo getMBeanInfo(Object managedBean, String beanKey) throws JMException { checkManagedBean(managedBean); ModelMBeanInfo info = new ModelMBeanInfoSupport( getClassName(managedBean, beanKey), getDescription(managedBean, beanKey), getAttributeInfo(managedBean, beanKey), getConstructorInfo(managedBean, beanKey), getOperationInfo(managedBean, beanKey), getNotificationInfo(managedBean, beanKey)); Descriptor desc = info.getMBeanDescriptor(); populateMBeanDescriptor(desc, managedBean, beanKey); info.setMBeanDescriptor(desc); return info; }
public MBeanInfo getMBeanInfo(ExposableJmxEndpoint endpoint) { String className = EndpointMBean.class.getName(); String description = getDescription(endpoint); ModelMBeanOperationInfo[] operations = getMBeanOperations(endpoint); return new ModelMBeanInfoSupport(className, description, NO_ATTRIBUTES, NO_CONSTRUCTORS, operations, NO_NOTIFICATIONS); }
/** * Create and return a default <code>ModelMBeanInfo</code> object. */ protected ModelMBeanInfo createDefaultModelMBeanInfo() { return (new ModelMBeanInfoSupport(this.getClass().getName(), "Default ModelMBean", null, null, null, null)); }
public ModelMBeanInfo buildModelMBeanInfo(Descriptor desc) { ModelMBeanOperationInfo[] ops = operations.values().toArray(new ModelMBeanOperationInfo[operations.values().size()]); ModelMBeanAttributeInfo[] atts = attributes.values().toArray(new ModelMBeanAttributeInfo[attributes.values().size()]); ModelMBeanConstructorInfo[] cons = constructors.values().toArray(new ModelMBeanConstructorInfo[constructors.values().size()]); ModelMBeanNotificationInfo[] notifs = notifications.values().toArray(new ModelMBeanNotificationInfo[notifications.values().size()]); return new ModelMBeanInfoSupport("javax.management.modelmbean.ModelMBeanInfo", "description", atts, cons, ops, notifs, desc); }
public ModelMBeanInfo buildModelMBeanInfo(Descriptor desc) { ModelMBeanOperationInfo[] ops = (ModelMBeanOperationInfo[])operations.values().toArray(new ModelMBeanOperationInfo[0]); ModelMBeanAttributeInfo[] atts = (ModelMBeanAttributeInfo[])attributes.values().toArray(new ModelMBeanAttributeInfo[0]); ModelMBeanConstructorInfo[] cons = (ModelMBeanConstructorInfo[])constructors.values().toArray(new ModelMBeanConstructorInfo[0]); ModelMBeanNotificationInfo[] notifs = (ModelMBeanNotificationInfo[])notifications.values().toArray(new ModelMBeanNotificationInfo[0]); return new ModelMBeanInfoSupport("javax.management.modelmbean.ModelMBeanInfo", "description", atts, cons, ops, notifs, desc); }
public synchronized MBeanInfo getMBeanInfo() { log.debug("getMBeanInfo"); if (_dirty) { _dirty=false; ModelMBeanAttributeInfo[] attributes = (ModelMBeanAttributeInfo[]) _attributes.toArray(new ModelMBeanAttributeInfo[_attributes.size()]); ModelMBeanOperationInfo[] operations = (ModelMBeanOperationInfo[]) _operations.toArray(new ModelMBeanOperationInfo[_operations.size()]); ModelMBeanNotificationInfo[] notifications =(ModelMBeanNotificationInfo[]) _notifications.toArray(new ModelMBeanNotificationInfo[_notifications.size()]); _beanInfo = new ModelMBeanInfoSupport(_object.getClass().getName(), findDescription(null), attributes, null, operations, notifications); } return _beanInfo; }
public synchronized MBeanInfo getMBeanInfo() { log.debug("getMBeanInfo"); if (_dirty) { _dirty=false; ModelMBeanAttributeInfo[] attributes = (ModelMBeanAttributeInfo[]) _attributes.toArray(new ModelMBeanAttributeInfo[_attributes.size()]); ModelMBeanOperationInfo[] operations = (ModelMBeanOperationInfo[]) _operations.toArray(new ModelMBeanOperationInfo[_operations.size()]); ModelMBeanNotificationInfo[] notifications =(ModelMBeanNotificationInfo[]) _notifications.toArray(new ModelMBeanNotificationInfo[_notifications.size()]); _beanInfo = new ModelMBeanInfoSupport(_object.getClass().getName(), findDescription(null), attributes, null, operations, notifications); } return _beanInfo; }
private MBeanInfo createModelMBeanInfo(T source) { String className = source.getClass().getName(); String description = ""; ModelMBeanConstructorInfo[] constructors = new ModelMBeanConstructorInfo[0]; ModelMBeanNotificationInfo[] notifications = new ModelMBeanNotificationInfo[0]; List<ModelMBeanAttributeInfo> attributes = new ArrayList<ModelMBeanAttributeInfo>(); List<ModelMBeanOperationInfo> operations = new ArrayList<ModelMBeanOperationInfo>(); addAttributes(attributes, source); addExtraAttributes(attributes); addOperations(operations, source); addExtraOperations(operations); operations.add(new ModelMBeanOperationInfo("unregisterMBean", "unregisterMBean", new MBeanParameterInfo[0], void.class.getName(), ModelMBeanOperationInfo.ACTION)); return new ModelMBeanInfoSupport(className, description, attributes.toArray(new ModelMBeanAttributeInfo[attributes.size()]), constructors, operations.toArray(new ModelMBeanOperationInfo[operations.size()]), notifications); }
private MBeanInfo createModelMBeanInfo(T source) { String className = source.getClass().getName(); String description = ""; ModelMBeanConstructorInfo[] constructors = new ModelMBeanConstructorInfo[0]; ModelMBeanNotificationInfo[] notifications = new ModelMBeanNotificationInfo[0]; List<ModelMBeanAttributeInfo> attributes = new ArrayList<>(); List<ModelMBeanOperationInfo> operations = new ArrayList<>(); addAttributes(attributes, source); addExtraAttributes(attributes); addOperations(operations, source); addExtraOperations(operations); operations.add(new ModelMBeanOperationInfo( "unregisterMBean", "unregisterMBean", new MBeanParameterInfo[0], void.class.getName(), ModelMBeanOperationInfo.ACTION)); return new ModelMBeanInfoSupport( className, description, attributes.toArray(new ModelMBeanAttributeInfo[attributes.size()]), constructors, operations.toArray(new ModelMBeanOperationInfo[operations.size()]), notifications); }
public RequiredModelMBean newModelMBean() throws MBeanException { Descriptor mmbDesc = new DescriptorSupport(); mmbDesc.setField( "name", objectName.toString() ); mmbDesc.setField( "descriptorType", "mbean" ); mmbDesc.setField( "displayName", displayName ); ModelMBeanInfo modelMBeanInfo = new ModelMBeanInfoSupport( className, displayName, attributes.toArray( new ModelMBeanAttributeInfo[attributes.size()]), constructors.toArray( new ModelMBeanConstructorInfo[constructors.size()]), operations.toArray( new ModelMBeanOperationInfo[operations.size()]), notifications.toArray( new ModelMBeanNotificationInfo[notifications.size()]) ); modelMBeanInfo.setMBeanDescriptor( mmbDesc ); return new RequiredModelMBean(modelMBeanInfo); } }
public RequiredModelMBean newModelMBean() throws MBeanException { Descriptor mmbDesc = new DescriptorSupport(); mmbDesc.setField( "name", objectName.toString() ); mmbDesc.setField( "descriptorType", "mbean" ); mmbDesc.setField( "displayName", displayName ); ModelMBeanInfo modelMBeanInfo = new ModelMBeanInfoSupport( className, displayName, attributes.toArray( new ModelMBeanAttributeInfo[attributes.size()]), constructors.toArray( new ModelMBeanConstructorInfo[constructors.size()]), operations.toArray( new ModelMBeanOperationInfo[operations.size()]), notifications.toArray( new ModelMBeanNotificationInfo[notifications.size()]) ); modelMBeanInfo.setMBeanDescriptor( mmbDesc ); return new RequiredModelMBean(modelMBeanInfo); } }
public Object instantiate() { ModelMBeanOperationInfo[] ops = new ModelMBeanOperationInfo[operInfo.size()]; operInfo.toArray(ops); ModelMBeanAttributeInfo[] attrs = new ModelMBeanAttributeInfo[attrInfo.size()]; attrInfo.toArray(attrs); ModelMBeanConstructorInfo[] ctors = new ModelMBeanConstructorInfo[constrInfo.size()]; constrInfo.toArray(ctors); ModelMBeanNotificationInfo[] msgs = new ModelMBeanNotificationInfo[notifInfo.size()]; notifInfo.toArray(msgs); // Validate the required descriptor fields if( descriptor != null ) { if( descriptor.getFieldValue(ModelMBeanConstants.NAME) == null ) descriptor.setField(ModelMBeanConstants.NAME, getClassName()); if( descriptor.getFieldValue(ModelMBeanConstants.DESCRIPTOR_TYPE) == null ) descriptor.setField(ModelMBeanConstants.DESCRIPTOR_TYPE, ModelMBeanConstants.MBEAN_DESCRIPTOR); } ModelMBeanInfo info = new ModelMBeanInfoSupport( mmbClassName, description, attrs, ctors, ops, msgs, descriptor); return info; }
managementInfo = new ModelMBeanInfoSupport(clazz.getCanonicalName(), "", attributesInfo.values().toArray( new ModelMBeanAttributeInfo[attributesInfo.size()]), constructorsInfo.values().toArray( new ModelMBeanConstructorInfo[constructorsInfo.size()]), operationsInfo.values().toArray(