org.springframework.jmx.export.assembler.AutodetectCapableMBeanInfoAssembler Java Examples

The following examples show how to use org.springframework.jmx.export.assembler.AutodetectCapableMBeanInfoAssembler. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MBeanExporter.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * Register the defined beans with the {@link MBeanServer}.
 * <p>Each bean is exposed to the {@code MBeanServer} via a
 * {@code ModelMBean}. The actual implementation of the
 * {@code ModelMBean} interface used depends on the implementation of
 * the {@code ModelMBeanProvider} interface that is configured. By
 * default the {@code RequiredModelMBean} class that is supplied with
 * all JMX implementations is used.
 * <p>The management interface produced for each bean is dependent on the
 * {@code MBeanInfoAssembler} implementation being used. The
 * {@code ObjectName} given to each bean is dependent on the
 * implementation of the {@code ObjectNamingStrategy} interface being used.
 */
protected void registerBeans() {
	// The beans property may be null, for example if we are relying solely on autodetection.
	if (this.beans == null) {
		this.beans = new HashMap<>();
		// Use AUTODETECT_ALL as default in no beans specified explicitly.
		if (this.autodetectMode == null) {
			this.autodetectMode = AUTODETECT_ALL;
		}
	}

	// Perform autodetection, if desired.
	int mode = (this.autodetectMode != null ? this.autodetectMode : AUTODETECT_NONE);
	if (mode != AUTODETECT_NONE) {
		if (this.beanFactory == null) {
			throw new MBeanExportException("Cannot autodetect MBeans if not running in a BeanFactory");
		}
		if (mode == AUTODETECT_MBEAN || mode == AUTODETECT_ALL) {
			// Autodetect any beans that are already MBeans.
			logger.debug("Autodetecting user-defined JMX MBeans");
			autodetect(this.beans, (beanClass, beanName) -> isMBean(beanClass));
		}
		// Allow the assembler a chance to vote for bean inclusion.
		if ((mode == AUTODETECT_ASSEMBLER || mode == AUTODETECT_ALL) &&
				this.assembler instanceof AutodetectCapableMBeanInfoAssembler) {
			autodetect(this.beans, ((AutodetectCapableMBeanInfoAssembler) this.assembler)::includeBean);
		}
	}

	if (!this.beans.isEmpty()) {
		this.beans.forEach((beanName, instance) -> registerBeanNameOrInstance(instance, beanName));
	}
}
 
Example #2
Source File: MBeanExporter.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * Register the defined beans with the {@link MBeanServer}.
 * <p>Each bean is exposed to the {@code MBeanServer} via a
 * {@code ModelMBean}. The actual implementation of the
 * {@code ModelMBean} interface used depends on the implementation of
 * the {@code ModelMBeanProvider} interface that is configured. By
 * default the {@code RequiredModelMBean} class that is supplied with
 * all JMX implementations is used.
 * <p>The management interface produced for each bean is dependent on the
 * {@code MBeanInfoAssembler} implementation being used. The
 * {@code ObjectName} given to each bean is dependent on the
 * implementation of the {@code ObjectNamingStrategy} interface being used.
 */
protected void registerBeans() {
	// The beans property may be null, for example if we are relying solely on autodetection.
	if (this.beans == null) {
		this.beans = new HashMap<>();
		// Use AUTODETECT_ALL as default in no beans specified explicitly.
		if (this.autodetectMode == null) {
			this.autodetectMode = AUTODETECT_ALL;
		}
	}

	// Perform autodetection, if desired.
	int mode = (this.autodetectMode != null ? this.autodetectMode : AUTODETECT_NONE);
	if (mode != AUTODETECT_NONE) {
		if (this.beanFactory == null) {
			throw new MBeanExportException("Cannot autodetect MBeans if not running in a BeanFactory");
		}
		if (mode == AUTODETECT_MBEAN || mode == AUTODETECT_ALL) {
			// Autodetect any beans that are already MBeans.
			logger.debug("Autodetecting user-defined JMX MBeans");
			autodetect(this.beans, (beanClass, beanName) -> isMBean(beanClass));
		}
		// Allow the assembler a chance to vote for bean inclusion.
		if ((mode == AUTODETECT_ASSEMBLER || mode == AUTODETECT_ALL) &&
				this.assembler instanceof AutodetectCapableMBeanInfoAssembler) {
			autodetect(this.beans, ((AutodetectCapableMBeanInfoAssembler) this.assembler)::includeBean);
		}
	}

	if (!this.beans.isEmpty()) {
		this.beans.forEach((beanName, instance) -> registerBeanNameOrInstance(instance, beanName));
	}
}
 
Example #3
Source File: MBeanExporter.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Registers the defined beans with the {@link MBeanServer}.
 * <p>Each bean is exposed to the {@code MBeanServer} via a
 * {@code ModelMBean}. The actual implemetation of the
 * {@code ModelMBean} interface used depends on the implementation of
 * the {@code ModelMBeanProvider} interface that is configured. By
 * default the {@code RequiredModelMBean} class that is supplied with
 * all JMX implementations is used.
 * <p>The management interface produced for each bean is dependent on the
 * {@code MBeanInfoAssembler} implementation being used. The
 * {@code ObjectName} given to each bean is dependent on the
 * implementation of the {@code ObjectNamingStrategy} interface being used.
 */
