Search in sources :

Example 76 with MBeanAttributeInfo

use of javax.management.MBeanAttributeInfo in project neo4j by neo4j.

the class JmxQueryProcedureTest method shouldHandleCompositeAttributes.

@Test
public void shouldHandleCompositeAttributes() throws Throwable {
    // given
    ObjectName beanName = new ObjectName("org.neo4j:chevyMakesTheTruck=bobMcCoshMakesTheDifference");
    when(jmxServer.queryNames(new ObjectName("*:*"), null)).thenReturn(asSet(beanName));
    when(jmxServer.getMBeanInfo(beanName)).thenReturn(new MBeanInfo("org.neo4j.SomeMBean", "This is a description", new MBeanAttributeInfo[] { new MBeanAttributeInfo("name", "differenceMaker", "Who makes the difference?", true, false, false) }, null, null, null));
    when(jmxServer.getAttribute(beanName, "name")).thenReturn(new CompositeDataSupport(new CompositeType("myComposite", "Composite description", new String[] { "key1", "key2" }, new String[] { "Can't be empty", "Also can't be empty" }, new OpenType<?>[] { SimpleType.STRING, SimpleType.INTEGER }), map("key1", "Hello", "key2", 123)));
    JmxQueryProcedure procedure = new JmxQueryProcedure(ProcedureSignature.procedureName("bob"), jmxServer);
    // when
    RawIterator<Object[], ProcedureException> result = procedure.apply(null, new Object[] { "*:*" });
    // then
    assertThat(asList(result), contains(equalTo(new Object[] { "org.neo4j:chevyMakesTheTruck=bobMcCoshMakesTheDifference", "This is a description", map(attributeName, map("description", "Who makes the difference?", "value", map("description", "Composite description", "properties", map("key1", "Hello", "key2", 123)))) })));
}
Also used : MBeanInfo(javax.management.MBeanInfo) CompositeDataSupport(javax.management.openmbean.CompositeDataSupport) ProcedureException(org.neo4j.kernel.api.exceptions.ProcedureException) MBeanAttributeInfo(javax.management.MBeanAttributeInfo) ObjectName(javax.management.ObjectName) CompositeType(javax.management.openmbean.CompositeType) Test(org.junit.Test)

Example 77 with MBeanAttributeInfo

use of javax.management.MBeanAttributeInfo in project CloudStack-archive by CloudStack-extras.

the class PropertyMapDynamicBean method getMBeanInfo.

@Override
public synchronized MBeanInfo getMBeanInfo() {
    SortedSet<String> names = new TreeSet<String>();
    for (String name : _propMap.keySet()) names.add(name);
    MBeanAttributeInfo[] attrs = new MBeanAttributeInfo[names.size()];
    Iterator<String> it = names.iterator();
    for (int i = 0; i < attrs.length; i++) {
        String name = it.next();
        attrs[i] = new MBeanAttributeInfo(name, "java.lang.String", name, // isReadable
        true, // isWritable
        true, // isIs
        false);
    }
    return new MBeanInfo(this.getClass().getName(), "Dynamic MBean", attrs, null, null, null);
}
Also used : MBeanInfo(javax.management.MBeanInfo) TreeSet(java.util.TreeSet) MBeanAttributeInfo(javax.management.MBeanAttributeInfo)

Example 78 with MBeanAttributeInfo

use of javax.management.MBeanAttributeInfo in project spring-framework by spring-projects.

the class MBeanClientInterceptor method retrieveMBeanInfo.

/**
	 * Loads the management interface info for the configured MBean into the caches.
	 * This information is used by the proxy when determining whether an invocation matches
	 * a valid operation or attribute on the management interface of the managed resource.
	 */
