List of usage examples for javax.management MBeanInfo getDescriptor
public Descriptor getDescriptor()
From source file:com.proofpoint.jmx.MBeanRepresentation.java
public MBeanRepresentation(MBeanServer mbeanServer, ObjectName objectName, ObjectMapper objectMapper) throws JMException { this.objectName = objectName; MBeanInfo mbeanInfo = mbeanServer.getMBeanInfo(objectName); className = mbeanInfo.getClassName(); description = mbeanInfo.getDescription(); descriptor = toMap(mbeanInfo.getDescriptor()); //// w w w . jav a 2 s . co m // Attributes // LinkedHashMap<String, MBeanAttributeInfo> attributeInfos = Maps.newLinkedHashMap(); for (MBeanAttributeInfo attributeInfo : mbeanInfo.getAttributes()) { attributeInfos.put(attributeInfo.getName(), attributeInfo); } String[] attributeNames = attributeInfos.keySet().toArray(new String[attributeInfos.size()]); ImmutableList.Builder<AttributeRepresentation> attributes = ImmutableList.builder(); for (Attribute attribute : mbeanServer.getAttributes(objectName, attributeNames).asList()) { String attributeName = attribute.getName(); // use remove so we only include one value for each attribute MBeanAttributeInfo attributeInfo = attributeInfos.remove(attributeName); if (attributeInfo == null) { // unknown extra attribute, could have been added after MBeanInfo was fetched continue; } Object attributeValue = attribute.getValue(); AttributeRepresentation attributeRepresentation = new AttributeRepresentation(attributeInfo, attributeValue, objectMapper); attributes.add(attributeRepresentation); } this.attributes = attributes.build(); // // Operations // ImmutableList.Builder<OperationRepresentation> operations = ImmutableList.builder(); for (MBeanOperationInfo operationInfo : mbeanInfo.getOperations()) { operations.add(new OperationRepresentation(operationInfo)); } this.operations = operations.build(); }
From source file:org.apache.geode.management.internal.security.MBeanServerWrapper.java
private ResourcePermission getOperationContext(ObjectName objectName, String featureName, boolean isOp) throws InstanceNotFoundException, ReflectionException { MBeanInfo beanInfo; try {//from w ww . j av a 2 s. c o m beanInfo = mbs.getMBeanInfo(objectName); } catch (IntrospectionException e) { throw new GemFireSecurityException("error getting beanInfo of " + objectName, e); } // If there is no annotation defined either in the class level or method level, we should // consider this operation/attribute freely accessible ResourcePermission result = null; // find the context in the beanInfo if defined in the class level result = getOperationContext(beanInfo.getDescriptor(), result); MBeanFeatureInfo[] featureInfos; if (isOp) { featureInfos = beanInfo.getOperations(); } else { featureInfos = beanInfo.getAttributes(); } // still look into the attributes/operations to see if it's defined in the method level for (MBeanFeatureInfo info : featureInfos) { if (info.getName().equals(featureName)) { // found the featureInfo of this method on the bean result = getOperationContext(info.getDescriptor(), result); break; } } return result; }
From source file:org.eclipse.virgo.repository.internal.remote.RemoteRepositoryTests.java
@Test public void mBeanPublication() throws Exception { URI repositoryUri = URI.create("http://localhost:8080/repository"); RemoteRepositoryConfiguration configuration = new RemoteRepositoryConfiguration("remote-repo", this.proxyIndexLocation, repositoryUri, 1, MBEAN_DOMAIN_VIRGO_WEB_SERVER, this.cacheDirectory); RemoteRepository repository = new RemoteRepository(configuration, new MockEventLogger()); ObjectName objectName = new ObjectName(MBEAN_DOMAIN_VIRGO_WEB_SERVER + ":type=Repository,name=remote-repo"); MBeanServer platformMBeanServer = ManagementFactory.getPlatformMBeanServer(); try {/*from ww w. j a v a 2 s. c o m*/ platformMBeanServer.getMBeanInfo(objectName); fail("MBean should not be present until repository has been started"); } catch (InstanceNotFoundException infe) { } repository.start(); MBeanInfo mBeanInfo = platformMBeanServer.getMBeanInfo(objectName); Object type = mBeanInfo.getDescriptor().getFieldValue("type"); assertNotNull(type); assertEquals("remote", type); repository.stop(); try { platformMBeanServer.getMBeanInfo(objectName); fail("MBean should not be present once repository has been stopped"); } catch (InstanceNotFoundException infe) { } }