Search in sources :

Example 51 with MBeanAttributeInfo

use of javax.management.MBeanAttributeInfo in project tomee by apache.

the class StatelessInvocationStatsTest method testBasic.

/**
     * This whole method is a template, feel free to split it anyway you like
     * Fine to have one big
     *
     * @throws Exception
     */
public void testBasic() throws Exception {
    // some pre-load to avoid to load the class lazily with the first invocation
    new CounterBean().red();
    new CounterBean().blue();
    new CounterBean().green();
    // end preload
    System.setProperty(javax.naming.Context.INITIAL_CONTEXT_FACTORY, org.apache.openejb.core.LocalInitialContextFactory.class.getName());
    final ConfigurationFactory config = new ConfigurationFactory();
    final Assembler assembler = new Assembler();
    assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
    assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
    // containers
    final StatelessSessionContainerInfo statelessContainerInfo = config.configureService(StatelessSessionContainerInfo.class);
    statelessContainerInfo.properties.setProperty("AccessTimeout", "100");
    statelessContainerInfo.properties.setProperty("MaxSize", "15");
    statelessContainerInfo.properties.setProperty("MinSize", "3");
    statelessContainerInfo.properties.setProperty("StrictPooling", "true");
    assembler.createContainer(statelessContainerInfo);
    // Setup the descriptor information
    CounterBean.instances.set(0);
    final EjbJar ejbJar = new EjbJar("StatsModule");
    ejbJar.addEnterpriseBean(new StatelessBean(CounterBean.class));
    assembler.createApplication(config.configureApplication(ejbJar));
    final javax.naming.Context context = new InitialContext();
    final CounterBean bean = (CounterBean) context.lookup("CounterBeanLocalBean");
    // Invoke each method once
    bean.red();
    bean.green();
    bean.blue();
    final MBeanServer server = LocalMBeanServer.get();
    final ObjectName invocationsName = new ObjectName("openejb.management:J2EEServer=openejb,J2EEApplication=<empty>,EJBModule=StatsModule,StatelessSessionBean=CounterBean,j2eeType=Invocations,name=CounterBean");
    // Grab the mbeanInfo and check the expected attributes exist and have the correct return types and parameters
    /*
        * Invocation MBeanInfo
        *
        */
    final List<MBeanAttributeInfo> expectedAttributes = new ArrayList<MBeanAttributeInfo>();
    expectedAttributes.add(new MBeanAttributeInfo("InvocationCount", "long", "", true, false, false));
    expectedAttributes.add(new MBeanAttributeInfo("InvocationTime", "long", "", true, false, false));
    expectedAttributes.add(new MBeanAttributeInfo("MonitoredMethods", "long", "", true, false, false));
    final Map<String, Object> expectedValues = new TreeMap<String, Object>();
    expectedValues.put("InvocationCount", (long) 6);
    expectedValues.put("InvocationTime", (long) 0);
    expectedValues.put("MonitoredMethods", (long) 4);
    final String[] methods = { "PostConstruct()", "blue()", "green()", "red()" };
    for (final String s : methods) {
        expectedAttributes.add(new MBeanAttributeInfo(s + ".Count", "long", "", true, false, false));
        expectedAttributes.add(new MBeanAttributeInfo(s + ".GeometricMean", "double", "", true, false, false));
        expectedAttributes.add(new MBeanAttributeInfo(s + ".Kurtosis", "double", "", true, false, false));
        expectedAttributes.add(new MBeanAttributeInfo(s + ".Max", "double", "", true, false, false));
        expectedAttributes.add(new MBeanAttributeInfo(s + ".Mean", "double", "", true, false, false));
        expectedAttributes.add(new MBeanAttributeInfo(s + ".Min", "double", "", true, false, false));
        expectedAttributes.add(new MBeanAttributeInfo(s + ".Percentile01", "double", "", true, false, false));
        expectedAttributes.add(new MBeanAttributeInfo(s + ".Percentile10", "double", "", true, false, false));
        expectedAttributes.add(new MBeanAttributeInfo(s + ".Percentile25", "double", "", true, false, false));
        expectedAttributes.add(new MBeanAttributeInfo(s + ".Percentile50", "double", "", true, false, false));
        expectedAttributes.add(new MBeanAttributeInfo(s + ".Percentile75", "double", "", true, false, false));
        expectedAttributes.add(new MBeanAttributeInfo(s + ".Percentile90", "double", "", true, false, false));
        expectedAttributes.add(new MBeanAttributeInfo(s + ".Percentile99", "double", "", true, false, false));
        expectedAttributes.add(new MBeanAttributeInfo(s + ".SampleSize", "int", "", true, false, false));
        expectedAttributes.add(new MBeanAttributeInfo(s + ".Skewness", "double", "", true, false, false));
        expectedAttributes.add(new MBeanAttributeInfo(s + ".StandardDeviation", "double", "", true, false, false));
        expectedAttributes.add(new MBeanAttributeInfo(s + ".Sum", "double", "", true, false, false));
        expectedAttributes.add(new MBeanAttributeInfo(s + ".Sumsq", "double", "", true, false, false));
        expectedAttributes.add(new MBeanAttributeInfo(s + ".Variance", "double", "", true, false, false));
        if (s.equals("PostConstruct()")) {
            expectedValues.put(s + ".Count", (long) 3);
        } else {
            expectedValues.put(s + ".Count", (long) 1);
        }
        expectedValues.put(s + ".GeometricMean", 0.0);
        expectedValues.put(s + ".Kurtosis", Double.NaN);
        expectedValues.put(s + ".Max", 0.0);
        expectedValues.put(s + ".Mean", 0.0);
        expectedValues.put(s + ".Min", 0.0);
        expectedValues.put(s + ".Percentile01", 0.0);
        expectedValues.put(s + ".Percentile10", 0.0);
        expectedValues.put(s + ".Percentile25", 0.0);
        expectedValues.put(s + ".Percentile50", 0.0);
        expectedValues.put(s + ".Percentile75", 0.0);
        expectedValues.put(s + ".Percentile90", 0.0);
        expectedValues.put(s + ".Percentile99", 0.0);
        expectedValues.put(s + ".SampleSize", 2000);
        expectedValues.put(s + ".Skewness", Double.NaN);
        expectedValues.put(s + ".StandardDeviation", 0.0);
        expectedValues.put(s + ".Sum", 0.0);
        expectedValues.put(s + ".Sumsq", 0.0);
        expectedValues.put(s + ".Variance", 0.0);
    }
    final List<MBeanAttributeInfo> actualAttributes = new ArrayList<MBeanAttributeInfo>();
    final Map<String, Object> actualValues = new TreeMap<String, Object>();
    final MBeanInfo beanInfo = server.getMBeanInfo(invocationsName);
    for (final MBeanAttributeInfo info : beanInfo.getAttributes()) {
        actualAttributes.add(info);
        actualValues.put(info.getName(), server.getAttribute(invocationsName, info.getName()));
    }
    //Verify invocation attributes and values
    assertEquals(expectedAttributes, actualAttributes);
    boolean ok = true;
    for (final Map.Entry<String, Object> entry : actualValues.entrySet()) {
        final Number value = (Number) expectedValues.get(entry.getKey());
        final Number real = (Number) actualValues.get(entry.getKey());
        if (!value.equals(real)) {
            // tolerating a 1 wide range
            Logger.getLogger(StatelessInvocationStatsTest.class.getName()).log(Level.WARNING, "Test tolerance: " + entry.getKey() + " => " + entry.getValue() + "/" + expectedValues.get(entry.getKey()));
            final Double abs = Math.abs(real.doubleValue() - value.doubleValue());
            if (abs.intValue() > 1) {
                ok = false;
            }
        }
    }
    // assertEquals(expectedValues, actualValues);
    assertTrue(ok);
    // Grab invocation mbean operations
    final MBeanParameterInfo[] invocationParameters1 = { new MBeanParameterInfo("excludeRegex", "java.lang.String", "\"\""), new MBeanParameterInfo("includeRegex", "java.lang.String", "\"\"") };
    final MBeanParameterInfo[] invocationParameters2 = { new MBeanParameterInfo("p1", "int", "") };
    final List<MBeanOperationInfo> expectedOperations = new ArrayList<MBeanOperationInfo>();
    expectedOperations.add(new MBeanOperationInfo("FilterAttributes", "Filters the attributes that show up in the MBeanInfo.  The exclude is applied first, then any attributes that match the include are re-added.  It may be required to disconnect and reconnect the JMX console to force a refresh of the MBeanInfo", invocationParameters1, "void", MBeanOperationInfo.UNKNOWN));
    for (final String s : methods) {
        expectedOperations.add(new MBeanOperationInfo(s + ".setSampleSize", "", invocationParameters2, "void", MBeanOperationInfo.UNKNOWN));
        expectedOperations.add(new MBeanOperationInfo(s + ".sortedValues", "", new MBeanParameterInfo[0], "[D", MBeanOperationInfo.UNKNOWN));
        expectedOperations.add(new MBeanOperationInfo(s + ".values", "", new MBeanParameterInfo[0], "[D", MBeanOperationInfo.UNKNOWN));
    }
    final List<MBeanOperationInfo> actualOperations1 = new ArrayList<MBeanOperationInfo>();
    actualOperations1.addAll(Arrays.asList(beanInfo.getOperations()));
    //Verify invocation operation information and remove bean.
    assertEquals(expectedOperations, actualOperations1);
}
Also used : StatelessSessionContainerInfo(org.apache.openejb.assembler.classic.StatelessSessionContainerInfo) MBeanInfo(javax.management.MBeanInfo) ArrayList(java.util.ArrayList) ConfigurationFactory(org.apache.openejb.config.ConfigurationFactory) SecurityServiceInfo(org.apache.openejb.assembler.classic.SecurityServiceInfo) EjbJar(org.apache.openejb.jee.EjbJar) MBeanServer(javax.management.MBeanServer) LocalMBeanServer(org.apache.openejb.monitoring.LocalMBeanServer) MBeanOperationInfo(javax.management.MBeanOperationInfo) TreeMap(java.util.TreeMap) InitialContext(javax.naming.InitialContext) MBeanAttributeInfo(javax.management.MBeanAttributeInfo) ObjectName(javax.management.ObjectName) TransactionServiceInfo(org.apache.openejb.assembler.classic.TransactionServiceInfo) StatelessBean(org.apache.openejb.jee.StatelessBean) Assembler(org.apache.openejb.assembler.classic.Assembler) Map(java.util.Map) TreeMap(java.util.TreeMap) MBeanParameterInfo(javax.management.MBeanParameterInfo)