protected void registerBeans() {
	// The beans property may be null, for example if we are relying solely on autodetection.
	if (this.beans == null) {
		this.beans = new HashMap<String, Object>();
		// Use AUTODETECT_ALL as default in no beans specified explicitly.
		if (this.autodetectMode == null) {
			this.autodetectMode = AUTODETECT_ALL;
		}
	}

	// Perform autodetection, if desired.
	int mode = (this.autodetectMode != null ? this.autodetectMode : AUTODETECT_NONE);
	if (mode != AUTODETECT_NONE) {
		if (this.beanFactory == null) {
			throw new MBeanExportException("Cannot autodetect MBeans if not running in a BeanFactory");
		}
		if (mode == AUTODETECT_MBEAN || mode == AUTODETECT_ALL) {
			// Autodetect any beans that are already MBeans.
			logger.debug("Autodetecting user-defined JMX MBeans");
			autodetectMBeans();
		}
		// Allow the assembler a chance to vote for bean inclusion.
		if ((mode == AUTODETECT_ASSEMBLER || mode == AUTODETECT_ALL) &&
				this.assembler instanceof AutodetectCapableMBeanInfoAssembler) {
			autodetectBeans((AutodetectCapableMBeanInfoAssembler) this.assembler);
		}
	}

	if (!this.beans.isEmpty()) {
		for (Map.Entry<String, Object> entry : this.beans.entrySet()) {
			registerBeanNameOrInstance(entry.getValue(), entry.getKey());
		}
	}
}
 
Example #4
Source File: MBeanExporter.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Invoked when using an {@code AutodetectCapableMBeanInfoAssembler}.
 * Gives the assembler the opportunity to add additional beans from the
 * {@code BeanFactory} to the list of beans to be exposed via JMX.
 * <p>This implementation prevents a bean from being added to the list
 * automatically if it has already been added manually, and it prevents
 * certain internal classes from being registered automatically.
 */
private void autodetectBeans(final AutodetectCapableMBeanInfoAssembler assembler) {
	autodetect(new AutodetectCallback() {
		@Override
		public boolean include(Class<?> beanClass, String beanName) {
			return assembler.includeBean(beanClass, beanName);
		}
	});
}
 
Example #5
Source File: MBeanExporter.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * Registers the defined beans with the {@link MBeanServer}.
 * <p>Each bean is exposed to the {@code MBeanServer} via a
 * {@code ModelMBean}. The actual implemetation of the
 * {@code ModelMBean} interface used depends on the implementation of
 * the {@code ModelMBeanProvider} interface that is configured. By
 * default the {@code RequiredModelMBean} class that is supplied with
 * all JMX implementations is used.
 * <p>The management interface produced for each bean is dependent on the
 * {@code MBeanInfoAssembler} implementation being used. The
 * {@code ObjectName} given to each bean is dependent on the
 * implementation of the {@code ObjectNamingStrategy} interface being used.
 */
protected void registerBeans() {
	// The beans property may be null, for example if we are relying solely on autodetection.
	if (this.beans == null) {
		this.beans = new HashMap<String, Object>();
		// Use AUTODETECT_ALL as default in no beans specified explicitly.
		if (this.autodetectMode == null) {
			this.autodetectMode = AUTODETECT_ALL;
		}
	}

	// Perform autodetection, if desired.
	int mode = (this.autodetectMode != null ? this.autodetectMode : AUTODETECT_NONE);
	if (mode != AUTODETECT_NONE) {
		if (this.beanFactory == null) {
			throw new MBeanExportException("Cannot autodetect MBeans if not running in a BeanFactory");
		}
		if (mode == AUTODETECT_MBEAN || mode == AUTODETECT_ALL) {
			// Autodetect any beans that are already MBeans.
			logger.debug("Autodetecting user-defined JMX MBeans");
			autodetectMBeans();
		}
		// Allow the assembler a chance to vote for bean inclusion.
		if ((mode == AUTODETECT_ASSEMBLER || mode == AUTODETECT_ALL) &&
				this.assembler instanceof AutodetectCapableMBeanInfoAssembler) {
			autodetectBeans((AutodetectCapableMBeanInfoAssembler) this.assembler);
		}
	}

	if (!this.beans.isEmpty()) {
		for (Map.Entry<String, Object> entry : this.beans.entrySet()) {
			registerBeanNameOrInstance(entry.getValue(), entry.getKey());
		}
	}
}
 
Example #6
Source File: MBeanExporter.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * Invoked when using an {@code AutodetectCapableMBeanInfoAssembler}.
 * Gives the assembler the opportunity to add additional beans from the
 * {@code BeanFactory} to the list of beans to be exposed via JMX.
 * <p>This implementation prevents a bean from being added to the list
 * automatically if it has already been added manually, and it prevents
 * certain internal classes from being registered automatically.
 */
private void autodetectBeans(final AutodetectCapableMBeanInfoAssembler assembler) {
	autodetect(new AutodetectCallback() {
		@Override
		public boolean include(Class<?> beanClass, String beanName) {
			return assembler.includeBean(beanClass, beanName);
		}
	});
}