org.springframework.jmx.support.RegistrationPolicy Java Examples

The following examples show how to use org.springframework.jmx.support.RegistrationPolicy. 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: MBeanExportBeanDefinitionParser.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
protected AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext) {
	BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(AnnotationMBeanExporter.class);

	// Mark as infrastructure bean and attach source location.
	builder.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
	builder.getRawBeanDefinition().setSource(parserContext.extractSource(element));

	String defaultDomain = element.getAttribute(DEFAULT_DOMAIN_ATTRIBUTE);
	if (StringUtils.hasText(defaultDomain)) {
		builder.addPropertyValue("defaultDomain", defaultDomain);
	}

	String serverBeanName = element.getAttribute(SERVER_ATTRIBUTE);
	if (StringUtils.hasText(serverBeanName)) {
		builder.addPropertyReference("server", serverBeanName);
	}
	else {
		AbstractBeanDefinition specialServer = MBeanServerBeanDefinitionParser.findServerForSpecialEnvironment();
		if (specialServer != null) {
			builder.addPropertyValue("server", specialServer);
		}
	}

	String registration = element.getAttribute(REGISTRATION_ATTRIBUTE);
	RegistrationPolicy registrationPolicy = RegistrationPolicy.FAIL_ON_EXISTING;
	if (REGISTRATION_IGNORE_EXISTING.equals(registration)) {
		registrationPolicy = RegistrationPolicy.IGNORE_EXISTING;
	}
	else if (REGISTRATION_REPLACE_EXISTING.equals(registration)) {
		registrationPolicy = RegistrationPolicy.REPLACE_EXISTING;
	}
	builder.addPropertyValue("registrationPolicy", registrationPolicy);

	return builder.getBeanDefinition();
}
 
Example #2
Source File: MBeanExporterTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void testRegisterIgnoreExisting() throws Exception {
	ObjectName objectName = ObjectNameManager.getInstance(OBJECT_NAME);

	Person preRegistered = new Person();
	preRegistered.setName("Rob Harrop");

	server.registerMBean(preRegistered, objectName);

	Person springRegistered = new Person();
	springRegistered.setName("Sally Greenwood");

	String objectName2 = "spring:test=equalBean";

	Map<String, Object> beans = new HashMap<>();
	beans.put(objectName.toString(), springRegistered);
	beans.put(objectName2, springRegistered);

	MBeanExporter exporter = new MBeanExporter();
	exporter.setServer(server);
	exporter.setBeans(beans);
	exporter.setRegistrationPolicy(RegistrationPolicy.IGNORE_EXISTING);

	start(exporter);

	ObjectInstance instance = server.getObjectInstance(objectName);
	assertNotNull(instance);
	ObjectInstance instance2 = server.getObjectInstance(new ObjectName(objectName2));
	assertNotNull(instance2);

	// should still be the first bean with name Rob Harrop
	assertEquals("Rob Harrop", server.getAttribute(objectName, "Name"));
}
 
Example #3
Source File: MBeanExporterTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void testRegisterReplaceExisting() throws Exception {
	ObjectName objectName = ObjectNameManager.getInstance(OBJECT_NAME);

	Person preRegistered = new Person();
	preRegistered.setName("Rob Harrop");

	server.registerMBean(preRegistered, objectName);

	Person springRegistered = new Person();
	springRegistered.setName("Sally Greenwood");

	Map<String, Object> beans = new HashMap<>();
	beans.put(objectName.toString(), springRegistered);

	MBeanExporter exporter = new MBeanExporter();
	exporter.setServer(server);
	exporter.setBeans(beans);
	exporter.setRegistrationPolicy(RegistrationPolicy.REPLACE_EXISTING);

	start(exporter);

	ObjectInstance instance = server.getObjectInstance(objectName);
	assertNotNull(instance);

	// should still be the new bean with name Sally Greenwood
	assertEquals("Sally Greenwood", server.getAttribute(objectName, "Name"));
}
 
