private void addMBeanInfo()

in hawtio-system/src/main/java/io/hawt/jmx/RBACRegistry.java [114:167]


    private void addMBeanInfo(Map<String, Map<String, Object>> cache, Map<String, Map<String, Object>> domains, Set<ObjectName> visited,
                              ObjectName nameObject) throws IntrospectionException, ReflectionException {
        // Don't add if already visited previously
        if (visited.contains(nameObject)) {
            return;
        }

        Map<String, Object> jsonifiedMBeanInfo;

        // Let's try to avoid invoking getMBeanInfo. simply domain+type attr is not enough, but we may
        // detect special cases
        String mbeanInfoKey = isSpecialMBean(nameObject);
        if (mbeanInfoKey != null && cache.containsKey(mbeanInfoKey)) {
            jsonifiedMBeanInfo = cache.get(mbeanInfoKey);
        } else {
            // we may have to assemble the info on the fly
            try {
                MBeanInfo mBeanInfo = mBeanServer.getMBeanInfo(nameObject);

                // 2nd level of special cases - a bit slower (we had to getMBeanInfo(), but we may try
                // cache by MBean's domain and class)
                if (mbeanInfoKey == null) {
                    mbeanInfoKey = isSpecialClass(nameObject, mBeanInfo);
                }
                if (mbeanInfoKey != null && cache.containsKey(mbeanInfoKey)) {
                    jsonifiedMBeanInfo = cache.get(mbeanInfoKey);
                } else {
                    // hard work here
                    jsonifiedMBeanInfo = jsonifyMBeanInfo(mBeanInfo);
                }

                if (mbeanInfoKey != null) {
                    cache.put(mbeanInfoKey, jsonifiedMBeanInfo);
                }
            } catch (InstanceNotFoundException e) {
                // Log failure and continue so that we can still send a response back
                LOG.debug("Failed to get MBean info for {}. Due to InstanceNotFoundException.", nameObject);
                return;
            }
        }

        Map<String, Object> domain = domains.computeIfAbsent(nameObject.getDomain(), key -> new HashMap<>());

        // jsonifiedMBeanInfo should not be null here and *may* be cached
        if (mbeanInfoKey != null) {
            // in hawtio we'll check `typeof info === 'string'` (angular.isString(info))
            domain.put(nameObject.getKeyPropertyListString(), mbeanInfoKey);
        } else {
            // angular.isObject(info)
            domain.put(nameObject.getKeyPropertyListString(), jsonifiedMBeanInfo);
        }

        visited.add(nameObject);
    }