Java Code Examples for org.springframework.jmx.support.RegistrationPolicy

The following examples show how to use org.springframework.jmx.support.RegistrationPolicy. These examples are extracted from open source projects. 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
@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 Project: spring-analysis-note   Source File: MBeanExporterTests.java    License: 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 Project: spring-analysis-note   Source File: MBeanExporterTests.java    License: 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
@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 Project: java-technology-stack   Source File: MBeanExporterTests.java    License: 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 Project: java-technology-stack   Source File: MBeanExporterTests.java    License: 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
/**
 * 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
@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
@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 Project: spring4-understanding   Source File: MBeanExporterTests.java    License: 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 Project: spring-analysis-note   Source File: MBeanExportConfiguration.java    License: 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 Project: java-technology-stack   Source File: MBeanExportConfiguration.java    License: 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
private void setupRegistrationPolicy(AnnotationMBeanExporter exporter) {
	RegistrationPolicy registrationPolicy = this.enableMBeanExport.getEnum("registration");
	exporter.setRegistrationPolicy(registrationPolicy);
}
 
Example 14
private void setupRegistrationPolicy(AnnotationMBeanExporter exporter) {
	RegistrationPolicy registrationPolicy = this.enableMBeanExport.getEnum("registration");
	exporter.setRegistrationPolicy(registrationPolicy);
}