/** * 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); } }
@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); }
/** * 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; }
/** * 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; }
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); } }
private 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 RuntimeException(e); } catch (InvalidTargetObjectTypeException e) { throw new RuntimeException(e); } catch (InstanceNotFoundException e) { throw new RuntimeException(e); } }
/** * Default constructor for the XMBean Model MBean implementation. This * creates an uninitialized Model MBean template. * @throws MBeanException for any error */ public XMBean() throws MBeanException { try { setManagedResource(new Object(), OBJECT_REF); setModelMBeanInfo(new ModelMBeanInfoSupport("XMBean", "Uninitialized XMBean", new ModelMBeanAttributeInfo[0], new ModelMBeanConstructorInfo[0], new ModelMBeanOperationInfo[0], new ModelMBeanNotificationInfo[0])); } catch (RuntimeException e) { throw new RuntimeOperationsException(e); } catch (Exception e) { throw new MBeanException(e); } }
public MBeanInfo getMBeanInfo() { Descriptor lastLoadDateDesc = new DescriptorSupport(new String[] {"name=LastLoadDate", "descriptorType=attribute", "default=0", "displayName=Last Load Date", "getMethod=getLastLoadDate"}); Descriptor lastLoadTimeDesc = new DescriptorSupport(new String[] {"name=LastLoadTime", "descriptorType=attribute", "default=0", "displayName=Last Load Time", "getMethod=getLoadTime"}); ModelMBeanAttributeInfo[] mmbai = new ModelMBeanAttributeInfo[2]; mmbai[0] = new ModelMBeanAttributeInfo("LastLoadDate", "java.util.Date", "Last Load Date", true, false, false, lastLoadDateDesc); mmbai[1] = new ModelMBeanAttributeInfo("LastLoadTime", "java.lang.Long", "Last Load Time", true, false, false, lastLoadTimeDesc); ModelMBeanOperationInfo[] mmboi = new ModelMBeanOperationInfo[7]; mmboi[0] = new ModelMBeanOperationInfo("start", "Start DSpace Kernel", null, "void", ModelMBeanOperationInfo.ACTION); mmboi[1] = new ModelMBeanOperationInfo("stop", "Stop DSpace Kernel", null, "void", ModelMBeanOperationInfo.ACTION); mmboi[2] = new ModelMBeanOperationInfo("getManagedBean", "Get the Current Kernel", null, DSpaceKernel.class.getName(), ModelMBeanOperationInfo.INFO); return new ModelMBeanInfoSupport(this.getClass().getName(), "DSpace Kernel", mmbai, null, mmboi, null); }
public MBeanInfo getMBeanInfo() { Descriptor lastLoadDateDesc = new DescriptorSupport(new String[] {"name=LastLoadDate", "descriptorType=attribute", "default=0", "displayName=Last Load Date", "getMethod=getLastLoadDate"}); Descriptor lastLoadTimeDesc = new DescriptorSupport(new String[] {"name=LastLoadTime", "descriptorType=attribute", "default=0", "displayName=Last Load Time", "getMethod=getLoadTime" }); ModelMBeanAttributeInfo[] mmbai = new ModelMBeanAttributeInfo[2]; mmbai[0] = new ModelMBeanAttributeInfo("LastLoadDate", "java.util.Date", "Last Load Date", true, false, false, lastLoadDateDesc); mmbai[1] = new ModelMBeanAttributeInfo("LastLoadTime", "java.lang.Long", "Last Load Time", true, false, false, lastLoadTimeDesc); ModelMBeanOperationInfo[] mmboi = new ModelMBeanOperationInfo[7]; mmboi[0] = new ModelMBeanOperationInfo("start", "Start DSpace Kernel", null, "void", ModelMBeanOperationInfo.ACTION); mmboi[1] = new ModelMBeanOperationInfo("stop", "Stop DSpace Kernel", null, "void", ModelMBeanOperationInfo.ACTION); mmboi[2] = new ModelMBeanOperationInfo("getManagedBean", "Get the Current Kernel", null, DSpaceKernel.class.getName(), ModelMBeanOperationInfo.INFO); return new ModelMBeanInfoSupport(this.getClass().getName(), "DSpace Kernel", mmbai, null, mmboi, null); }
public MBeanInfo getMBeanInfo() { Descriptor lastLoadDateDesc = new DescriptorSupport(new String[] {"name=LastLoadDate", "descriptorType=attribute", "default=0", "displayName=Last Load Date", "getMethod=getLastLoadDate"}); Descriptor lastLoadTimeDesc = new DescriptorSupport(new String[] {"name=LastLoadTime", "descriptorType=attribute", "default=0", "displayName=Last Load Time", "getMethod=getLoadTime" }); ModelMBeanAttributeInfo[] mmbai = new ModelMBeanAttributeInfo[2]; mmbai[0] = new ModelMBeanAttributeInfo("LastLoadDate", "java.util.Date", "Last Load Date", true, false, false, lastLoadDateDesc); mmbai[1] = new ModelMBeanAttributeInfo("LastLoadTime", "java.lang.Long", "Last Load Time", true, false, false, lastLoadTimeDesc); ModelMBeanOperationInfo[] mmboi = new ModelMBeanOperationInfo[7]; mmboi[0] = new ModelMBeanOperationInfo("start", "Start DSpace Kernel", null, "void", ModelMBeanOperationInfo.ACTION); mmboi[1] = new ModelMBeanOperationInfo("stop", "Stop DSpace Kernel", null, "void", ModelMBeanOperationInfo.ACTION); mmboi[2] = new ModelMBeanOperationInfo("getManagedBean", "Get the Current Kernel", null, DSpaceKernel.class.getName(), ModelMBeanOperationInfo.INFO); return new ModelMBeanInfoSupport(this.getClass().getName(), "DSpace Kernel", mmbai, null, mmboi, null); }
protected ModelMBeanInfo buildMBeanMetaData(String description, List constructors, List operations, List attributes, List notifications, Descriptor descr) throws NotCompliantMBeanException { ModelMBeanOperationInfo[] operInfo = buildOperationInfo(operations); ModelMBeanAttributeInfo[] attrInfo = buildAttributeInfo(attributes); ModelMBeanConstructorInfo[] constrInfo = buildConstructorInfo(constructors); ModelMBeanNotificationInfo[] notifInfo = buildNotificationInfo(notifications); ModelMBeanInfo info = new ModelMBeanInfoSupport( mmbClassName, description, attrInfo, constrInfo, operInfo, notifInfo, descr ); return info; }
protected ModelMBeanInfo buildMBeanMetaData(String description, List constructors, List operations, List attributes, List notifications, Descriptor descr) throws NotCompliantMBeanException { ModelMBeanOperationInfo[] operInfo = buildOperationInfo(operations); ModelMBeanAttributeInfo[] attrInfo = buildAttributeInfo(attributes); ModelMBeanConstructorInfo[] constrInfo = buildConstructorInfo(constructors); ModelMBeanNotificationInfo[] notifInfo = buildNotificationInfo(notifications); ModelMBeanInfo info = new ModelMBeanInfoSupport( mmbClassName, description, attrInfo, constrInfo, operInfo, notifInfo, descr ); return info; }