org.springframework.jmx.export.naming.ObjectNamingStrategy Java Examples

The following examples show how to use org.springframework.jmx.export.naming.ObjectNamingStrategy. 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: MBeanExporterOperationsTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void testRegisterManagedResourceWithGeneratedObjectName() throws Exception {
	final ObjectName objectNameTemplate = ObjectNameManager.getInstance("spring:type=Test");

	MBeanExporter exporter = new MBeanExporter();
	exporter.setServer(getServer());
	exporter.setNamingStrategy(new ObjectNamingStrategy() {
		@Override
		public ObjectName getObjectName(Object managedBean, String beanKey) {
			return objectNameTemplate;
		}
	});

	JmxTestBean bean1 = new JmxTestBean();
	JmxTestBean bean2 = new JmxTestBean();

	ObjectName reg1 = exporter.registerManagedResource(bean1);
	ObjectName reg2 = exporter.registerManagedResource(bean2);

	assertIsRegistered("Bean 1 not registered with MBeanServer", reg1);
	assertIsRegistered("Bean 2 not registered with MBeanServer", reg2);

	assertObjectNameMatchesTemplate(objectNameTemplate, reg1);
	assertObjectNameMatchesTemplate(objectNameTemplate, reg2);
}
 
Example #2
Source File: MBeanExporterOperationsTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void testRegisterManagedResourceWithGeneratedObjectName() throws Exception {
	final ObjectName objectNameTemplate = ObjectNameManager.getInstance("spring:type=Test");

	MBeanExporter exporter = new MBeanExporter();
	exporter.setServer(getServer());
	exporter.setNamingStrategy(new ObjectNamingStrategy() {
		@Override
		public ObjectName getObjectName(Object managedBean, String beanKey) {
			return objectNameTemplate;
		}
	});

	JmxTestBean bean1 = new JmxTestBean();
	JmxTestBean bean2 = new JmxTestBean();

	ObjectName reg1 = exporter.registerManagedResource(bean1);
	ObjectName reg2 = exporter.registerManagedResource(bean2);

	assertIsRegistered("Bean 1 not registered with MBeanServer", reg1);
	assertIsRegistered("Bean 2 not registered with MBeanServer", reg2);

	assertObjectNameMatchesTemplate(objectNameTemplate, reg1);
	assertObjectNameMatchesTemplate(objectNameTemplate, reg2);
}
 
Example #3
Source File: MBeanExporterOperationsTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Test
public void testRegisterManagedResourceWithGeneratedObjectName() throws Exception {
	final ObjectName objectNameTemplate = ObjectNameManager.getInstance("spring:type=Test");

	MBeanExporter exporter = new MBeanExporter();
	exporter.setServer(getServer());
	exporter.setNamingStrategy(new ObjectNamingStrategy() {
		@Override
		public ObjectName getObjectName(Object managedBean, String beanKey) {
			return objectNameTemplate;
		}
	});

	JmxTestBean bean1 = new JmxTestBean();
	JmxTestBean bean2 = new JmxTestBean();

	ObjectName reg1 = exporter.registerManagedResource(bean1);
	ObjectName reg2 = exporter.registerManagedResource(bean2);

	assertIsRegistered("Bean 1 not registered with MBeanServer", reg1);
	assertIsRegistered("Bean 2 not registered with MBeanServer", reg2);

	assertObjectNameMatchesTemplate(objectNameTemplate, reg1);
	assertObjectNameMatchesTemplate(objectNameTemplate, reg2);
}
 
Example #4
Source File: MBeanExporterOperationsTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void testRegisterManagedResourceWithGeneratedObjectNameWithoutUniqueness() throws Exception {
	final ObjectName objectNameTemplate = ObjectNameManager.getInstance("spring:type=Test");

	MBeanExporter exporter = new MBeanExporter();
	exporter.setServer(getServer());
	exporter.setEnsureUniqueRuntimeObjectNames(false);
	exporter.setNamingStrategy(new ObjectNamingStrategy() {
		@Override
		public ObjectName getObjectName(Object managedBean, String beanKey) {
			return objectNameTemplate;
		}
	});

	JmxTestBean bean1 = new JmxTestBean();
	JmxTestBean bean2 = new JmxTestBean();

	ObjectName reg1 = exporter.registerManagedResource(bean1);
	assertIsRegistered("Bean 1 not registered with MBeanServer", reg1);

	try {
		exporter.registerManagedResource(bean2);
		fail("Shouldn't be able to register a runtime MBean with a reused ObjectName.");
	}
	catch (MBeanExportException e) {
		assertEquals("Incorrect root cause", InstanceAlreadyExistsException.class, e.getCause().getClass());
	}
}
 