Example 52 with MBeanAttributeInfo

use of javax.management.MBeanAttributeInfo in project tomee by apache.

the class StatelessPoolStatsTest method testBasic.

/**
     * @throws Exception On error
     */
public void testBasic() throws Exception {
    final Properties properties = new Properties();
    properties.setProperty("AccessTimeout", "100");
    properties.setProperty("MaxSize", "15");
    properties.setProperty("SweepInterval", "10 ms");
    properties.setProperty("MinSize", "3");
    properties.setProperty("StrictPooling", "true");
    deploy("testBasic", properties);
    // Grab the mbeanInfo and check the expected attributes exist and have the correct return types and parameters
    final MBeanInfo poolMBeanInfo = server.getMBeanInfo(objectName);
    /*
        * Pool MBeanInfo
        *
        */
    final List<MBeanAttributeInfo> expectedAttributes = new ArrayList<MBeanAttributeInfo>();
    expectedAttributes.add(new MBeanAttributeInfo("AccessTimeouts", "long", "", true, false, false));
    expectedAttributes.add(new MBeanAttributeInfo("AccessTimeouts.Latest", "java.lang.String", "", true, false, false));
    expectedAttributes.add(new MBeanAttributeInfo("AccessTimeouts.LatestTime", "long", "", true, false, false));
    expectedAttributes.add(new MBeanAttributeInfo("Aged", "long", "", true, false, false));
    expectedAttributes.add(new MBeanAttributeInfo("Aged.Latest", "java.lang.String", "", true, false, false));
    expectedAttributes.add(new MBeanAttributeInfo("Aged.LatestTime", "long", "", true, false, false));
    expectedAttributes.add(new MBeanAttributeInfo("AvailablePermits", "int", "", true, false, false));
    expectedAttributes.add(new MBeanAttributeInfo("Flushed", "long", "", true, false, false));
    expectedAttributes.add(new MBeanAttributeInfo("Flushed.Latest", "java.lang.String", "", true, false, false));
    expectedAttributes.add(new MBeanAttributeInfo("Flushed.LatestTime", "long", "", true, false, false));
    expectedAttributes.add(new MBeanAttributeInfo("Flushes", "long", "", true, false, false));
    expectedAttributes.add(new MBeanAttributeInfo("Flushes.Latest", "java.lang.String", "", true, false, false));
    expectedAttributes.add(new MBeanAttributeInfo("Flushes.LatestTime", "long", "", true, false, false));
    expectedAttributes.add(new MBeanAttributeInfo("GarbageCollected", "long", "", true, false, false));
    expectedAttributes.add(new MBeanAttributeInfo("GarbageCollected.Latest", "java.lang.String", "", true, false, false));
    expectedAttributes.add(new MBeanAttributeInfo("GarbageCollected.LatestTime", "long", "", true, false, false));
    expectedAttributes.add(new MBeanAttributeInfo("GarbageCollection", "boolean", "", true, false, false));
    expectedAttributes.add(new MBeanAttributeInfo("IdleTimeout", "long", "", true, false, false));
    expectedAttributes.add(new MBeanAttributeInfo("IdleTimeouts", "long", "", true, false, false));
    expectedAttributes.add(new MBeanAttributeInfo("IdleTimeouts.Latest", "java.lang.String", "", true, false, false));
    expectedAttributes.add(new MBeanAttributeInfo("IdleTimeouts.LatestTime", "long", "", true, false, false));
    expectedAttributes.add(new MBeanAttributeInfo("InstancesActive", "int", "", true, false, false));
    expectedAttributes.add(new MBeanAttributeInfo("InstancesIdle", "int", "", true, false, false));
    expectedAttributes.add(new MBeanAttributeInfo("InstancesInitializing", "int", "", true, false, false));
    expectedAttributes.add(new MBeanAttributeInfo("InstancesPooled", "int", "", true, false, false));
    expectedAttributes.add(new MBeanAttributeInfo("MaxAge", "long", "", true, false, false));
    expectedAttributes.add(new MBeanAttributeInfo("MaxAgeOffset", "double", "", true, false, false));
    expectedAttributes.add(new MBeanAttributeInfo("MaxSize", "int", "", true, false, false));
    expectedAttributes.add(new MBeanAttributeInfo("MinSize", "int", "", true, false, false));
    expectedAttributes.add(new MBeanAttributeInfo("MinimumInstances", "int", "", true, false, false));
    expectedAttributes.add(new MBeanAttributeInfo("Overdrafts", "long", "", true, false, false));
    expectedAttributes.add(new MBeanAttributeInfo("Overdrafts.Latest", "java.lang.String", "", true, false, false));
    expectedAttributes.add(new MBeanAttributeInfo("Overdrafts.LatestTime", "long", "", true, false, false));
    expectedAttributes.add(new MBeanAttributeInfo("PoolVersion", "int", "", true, false, false));
    expectedAttributes.add(new MBeanAttributeInfo("ReplaceAged", "boolean", "", true, false, false));
    expectedAttributes.add(new MBeanAttributeInfo("ReplaceFlushed", "boolean", "", true, false, false));
    expectedAttributes.add(new MBeanAttributeInfo("Replaced", "long", "", true, false, false));
    expectedAttributes.add(new MBeanAttributeInfo("Replaced.Latest", "java.lang.String", "", true, false, false));
    expectedAttributes.add(new MBeanAttributeInfo("Replaced.LatestTime", "long", "", true, false, false));
    expectedAttributes.add(new MBeanAttributeInfo("StrictPooling", "boolean", "", true, false, false));
    expectedAttributes.add(new MBeanAttributeInfo("SweepInterval", "long", "", true, false, false));
    expectedAttributes.add(new MBeanAttributeInfo("Sweeps", "long", "", true, false, false));
    expectedAttributes.add(new MBeanAttributeInfo("Sweeps.Latest", "java.lang.String", "", true, false, false));
    expectedAttributes.add(new MBeanAttributeInfo("Sweeps.LatestTime", "long", "", true, false, false));
    // The hardest part, check the values of each, PoolVersion is AtomicaInteger, *.Latest are time-sensitive, so not verified.
    final Map<String, Object> expectedAttributesValue = new TreeMap<String, Object>();
    expectedAttributesValue.put("AccessTimeouts", (long) 0);
    expectedAttributesValue.put("Aged", (long) 0);
    expectedAttributesValue.put("AvailablePermits", 15);
    expectedAttributesValue.put("Flushed", (long) 0);
    expectedAttributesValue.put("Flushes", (long) 0);
    expectedAttributesValue.put("GarbageCollected", (long) 0);
    expectedAttributesValue.put("GarbageCollection", false);
    expectedAttributesValue.put("IdleTimeout", (long) 0);
    expectedAttributesValue.put("IdleTimeouts", (long) 0);
    expectedAttributesValue.put("InstancesPooled", 3);
    expectedAttributesValue.put("InstancesActive", 0);
    expectedAttributesValue.put("InstancesIdle", 3);
    expectedAttributesValue.put("InstancesInitializing", 0);
    expectedAttributesValue.put("MaxAge", (long) 0);
    expectedAttributesValue.put("MaxAgeOffset", -1.0);
    expectedAttributesValue.put("MaxSize", 15);
    expectedAttributesValue.put("MinSize", 3);
    expectedAttributesValue.put("MinimumInstances", 3);
    expectedAttributesValue.put("Overdrafts", (long) 0);
    expectedAttributesValue.put("PoolVersion", 0);
    expectedAttributesValue.put("ReplaceAged", true);
    expectedAttributesValue.put("ReplaceFlushed", false);
    expectedAttributesValue.put("Replaced", (long) 0);
    expectedAttributesValue.put("SweepInterval", (long) 10);
    // expectedAttributesValue.put("Sweeps", (long) 1);
    expectedAttributesValue.put("StrictPooling", true);
    final List<MBeanAttributeInfo> actualAttributes = new ArrayList<MBeanAttributeInfo>();
    final Map<String, Object> actualAttributesValue = new TreeMap<String, Object>();
    for (final MBeanAttributeInfo info : poolMBeanInfo.getAttributes()) {
        actualAttributes.add(info);
        if (!info.getName().endsWith(".Latest") && !info.getName().endsWith(".LatestTime") && !info.getName().equals("Sweeps")) {
            actualAttributesValue.put(info.getName(), server.getAttribute(objectName, info.getName()));
        }
    }
    assertEquals(expectedAttributes, actualAttributes);
    assertEquals(expectedAttributesValue, actualAttributesValue);
    // Grab pool mbean operations
    final MBeanParameterInfo[] operations = { new MBeanParameterInfo("excludeRegex", "java.lang.String", "\"\""), new MBeanParameterInfo("includeRegex", "java.lang.String", "\"\"") };
    final List<MBeanOperationInfo> expectedOperations = new ArrayList<MBeanOperationInfo>();
    expectedOperations.add(new MBeanOperationInfo("FilterAttributes", "Filters the attributes that show up in the MBeanInfo.  The exclude is applied first, then any attributes that match the include are re-added.  It may be required to disconnect and reconnect the JMX console to force a refresh of the MBeanInfo", operations, "void", MBeanOperationInfo.UNKNOWN));
    expectedOperations.add(new MBeanOperationInfo("flush", "", new MBeanParameterInfo[0], "void", MBeanOperationInfo.UNKNOWN));
    final List<MBeanOperationInfo> actualOperations = new ArrayList<MBeanOperationInfo>();
    actualOperations.addAll(Arrays.asList(poolMBeanInfo.getOperations()));
    assertEquals(expectedOperations, actualOperations);
}
Also used : MBeanInfo(javax.management.MBeanInfo) MBeanOperationInfo(javax.management.MBeanOperationInfo) ArrayList(java.util.ArrayList) Properties(java.util.Properties) TreeMap(java.util.TreeMap) MBeanAttributeInfo(javax.management.MBeanAttributeInfo) MBeanParameterInfo(javax.management.MBeanParameterInfo)