Example #4
Source File: MBeanExportBeanDefinitionParser.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
protected AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext) {
	BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(AnnotationMBeanExporter.class);

	// Mark as infrastructure bean and attach source location.
	builder.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
	builder.getRawBeanDefinition().setSource(parserContext.extractSource(element));

	String defaultDomain = element.getAttribute(DEFAULT_DOMAIN_ATTRIBUTE);
	if (StringUtils.hasText(defaultDomain)) {
		builder.addPropertyValue("defaultDomain", defaultDomain);
	}

	String serverBeanName = element.getAttribute(SERVER_ATTRIBUTE);
	if (StringUtils.hasText(serverBeanName)) {
		builder.addPropertyReference("server", serverBeanName);
	}
	else {
		AbstractBeanDefinition specialServer = MBeanServerBeanDefinitionParser.findServerForSpecialEnvironment();
		if (specialServer != null) {
			builder.addPropertyValue("server", specialServer);
		}
	}

	String registration = element.getAttribute(REGISTRATION_ATTRIBUTE);
	RegistrationPolicy registrationPolicy = RegistrationPolicy.FAIL_ON_EXISTING;
	if (REGISTRATION_IGNORE_EXISTING.equals(registration)) {
		registrationPolicy = RegistrationPolicy.IGNORE_EXISTING;
	}
	else if (REGISTRATION_REPLACE_EXISTING.equals(registration)) {
		registrationPolicy = RegistrationPolicy.REPLACE_EXISTING;
	}
	builder.addPropertyValue("registrationPolicy", registrationPolicy);

	return builder.getBeanDefinition();
}
 
Example #5
Source File: MBeanExporterTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void testRegisterIgnoreExisting() throws Exception {
	ObjectName objectName = ObjectNameManager.getInstance(OBJECT_NAME);

	Person preRegistered = new Person();
	preRegistered.setName("Rob Harrop");

	server.registerMBean(preRegistered, objectName);

	Person springRegistered = new Person();
	springRegistered.setName("Sally Greenwood");

	String objectName2 = "spring:test=equalBean";

	Map<String, Object> beans = new HashMap<>();
	beans.put(objectName.toString(), springRegistered);
	beans.put(objectName2, springRegistered);

	MBeanExporter exporter = new MBeanExporter();
	exporter.setServer(server);
	exporter.setBeans(beans);
	exporter.setRegistrationPolicy(RegistrationPolicy.IGNORE_EXISTING);

	start(exporter);

	ObjectInstance instance = server.getObjectInstance(objectName);
	assertNotNull(instance);
	ObjectInstance instance2 = server.getObjectInstance(new ObjectName(objectName2));
	assertNotNull(instance2);

	// should still be the first bean with name Rob Harrop
	assertEquals("Rob Harrop", server.getAttribute(objectName, "Name"));
}
 
Example #6
Source File: MBeanExporterTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void testRegisterReplaceExisting() throws Exception {
	ObjectName objectName = ObjectNameManager.getInstance(OBJECT_NAME);

	Person preRegistered = new Person();
	preRegistered.setName("Rob Harrop");

	server.registerMBean(preRegistered, objectName);

	Person springRegistered = new Person();
	springRegistered.setName("Sally Greenwood");

	Map<String, Object> beans = new HashMap<>();
	beans.put(objectName.toString(), springRegistered);

	MBeanExporter exporter = new MBeanExporter();
	exporter.setServer(server);
	exporter.setBeans(beans);
	exporter.setRegistrationPolicy(RegistrationPolicy.REPLACE_EXISTING);

	start(exporter);

	ObjectInstance instance = server.getObjectInstance(objectName);
	assertNotNull(instance);

	// should still be the new bean with name Sally Greenwood
	assertEquals("Sally Greenwood", server.getAttribute(objectName, "Name"));
}
 
Example #7
Source File: DynamicMBeanExporter.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Instantiates a new dynamic MBean exporter.
 */
public DynamicMBeanExporter() 
{ 
    // For consistency, try to continue to use the last MBeanServer used in the same thread 
    MBeanServer server = threadServer.get(); 
    if (server != null) 
    { 
        setServer(server); 
    } 

    // Make replace existing the default registration behavior
    setRegistrationPolicy(RegistrationPolicy.IGNORE_EXISTING);
    setAutodetectMode(MBeanExporter.AUTODETECT_NONE);
}
 
Example #8
Source File: MBeanExportBeanDefinitionParser.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext) {
	BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(AnnotationMBeanExporter.class);

	// Mark as infrastructure bean and attach source location.
	builder.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
	builder.getRawBeanDefinition().setSource(parserContext.extractSource(element));

	String defaultDomain = element.getAttribute(DEFAULT_DOMAIN_ATTRIBUTE);
	if (StringUtils.hasText(defaultDomain)) {
		builder.addPropertyValue("defaultDomain", defaultDomain);
	}

	String serverBeanName = element.getAttribute(SERVER_ATTRIBUTE);
	if (StringUtils.hasText(serverBeanName)) {
		builder.addPropertyReference("server", serverBeanName);
	}
	else {
		AbstractBeanDefinition specialServer = MBeanServerBeanDefinitionParser.findServerForSpecialEnvironment();
		if (specialServer != null) {
			builder.addPropertyValue("server", specialServer);
		}
	}

	String registration = element.getAttribute(REGISTRATION_ATTRIBUTE);
	RegistrationPolicy registrationPolicy = RegistrationPolicy.FAIL_ON_EXISTING;
	if (REGISTRATION_IGNORE_EXISTING.equals(registration)) {
		registrationPolicy = RegistrationPolicy.IGNORE_EXISTING;
	}
	else if (REGISTRATION_REPLACE_EXISTING.equals(registration)) {
		registrationPolicy = RegistrationPolicy.REPLACE_EXISTING;
	}
	builder.addPropertyValue("registrationPolicy", registrationPolicy);

	return builder.getBeanDefinition();
}
 