Example #5
Source File: MBeanExporterOperationsTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void testRegisterManagedResourceWithGeneratedObjectNameWithoutUniqueness() throws Exception {
	final ObjectName objectNameTemplate = ObjectNameManager.getInstance("spring:type=Test");

	MBeanExporter exporter = new MBeanExporter();
	exporter.setServer(getServer());
	exporter.setEnsureUniqueRuntimeObjectNames(false);
	exporter.setNamingStrategy(new ObjectNamingStrategy() {
		@Override
		public ObjectName getObjectName(Object managedBean, String beanKey) {
			return objectNameTemplate;
		}
	});

	JmxTestBean bean1 = new JmxTestBean();
	JmxTestBean bean2 = new JmxTestBean();

	ObjectName reg1 = exporter.registerManagedResource(bean1);
	assertIsRegistered("Bean 1 not registered with MBeanServer", reg1);

	try {
		exporter.registerManagedResource(bean2);
		fail("Shouldn't be able to register a runtime MBean with a reused ObjectName.");
	}
	catch (MBeanExportException e) {
		assertEquals("Incorrect root cause", InstanceAlreadyExistsException.class, e.getCause().getClass());
	}
}
 
Example #6
Source File: MBeanExporterOperationsTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void testRegisterManagedResourceWithGeneratedObjectNameWithoutUniqueness() throws Exception {
	final ObjectName objectNameTemplate = ObjectNameManager.getInstance("spring:type=Test");

	MBeanExporter exporter = new MBeanExporter();
	exporter.setServer(getServer());
	exporter.setEnsureUniqueRuntimeObjectNames(false);
	exporter.setNamingStrategy(new ObjectNamingStrategy() {
		@Override
		public ObjectName getObjectName(Object managedBean, String beanKey) {
			return objectNameTemplate;
		}
	});

	JmxTestBean bean1 = new JmxTestBean();
	JmxTestBean bean2 = new JmxTestBean();

	ObjectName reg1 = exporter.registerManagedResource(bean1);
	assertIsRegistered("Bean 1 not registered with MBeanServer", reg1);

	try {
		exporter.registerManagedResource(bean2);
		fail("Shouldn't be able to register a runtime MBean with a reused ObjectName.");
	}
	catch (MBeanExportException e) {
		assertEquals("Incorrect root cause", InstanceAlreadyExistsException.class, e.getCause().getClass());
	}
}
 
Example #7
Source File: MBeanExporter.java    From spring-analysis-note with MIT License 2 votes vote down vote up
/**
 * Set the implementation of the {@code ObjectNamingStrategy} interface
 * to use for this exporter. Default is a {@code KeyNamingStrategy}.
 * @see org.springframework.jmx.export.naming.KeyNamingStrategy
 * @see org.springframework.jmx.export.naming.MetadataNamingStrategy
 */
public void setNamingStrategy(ObjectNamingStrategy namingStrategy) {
	this.namingStrategy = namingStrategy;
}
 
Example #8
Source File: MBeanExporter.java    From java-technology-stack with MIT License 2 votes vote down vote up
/**
 * Set the implementation of the {@code ObjectNamingStrategy} interface
 * to use for this exporter. Default is a {@code KeyNamingStrategy}.
 * @see org.springframework.jmx.export.naming.KeyNamingStrategy
 * @see org.springframework.jmx.export.naming.MetadataNamingStrategy
 */
public void setNamingStrategy(ObjectNamingStrategy namingStrategy) {
	this.namingStrategy = namingStrategy;
}
 
Example #9
Source File: MBeanExporter.java    From lams with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Set the implementation of the {@code ObjectNamingStrategy} interface
 * to use for this exporter. Default is a {@code KeyNamingStrategy}.
 * @see org.springframework.jmx.export.naming.KeyNamingStrategy
 * @see org.springframework.jmx.export.naming.MetadataNamingStrategy
 */
public void setNamingStrategy(ObjectNamingStrategy namingStrategy) {
	this.namingStrategy = namingStrategy;
}
 
Example #10
Source File: MBeanExporter.java    From spring4-understanding with Apache License 2.0 2 votes vote down vote up
/**
 * Set the implementation of the {@code ObjectNamingStrategy} interface
 * to use for this exporter. Default is a {@code KeyNamingStrategy}.
 * @see org.springframework.jmx.export.naming.KeyNamingStrategy
 * @see org.springframework.jmx.export.naming.MetadataNamingStrategy
 */
public void setNamingStrategy(ObjectNamingStrategy namingStrategy) {
	this.namingStrategy = namingStrategy;
}