/** * 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; }
private void removeAttributeChangeNotificationListener(NotificationListener listener, String attributeName, Object handback) throws MBeanException, RuntimeOperationsException, ListenerNotFoundException { if (listener == null) throw new RuntimeOperationsException(new IllegalArgumentException( "Listener cannot be null.")); AttributeChangeNotificationFilter filter = new AttributeChangeNotificationFilter(); if (attributeName != null) { filter.enableAttribute(attributeName); } else { MBeanAttributeInfo[] ai = m_modelMBeanInfo.getAttributes(); for (int i = 0; i < ai.length; i++) { Descriptor d = ((ModelMBeanAttributeInfo) ai[i]).getDescriptor(); filter.enableAttribute((String) d.getFieldValue("name")); } } getAttributeChangeBroadcaster().removeNotificationListener(listener, filter, handback); Logger logger = getLogger(); if (logger.isEnabledFor(Logger.DEBUG)) logger.debug("Listener " + listener + " for attribute " + attributeName + " removed successfully, handback is " + handback); }
/** * Tests the situation where the property only has a getter. */ @Test public void testWithOnlySetter() throws Exception { ModelMBeanInfo inf = getMBeanInfoFromAssembler(); ModelMBeanAttributeInfo attr = inf.getAttribute("NickName"); assertNotNull("Attribute should not be null", attr); }
/** * Gets the {@code ModelMBeanInfo} for the bean with the supplied key * and of the supplied type. */ private ModelMBeanInfo getMBeanInfo(Object managedBean, String beanKey) throws JMException { ModelMBeanInfo info = this.assembler.getMBeanInfo(managedBean, beanKey); if (logger.isInfoEnabled() && ObjectUtils.isEmpty(info.getAttributes()) && ObjectUtils.isEmpty(info.getOperations())) { logger.info("Bean with key '" + beanKey + "' has been registered as an MBean but has no exposed attributes or operations"); } return info; }
private Logger getModelMBeanLogger(String notificationType) throws MBeanException { // Get a copy to avoid synchronization ModelMBeanInfo info = getModelMBeanInfo(); // First look if there is a suitable notification descriptor, otherwise use MBean descriptor Descriptor descriptor = null; Logger modelMBeanLogger = null; if (notificationType != null) { descriptor = info.getDescriptor(notificationType, "notification"); modelMBeanLogger = findLogger(descriptor); } if (modelMBeanLogger == null) { descriptor = info.getMBeanDescriptor(); modelMBeanLogger = findLogger(descriptor); if (modelMBeanLogger != null) return modelMBeanLogger; } return null; }
ModelMBeanOperationInfo[] operations = (ModelMBeanOperationInfo[]) info.getOperations(); ModelMBeanAttributeInfo[] attributes = (ModelMBeanAttributeInfo[]) info.getAttributes(); info.getClassName(), info.getDescription(), (ModelMBeanAttributeInfo[]) info.getAttributes(), (ModelMBeanConstructorInfo[]) info.getConstructors(), operations, (ModelMBeanNotificationInfo[]) info.getNotifications(), info.getMBeanDescriptor() );
return null; Descriptor mbeanDescriptor = info.getMBeanDescriptor(); if (mbeanDescriptor == null) {
ModelMBeanOperationInfo operInfo = info.getOperation(method); if (operInfo == null) throw new MBeanException(new ServiceNotFoundException( Descriptor mbeanDescriptor = info.getMBeanDescriptor(); if (mbeanDescriptor == null) throw new MBeanException(new ServiceNotFoundException( info.setDescriptor(operationDescriptor, "operation");
ModelMBeanAttributeInfo attrInfo = info.getAttribute(attrName); if (attrInfo == null) throw new AttributeNotFoundException( Descriptor mbeanDescriptor = info.getMBeanDescriptor(); if (mbeanDescriptor == null) throw new AttributeNotFoundException( info.setDescriptor(attributeDescriptor, "attribute");
descriptors = minfo.getDescriptors(MBEAN_DESCRIPTOR); Descriptor descriptor = minfo.getMBeanDescriptor(); descriptor.setField(ModelMBeanConstants.OBJECT_NAME, name); minfo.setMBeanDescriptor(descriptor);
/** */ public void addAttributeChangeNotificationListener( NotificationListener listener, String attributeName, Object handback) throws MBeanException { // Check the attribute info ModelMBeanInfo minfo = (ModelMBeanInfo) info; AttributeChangeNotificationFilter filter = null; if (attributeName != null) { ModelMBeanAttributeInfo ainfo = minfo.getAttribute(attributeName); if( ainfo == null ) { throw new RuntimeOperationsException( new IllegalArgumentException("Attribute does not exist: "+attributeName)); } filter = new AttributeChangeNotificationFilter(); filter.enableAttribute(attributeName); } else { filter = new AttributeChangeNotificationFilter(); MBeanAttributeInfo[] allAttributes = minfo.getAttributes(); for (int i = 0; i < allAttributes.length; ++i) filter.enableAttribute(allAttributes[i].getName()); } notifier.addNotificationListener(listener, filter, handback); }
callback = (PersistentMBean) invocation.getInvoker(); ModelMBeanInfo info = (ModelMBeanInfo) invoker.getMetaData(); Descriptor mbeanDesc = info.getMBeanDescriptor(); Descriptor[] attrDescs = info.getDescriptors(ATTRIBUTE_DESCRIPTOR); for (int i = 0; i < attrDescs.length; ++i)
@Test public void testRegistrationOnInterface() throws Exception { Object bean = getContext().getBean("testInterfaceBean"); ModelMBeanInfo inf = getAssembler().getMBeanInfo(bean, "bean:name=interfaceTestBean"); assertNotNull(inf); assertEquals("My Managed Bean", inf.getDescription()); ModelMBeanOperationInfo op = inf.getOperation("foo"); assertNotNull("foo operation not exposed", op); assertEquals("invoke foo", op.getDescription()); assertNull("doNotExpose operation should not be exposed", inf.getOperation("doNotExpose")); ModelMBeanAttributeInfo attr = inf.getAttribute("Bar"); assertNotNull("bar attribute not exposed", attr); assertEquals("Bar description", attr.getDescription()); ModelMBeanAttributeInfo attr2 = inf.getAttribute("CacheEntries"); assertNotNull("cacheEntries attribute not exposed", attr2); assertEquals("Metric Type should be COUNTER", "COUNTER", attr2.getDescriptor().getFieldValue("metricType")); }
@Test public void testMetricDescription() throws Exception { ModelMBeanInfo inf = getMBeanInfoFromAssembler(); ModelMBeanAttributeInfo metric = inf.getAttribute(QUEUE_SIZE_METRIC); ModelMBeanOperationInfo operation = inf.getOperation("getQueueSize"); assertEquals("The description for the queue size metric is incorrect", "The QueueSize metric", metric.getDescription()); assertEquals("The description for the getter operation of the queue size metric is incorrect", "The QueueSize metric", operation.getDescription()); }
@Override public MBeanNotificationInfo[] getNotificationInfo() { return m_modelMBeanInfo.getNotifications(); }
@Test public void testOperationFromInterface() throws Exception { ModelMBeanInfo inf = getMBeanInfoFromAssembler(); ModelMBeanOperationInfo op = inf.getOperation("fromInterface"); assertNotNull(op); }
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); } }
try mbeanDescriptor = minfo.getDescriptor("", ModelMBeanConstants.MBEAN_DESCRIPTOR);
private boolean isModelMBeanInfoValid(ModelMBeanInfo info) { if (info == null || info.getClassName() == null) return false; // PENDING: maybe more checks are needed return true; }
@Test public void testGetMBeanOperationInfo() throws Exception { ModelMBeanInfo info = getMBeanInfoFromAssembler(); MBeanOperationInfo[] inf = info.getOperations(); assertEquals("Invalid number of Operations returned", getExpectedOperationCount(), inf.length); for (int x = 0; x < inf.length; x++) { assertNotNull("MBeanOperationInfo should not be null", inf[x]); assertNotNull( "Description for MBeanOperationInfo should not be null", inf[x].getDescription()); } }