Example 53 with MBeanAttributeInfo

use of javax.management.MBeanAttributeInfo in project tomee by apache.

the class JMXDataSourceTest method getDatasourceJmxMap.

private Map<String, Object> getDatasourceJmxMap() throws MalformedObjectNameException, InstanceNotFoundException, IntrospectionException, ReflectionException, MBeanException, AttributeNotFoundException {
    final ObjectName on = new ObjectName("openejb.management:ObjectType=datasources,DataSource=JMXDataSourceTest");
    final MBeanInfo mBeanInfo = ManagementFactory.getPlatformMBeanServer().getMBeanInfo(on);
    assertNotNull(mBeanInfo);
    final Map<String, Object> map = new HashMap<String, Object>();
    for (final MBeanAttributeInfo mBeanAttributeInfo : mBeanInfo.getAttributes()) {
        final String name = mBeanAttributeInfo.getName();
        final Object value = ManagementFactory.getPlatformMBeanServer().getAttribute(on, name);
        map.put(name, value);
    }
    return map;
}
Also used : MBeanInfo(javax.management.MBeanInfo) HashMap(java.util.HashMap) MBeanAttributeInfo(javax.management.MBeanAttributeInfo) ObjectName(javax.management.ObjectName)

Example 54 with MBeanAttributeInfo