Example #9
Source File: MBeanExportBeanDefinitionParser.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
protected AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext) {
	BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(AnnotationMBeanExporter.class);

	// Mark as infrastructure bean and attach source location.
	builder.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
	builder.getRawBeanDefinition().setSource(parserContext.extractSource(element));

	String defaultDomain = element.getAttribute(DEFAULT_DOMAIN_ATTRIBUTE);
	if (StringUtils.hasText(defaultDomain)) {
		builder.addPropertyValue("defaultDomain", defaultDomain);
	}

	String serverBeanName = element.getAttribute(SERVER_ATTRIBUTE);
	if (StringUtils.hasText(serverBeanName)) {
		builder.addPropertyReference("server", serverBeanName);
	}
	else {
		AbstractBeanDefinition specialServer = MBeanServerBeanDefinitionParser.findServerForSpecialEnvironment();
		if (specialServer != null) {
			builder.addPropertyValue("server", specialServer);
		}
	}

	String registration = element.getAttribute(REGISTRATION_ATTRIBUTE);
	RegistrationPolicy registrationPolicy = RegistrationPolicy.FAIL_ON_EXISTING;
	if (REGISTRATION_IGNORE_EXISTING.equals(registration)) {
		registrationPolicy = RegistrationPolicy.IGNORE_EXISTING;
	}
	else if (REGISTRATION_REPLACE_EXISTING.equals(registration)) {
		registrationPolicy = RegistrationPolicy.REPLACE_EXISTING;
	}
	builder.addPropertyValue("registrationPolicy", registrationPolicy);

	return builder.getBeanDefinition();
}
 
Example #10
Source File: MBeanExporterTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void testRegisterReplaceExisting() throws Exception {
	ObjectName objectName = ObjectNameManager.getInstance(OBJECT_NAME);

	Person preRegistered = new Person();
	preRegistered.setName("Rob Harrop");

	server.registerMBean(preRegistered, objectName);

	Person springRegistered = new Person();
	springRegistered.setName("Sally Greenwood");

	Map<String, Object> beans = new HashMap<String, Object>();
	beans.put(objectName.toString(), springRegistered);

	MBeanExporter exporter = new MBeanExporter();
	exporter.setServer(server);
	exporter.setBeans(beans);
	exporter.setRegistrationPolicy(RegistrationPolicy.REPLACE_EXISTING);

	start(exporter);

	ObjectInstance instance = server.getObjectInstance(objectName);
	assertNotNull(instance);

	// should still be the new bean with name Sally Greenwood
	assertEquals("Sally Greenwood", server.getAttribute(objectName, "Name"));
}
 
Example #11
Source File: MBeanExportConfiguration.java    From spring-analysis-note with MIT License 4 votes vote down vote up
private void setupRegistrationPolicy(AnnotationMBeanExporter exporter, AnnotationAttributes enableMBeanExport) {
	RegistrationPolicy registrationPolicy = enableMBeanExport.getEnum("registration");
	exporter.setRegistrationPolicy(registrationPolicy);
}
 
Example #12
Source File: MBeanExportConfiguration.java    From java-technology-stack with MIT License 4 votes vote down vote up
private void setupRegistrationPolicy(AnnotationMBeanExporter exporter, AnnotationAttributes enableMBeanExport) {
	RegistrationPolicy registrationPolicy = enableMBeanExport.getEnum("registration");
	exporter.setRegistrationPolicy(registrationPolicy);
}
 
Example #13
Source File: MBeanExportConfiguration.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
private void setupRegistrationPolicy(AnnotationMBeanExporter exporter) {
	RegistrationPolicy registrationPolicy = this.enableMBeanExport.getEnum("registration");
	exporter.setRegistrationPolicy(registrationPolicy);
}
 
Example #14
Source File: MBeanExportConfiguration.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
private void setupRegistrationPolicy(AnnotationMBeanExporter exporter) {
	RegistrationPolicy registrationPolicy = this.enableMBeanExport.getEnum("registration");
	exporter.setRegistrationPolicy(registrationPolicy);
}