/** * Used for autodetection of beans. Checks to see if the bean's class has a * {@code ManagedResource} attribute. If so it will add it list of included beans. * @param beanClass the class of the bean * @param beanName the name of the bean in the bean factory */ @Override public boolean includeBean(Class<?> beanClass, String beanName) { return (obtainAttributeSource().getManagedResource(getClassToExpose(beanClass)) != null); }
/** * Reads managed resource description from the source level metadata. * Returns an empty {@code String} if no description can be found. */ @Override protected String getDescription(Object managedBean, String beanKey) { ManagedResource mr = obtainAttributeSource().getManagedResource(getClassToExpose(managedBean)); return (mr != null ? mr.getDescription() : ""); }
/** * Used for autodetection of beans. Checks to see if the bean's class has a * {@code ManagedResource} attribute. If so it will add it list of included beans. * @param beanClass the class of the bean * @param beanName the name of the bean in the bean factory */ @Override public boolean includeBean(Class<?> beanClass, String beanName) { return (obtainAttributeSource().getManagedResource(getClassToExpose(beanClass)) != null); }
/** * Reads the {@code ObjectName} from the source-level metadata associated * with the managed resource's {@code Class}. */ @Override public ObjectName getObjectName(Object managedBean, @Nullable String beanKey) throws MalformedObjectNameException { Assert.state(this.attributeSource != null, "No JmxAttributeSource set"); Class<?> managedClass = AopUtils.getTargetClass(managedBean); ManagedResource mr = this.attributeSource.getManagedResource(managedClass); // Check that an object name has been specified. if (mr != null && StringUtils.hasText(mr.getObjectName())) { return ObjectNameManager.getInstance(mr.getObjectName()); } else { Assert.state(beanKey != null, "No ManagedResource attribute and no bean key specified"); try { return ObjectNameManager.getInstance(beanKey); } catch (MalformedObjectNameException ex) { String domain = this.defaultDomain; if (domain == null) { domain = ClassUtils.getPackageName(managedClass); } Hashtable<String, String> properties = new Hashtable<>(); properties.put("type", ClassUtils.getShortName(managedClass)); properties.put("name", beanKey); return ObjectNameManager.getInstance(domain, properties); } } }
/** * Reads managed resource description from the source level metadata. * Returns an empty {@code String} if no description can be found. */ @Override protected String getDescription(Object managedBean, String beanKey) { ManagedResource mr = obtainAttributeSource().getManagedResource(getClassToExpose(managedBean)); return (mr != null ? mr.getDescription() : ""); }
/** * Reads the {@code ObjectName} from the source-level metadata associated * with the managed resource's {@code Class}. */ @Override public ObjectName getObjectName(Object managedBean, @Nullable String beanKey) throws MalformedObjectNameException { Assert.state(this.attributeSource != null, "No JmxAttributeSource set"); Class<?> managedClass = AopUtils.getTargetClass(managedBean); ManagedResource mr = this.attributeSource.getManagedResource(managedClass); // Check that an object name has been specified. if (mr != null && StringUtils.hasText(mr.getObjectName())) { return ObjectNameManager.getInstance(mr.getObjectName()); } else { Assert.state(beanKey != null, "No ManagedResource attribute and no bean key specified"); try { return ObjectNameManager.getInstance(beanKey); } catch (MalformedObjectNameException ex) { String domain = this.defaultDomain; if (domain == null) { domain = ClassUtils.getPackageName(managedClass); } Hashtable<String, String> properties = new Hashtable<>(); properties.put("type", ClassUtils.getShortName(managedClass)); properties.put("name", beanKey); return ObjectNameManager.getInstance(domain, properties); } } }
ManagedResource mr = obtainAttributeSource().getManagedResource(getClassToExpose(managedBean)); if (mr == null) { throw new InvalidMetadataException(
ManagedResource mr = obtainAttributeSource().getManagedResource(getClassToExpose(managedBean)); if (mr == null) { throw new InvalidMetadataException(
/** * Reads managed resource description from the source level metadata. * Returns an empty {@code String} if no description can be found. */ @Override @Nonnull protected String getDescription(@Nonnull Object managedBean, String beanKey) { Class ifc = findJmxInterface(beanKey, AopUtils.getTargetClass(managedBean)); ManagedResource mr = this.attributeSource.getManagedResource(ifc); return (mr != null ? mr.getDescription() : ""); }
private Class findJmxInterface(String beanKey, Class<?> beanClass) { Class cachedInterface = interfaceCache.get(beanKey); if (cachedInterface != null) { return cachedInterface; } Class mbeanInterface = JmxUtils.getMBeanInterface(beanClass); if (mbeanInterface != null) { // found with MBean ending interfaceCache.put(beanKey, mbeanInterface); return mbeanInterface; } Class[] ifaces = ClassUtils.getAllInterfacesForClass(beanClass); for (Class ifc : ifaces) { ManagedResource metadata = attributeSource.getManagedResource(ifc); if (metadata != null) { // found with @ManagedResource annotation interfaceCache.put(beanKey, ifc); return ifc; } } throw new IllegalArgumentException(String.format( "Bean %s doesn't implement management interfaces. Management interface should either follow naming scheme or be annotated by @ManagedResource", beanKey)); }
/** * Used for autodetection of beans. Checks to see if the bean's class has a * {@code ManagedResource} attribute. If so it will add it list of included beans. * @param beanClass the class of the bean * @param beanName the name of the bean in the bean factory */ @Override public boolean includeBean(Class<?> beanClass, String beanName) { return (obtainAttributeSource().getManagedResource(getClassToExpose(beanClass)) != null); }
@Override public ObjectName getObjectName(Object managedBean, String beanKey) throws MalformedObjectNameException { Class managedClass = AopUtils.getTargetClass(managedBean); ManagedResource mr = this.attributeSource.getManagedResource(managedClass); // Check that an object name has been specified. if (mr != null && StringUtils.hasText(mr.getObjectName())) { return ObjectName.getInstance(mr.getObjectName()); } else { String domain = this.defaultDomain; if (domain == null) domain = ClassUtils.getPackageName(managedClass); return ObjectName.getInstance(domain + ":type=components,name=" + beanKey); } } }
/** * Reads managed resource description from the source level metadata. * Returns an empty {@code String} if no description can be found. */ @Override protected String getDescription(Object managedBean, String beanKey) { ManagedResource mr = obtainAttributeSource().getManagedResource(getClassToExpose(managedBean)); return (mr != null ? mr.getDescription() : ""); }
/** * Reads the {@code ObjectName} from the source-level metadata associated * with the managed resource's {@code Class}. */ @Override public ObjectName getObjectName(Object managedBean, @Nullable String beanKey) throws MalformedObjectNameException { Assert.state(this.attributeSource != null, "No JmxAttributeSource set"); Class<?> managedClass = AopUtils.getTargetClass(managedBean); ManagedResource mr = this.attributeSource.getManagedResource(managedClass); // Check that an object name has been specified. if (mr != null && StringUtils.hasText(mr.getObjectName())) { return ObjectNameManager.getInstance(mr.getObjectName()); } else { Assert.state(beanKey != null, "No ManagedResource attribute and no bean key specified"); try { return ObjectNameManager.getInstance(beanKey); } catch (MalformedObjectNameException ex) { String domain = this.defaultDomain; if (domain == null) { domain = ClassUtils.getPackageName(managedClass); } Hashtable<String, String> properties = new Hashtable<>(); properties.put("type", ClassUtils.getShortName(managedClass)); properties.put("name", beanKey); return ObjectNameManager.getInstance(domain, properties); } } }
protected void populateMBeanDescriptor(@Nonnull Descriptor desc, Object managedBean, String beanKey) { Class intf = findJmxInterface(beanKey, AopUtils.getTargetClass(managedBean)); ManagedResource mr = this.attributeSource.getManagedResource(intf); if (mr == null) { applyDefaultCurrencyTimeLimit(desc);
ManagedResource mr = obtainAttributeSource().getManagedResource(getClassToExpose(managedBean)); if (mr == null) { throw new InvalidMetadataException(