private void retrieveMBeanInfo() throws MBeanInfoRetrievalException {
    try {
        MBeanInfo info = this.serverToUse.getMBeanInfo(this.objectName);
        MBeanAttributeInfo[] attributeInfo = info.getAttributes();
        this.allowedAttributes = new HashMap<>(attributeInfo.length);
        for (MBeanAttributeInfo infoEle : attributeInfo) {
            this.allowedAttributes.put(infoEle.getName(), infoEle);
        }
        MBeanOperationInfo[] operationInfo = info.getOperations();
        this.allowedOperations = new HashMap<>(operationInfo.length);
        for (MBeanOperationInfo infoEle : operationInfo) {
            Class<?>[] paramTypes = JmxUtils.parameterInfoToTypes(infoEle.getSignature(), this.beanClassLoader);
            this.allowedOperations.put(new MethodCacheKey(infoEle.getName(), paramTypes), infoEle);
        }
    } catch (ClassNotFoundException ex) {
        throw new MBeanInfoRetrievalException("Unable to locate class specified in method signature", ex);
    } catch (IntrospectionException ex) {
        throw new MBeanInfoRetrievalException("Unable to obtain MBean info for bean [" + this.objectName + "]", ex);
    } catch (InstanceNotFoundException ex) {
        // if we are this far this shouldn't happen, but...
        throw new MBeanInfoRetrievalException("Unable to obtain MBean info for bean [" + this.objectName + "]: it is likely that this bean was unregistered during the proxy creation process", ex);
    } catch (ReflectionException ex) {
        throw new MBeanInfoRetrievalException("Unable to read MBean info for bean [ " + this.objectName + "]", ex);
    } catch (IOException ex) {
        throw new MBeanInfoRetrievalException("An IOException occurred when communicating with the " + "MBeanServer. It is likely that you are communicating with a remote MBeanServer. " + "Check the inner exception for exact details.", ex);
    }
}
Also used : ReflectionException(javax.management.ReflectionException) MBeanInfo(javax.management.MBeanInfo) MBeanOperationInfo(javax.management.MBeanOperationInfo) InstanceNotFoundException(javax.management.InstanceNotFoundException) IntrospectionException(javax.management.IntrospectionException) IOException(java.io.IOException) MBeanAttributeInfo(javax.management.MBeanAttributeInfo)

Example 79 with MBeanAttributeInfo

use of javax.management.MBeanAttributeInfo in project spring-framework by spring-projects.

the class MethodNameBasedMBeanInfoAssemblerMappedTests method testNickNameIsExposed.

@Test
public void testNickNameIsExposed() throws Exception {
    ModelMBeanInfo inf = (ModelMBeanInfo) getMBeanInfo();
    MBeanAttributeInfo attr = inf.getAttribute("NickName");
    assertNickName(attr);
}
Also used : ModelMBeanInfo(javax.management.modelmbean.ModelMBeanInfo) ModelMBeanAttributeInfo(javax.management.modelmbean.ModelMBeanAttributeInfo) MBeanAttributeInfo(javax.management.MBeanAttributeInfo) Test(org.junit.Test)

Example 80 with MBeanAttributeInfo

use of javax.management.MBeanAttributeInfo in project spring-framework by spring-projects.

the class MethodNameBasedMBeanInfoAssemblerMappedTests method testWithFallThrough.

@Test
public void testWithFallThrough() throws Exception {
    MethodNameBasedMBeanInfoAssembler assembler = getWithMapping("foobar", "add,myOperation,getName,setName,getAge");
    assembler.setManagedMethods("getNickName", "setNickName");
    ModelMBeanInfo inf = assembler.getMBeanInfo(getBean(), getObjectName());
    MBeanAttributeInfo attr = inf.getAttribute("NickName");
    assertNickName(attr);
}
Also used : ModelMBeanInfo(javax.management.modelmbean.ModelMBeanInfo) ModelMBeanAttributeInfo(javax.management.modelmbean.ModelMBeanAttributeInfo) MBeanAttributeInfo(javax.management.MBeanAttributeInfo) Test(org.junit.Test)

Aggregations

MBeanAttributeInfo (javax.management.MBeanAttributeInfo)106 MBeanInfo (javax.management.MBeanInfo)75 ObjectName (javax.management.ObjectName)45 MBeanOperationInfo (javax.management.MBeanOperationInfo)24 Test (org.junit.Test)21 MBeanServer (javax.management.MBeanServer)15 ArrayList (java.util.ArrayList)13 AttributeNotFoundException (javax.management.AttributeNotFoundException)12 ReflectionException (javax.management.ReflectionException)12 ModelMBeanAttributeInfo (javax.management.modelmbean.ModelMBeanAttributeInfo)11 IOException (java.io.IOException)10 AttributeList (javax.management.AttributeList)10 Attribute (javax.management.Attribute)9 InstanceNotFoundException (javax.management.InstanceNotFoundException)9 IntrospectionException (javax.management.IntrospectionException)9 MBeanParameterInfo (javax.management.MBeanParameterInfo)9 ModelMBeanInfo (javax.management.modelmbean.ModelMBeanInfo)9 HashMap (java.util.HashMap)8 MBeanConstructorInfo (javax.management.MBeanConstructorInfo)7 MBeanException (javax.management.MBeanException)7