use of javax.management.MBeanAttributeInfo in project sling by apache.

the class JMXResourceProvider method listChildren.

/**
     * @see org.apache.sling.api.resource.ResourceProvider#listChildren(org.apache.sling.api.resource.Resource)
     */
public Iterator<Resource> listChildren(final Resource parent) {
    final PathInfo info = this.parse(parent.getPath());
    if (info != null) {
        if (info.isRoot || info.mbeanInfo == null) {
            // list all MBeans
            final Set<ObjectName> names = this.queryObjectNames(info.isRoot ? null : info.pathInfo);
            final Set<String> filteredNames = new HashSet<String>();
            final String prefix = (info.isRoot ? null : info.pathInfo + "/");
            for (final ObjectName name : names) {
                final String path = this.convertObjectNameToResourcePath(name);
                final String testName = (info.isRoot ? path : path.substring(prefix.length()));
                final int sep = testName.indexOf('/');
                if (sep == -1) {
                    filteredNames.add(":" + name.getCanonicalName());
                } else {
                    filteredNames.add(testName.substring(0, sep));
                }
            }
            final List<String> sortedNames = new ArrayList<String>(filteredNames);
            Collections.sort(sortedNames);
            final Iterator<String> iter = sortedNames.iterator();
            return new Iterator<Resource>() {

                private Resource next;

                {
                    seek();
                }

                private void seek() {
                    while (iter.hasNext() && this.next == null) {
                        final String name = iter.next();
                        if (name.startsWith(":")) {
                            try {
                                final ObjectName on = new ObjectName(name.substring(1));
                                final MBeanInfo info = mbeanServer.getMBeanInfo(on);
                                final String path = convertObjectNameToResourcePath(on);
                                final int sep = path.lastIndexOf('/');
                                this.next = new MBeanResource(mbeanServer, parent.getResourceResolver(), path, parent.getPath() + "/" + path.substring(sep + 1), info, on);
                            } catch (final IntrospectionException e) {
                            // ignore
                            } catch (final InstanceNotFoundException e) {
                            // ignore
                            } catch (final ReflectionException e) {
                            // ignore
                            } catch (final MalformedObjectNameException e) {
                            // ignore
                            }
                        } else {
                            this.next = new RootResource(parent.getResourceResolver(), parent.getPath() + '/' + name);
                        }
                    }
                }

                public boolean hasNext() {
                    return next != null;
                }

                public Resource next() {
                    if (next != null) {
                        final Resource rsrc = next;
                        this.next = null;
                        seek();
                        return rsrc;
                    }
                    throw new NoSuchElementException();
                }

                public void remove() {
                    throw new UnsupportedOperationException("remove");
                }
            };
        } else {
            if (info.pathInfo == null) {
                final MBeanResource parentResource;
                if (parent instanceof MBeanResource) {
                    parentResource = (MBeanResource) parent;
                } else {
                    parentResource = (MBeanResource) this.getResource(parent.getResourceResolver(), parent.getPath());
                }
                final List<Resource> list = new ArrayList<Resource>();
                list.add(new AttributesResource(parent.getResourceResolver(), parent.getPath() + "/mbean:attributes", parentResource));
                return list.iterator();
            } else if (info.pathInfo.equals("mbean:attributes")) {
                final AttributesResource parentResource;
                if (parent instanceof AttributesResource) {
                    parentResource = (AttributesResource) parent;
                } else {
                    parentResource = (AttributesResource) this.getResource(parent.getResourceResolver(), parent.getPath());
                }
                final MBeanResource parentMBeanResource = (MBeanResource) parentResource.getParent();
                final AttributeList result = parentMBeanResource.getAttributes();
                final MBeanAttributeInfo[] infos = info.mbeanInfo.getAttributes();
                final Map<String, MBeanAttributeInfo> infoMap = new HashMap<String, MBeanAttributeInfo>();
                for (final MBeanAttributeInfo i : infos) {
                    infoMap.put(i.getName(), i);
                }
                final Iterator iter = result.iterator();
                return new Iterator<Resource>() {

                    public void remove() {
                        throw new UnsupportedOperationException("remove");
                    }

                    public Resource next() {
                        final Attribute attr = (Attribute) iter.next();
                        return new AttributeResource(parent.getResourceResolver(), parent.getPath() + "/" + attr.getName(), infoMap.get(attr.getName()), attr.getValue(), parentResource);
                    }

                    public boolean hasNext() {
                        return iter.hasNext();
                    }
                };
            } else if (info.pathInfo.startsWith("mbean:attributes/")) {
                Resource checkParentResource = parent;
                if (!(checkParentResource instanceof AttributeResource) && !(checkParentResource instanceof MapResource)) {
                    checkParentResource = this.getResource(parent.getResourceResolver(), parent.getPath());
                }
                final AttributeResource parentResource;
                if (checkParentResource instanceof AttributeResource) {
                    parentResource = (AttributeResource) checkParentResource;
                } else {
                    parentResource = ((MapResource) checkParentResource).getAttributeResource();
                }
                final String attrPath = info.pathInfo.substring("mbean:attributes/".length());
                final int pos = attrPath.indexOf('/');
                final String subPath;
                if (pos == -1) {
                    subPath = null;
                } else {
                    subPath = attrPath.substring(pos + 1);
                }
                return parentResource.getChildren(parent.getPath(), subPath);
            }
        }
    }
    return null;
}
Also used : MBeanInfo(javax.management.MBeanInfo) Attribute(javax.management.Attribute) AttributeList(javax.management.AttributeList) ArrayList(java.util.ArrayList) IntrospectionException(javax.management.IntrospectionException) Iterator(java.util.Iterator) HashSet(java.util.HashSet) ReflectionException(javax.management.ReflectionException) MalformedObjectNameException(javax.management.MalformedObjectNameException) InstanceNotFoundException(javax.management.InstanceNotFoundException) Resource(org.apache.sling.api.resource.Resource) MBeanAttributeInfo(javax.management.MBeanAttributeInfo) ObjectName(javax.management.ObjectName) HashMap(java.util.HashMap) Map(java.util.Map) TreeMap(java.util.TreeMap) NoSuchElementException(java.util.NoSuchElementException)

Example 55 with MBeanAttributeInfo

use of javax.management.MBeanAttributeInfo in project sling by apache.

the class MBeanResource method getAttributes.

public AttributeList getAttributes() {
    if (this.attributeList == null) {
        final MBeanAttributeInfo[] infos = info.getAttributes();
        final String[] names = new String[infos.length];
        int index = 0;
        for (final MBeanAttributeInfo i : infos) {
            names[index] = i.getName();
            index++;
        }
        try {
            this.attributeList = mbeanServer.getAttributes(objectName, names);
        } catch (InstanceNotFoundException e) {
            // ignore
            this.attributeList = new AttributeList();
        } catch (ReflectionException e) {
            // ignore
            this.attributeList = new AttributeList();
        }
    }
    return this.attributeList;
}
Also used : ReflectionException(javax.management.ReflectionException) AttributeList(javax.management.AttributeList) InstanceNotFoundException(javax.management.InstanceNotFoundException) MBeanAttributeInfo(javax.management.MBeanAttributeInfo)

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