本文整理汇总了Java中org.springframework.jmx.support.ObjectNameManager类的典型用法代码示例。如果您正苦于以下问题:Java ObjectNameManager类的具体用法?Java ObjectNameManager怎么用?Java ObjectNameManager使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ObjectNameManager类属于org.springframework.jmx.support包,在下文中一共展示了ObjectNameManager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getObjectName
import org.springframework.jmx.support.ObjectNameManager; //导入依赖的package包/类
/**
* Reads the {@code ObjectName} from the source-level metadata associated
* with the managed resource's {@code Class}.
*/
@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 ObjectNameManager.getInstance(mr.getObjectName());
}
else {
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<String, String>();
properties.put("type", ClassUtils.getShortName(managedClass));
properties.put("name", beanKey);
return ObjectNameManager.getInstance(domain, properties);
}
}
}
示例2: testPlaceholderBased
import org.springframework.jmx.support.ObjectNameManager; //导入依赖的package包/类
@Test
public void testPlaceholderBased() throws Exception {
MockEnvironment env = new MockEnvironment();
env.setProperty("serverName", "server");
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.setEnvironment(env);
ctx.register(PlaceholderBasedConfiguration.class);
ctx.refresh();
try {
MBeanServer server = (MBeanServer) ctx.getBean("server");
ObjectName oname = ObjectNameManager.getInstance("bean:name=testBean4");
assertNotNull(server.getObjectInstance(oname));
String name = (String) server.getAttribute(oname, "Name");
assertEquals("Invalid name returned", "TEST", name);
}
finally {
ctx.close();
}
}
示例3: testUserCreatedMBeanRegWithDynamicMBean
import org.springframework.jmx.support.ObjectNameManager; //导入依赖的package包/类
@Test
public void testUserCreatedMBeanRegWithDynamicMBean() throws Exception {
Map<String, Object> map = new HashMap<String, Object>();
map.put("spring:name=dynBean", new TestDynamicMBean());
InvokeDetectAssembler asm = new InvokeDetectAssembler();
MBeanExporter exporter = new MBeanExporter();
exporter.setServer(server);
exporter.setBeans(map);
exporter.setAssembler(asm);
try {
start(exporter);
Object name = server.getAttribute(ObjectNameManager.getInstance("spring:name=dynBean"), "Name");
assertEquals("The name attribute is incorrect", "Rob Harrop", name);
assertFalse("Assembler should not have been invoked", asm.invoked);
}
finally {
exporter.destroy();
}
}
示例4: testAutodetectMBeans
import org.springframework.jmx.support.ObjectNameManager; //导入依赖的package包/类
@Test
public void testAutodetectMBeans() throws Exception {
ConfigurableApplicationContext ctx = load("autodetectMBeans.xml");
try {
ctx.getBean("exporter");
MBeanServer server = ctx.getBean("server", MBeanServer.class);
ObjectInstance instance = server.getObjectInstance(ObjectNameManager.getInstance("spring:mbean=true"));
assertNotNull(instance);
instance = server.getObjectInstance(ObjectNameManager.getInstance("spring:mbean2=true"));
assertNotNull(instance);
instance = server.getObjectInstance(ObjectNameManager.getInstance("spring:mbean3=true"));
assertNotNull(instance);
}
finally {
ctx.close();
}
}
示例5: testAutodetectWithExclude
import org.springframework.jmx.support.ObjectNameManager; //导入依赖的package包/类
@Test
public void testAutodetectWithExclude() throws Exception {
ConfigurableApplicationContext ctx = load("autodetectMBeans.xml");
try {
ctx.getBean("exporter");
MBeanServer server = ctx.getBean("server", MBeanServer.class);
ObjectInstance instance = server.getObjectInstance(ObjectNameManager.getInstance("spring:mbean=true"));
assertNotNull(instance);
thrown.expect(InstanceNotFoundException.class);
server.getObjectInstance(ObjectNameManager.getInstance("spring:mbean=false"));
}
finally {
ctx.close();
}
}
示例6: testAutodetectLazyMBeans
import org.springframework.jmx.support.ObjectNameManager; //导入依赖的package包/类
@Test
public void testAutodetectLazyMBeans() throws Exception {
ConfigurableApplicationContext ctx = load("autodetectLazyMBeans.xml");
try {
ctx.getBean("exporter");
MBeanServer server = ctx.getBean("server", MBeanServer.class);
ObjectName oname = ObjectNameManager.getInstance("spring:mbean=true");
assertNotNull(server.getObjectInstance(oname));
String name = (String) server.getAttribute(oname, "Name");
assertEquals("Invalid name returned", "Rob Harrop", name);
oname = ObjectNameManager.getInstance("spring:mbean=another");
assertNotNull(server.getObjectInstance(oname));
name = (String) server.getAttribute(oname, "Name");
assertEquals("Invalid name returned", "Juergen Hoeller", name);
}
finally {
ctx.close();
}
}
示例7: testSelfNaming
import org.springframework.jmx.support.ObjectNameManager; //导入依赖的package包/类
@Test
public void testSelfNaming() throws Exception {
ObjectName objectName = ObjectNameManager.getInstance(OBJECT_NAME);
SelfNamingTestBean testBean = new SelfNamingTestBean();
testBean.setObjectName(objectName);
Map<String, Object> beans = new HashMap<String, Object>();
beans.put("foo", testBean);
MBeanExporter exporter = new MBeanExporter();
exporter.setServer(server);
exporter.setBeans(beans);
start(exporter);
ObjectInstance instance = server.getObjectInstance(objectName);
assertNotNull(instance);
}
示例8: testOnlyBonaFideMBeanIsExportedWhenAutodetectIsMBeanOnly
import org.springframework.jmx.support.ObjectNameManager; //导入依赖的package包/类
@Test
public void testOnlyBonaFideMBeanIsExportedWhenAutodetectIsMBeanOnly() throws Exception {
BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(Person.class);
DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
factory.registerBeanDefinition(OBJECT_NAME, builder.getBeanDefinition());
String exportedBeanName = "spring:type=TestBean";
factory.registerSingleton(exportedBeanName, new TestBean());
MBeanExporter exporter = new MBeanExporter();
exporter.setServer(getServer());
exporter.setAssembler(new NamedBeanAutodetectCapableMBeanInfoAssemblerStub(exportedBeanName));
exporter.setBeanFactory(factory);
exporter.setAutodetectMode(MBeanExporter.AUTODETECT_MBEAN);
start(exporter);
assertIsRegistered("Bona fide MBean not autodetected in AUTODETECT_MBEAN mode",
ObjectNameManager.getInstance(OBJECT_NAME));
assertIsNotRegistered("Bean autodetected and (only) AUTODETECT_MBEAN mode is on",
ObjectNameManager.getInstance(exportedBeanName));
}
示例9: testBonaFideMBeanAndRegularBeanExporterWithAutodetectAll
import org.springframework.jmx.support.ObjectNameManager; //导入依赖的package包/类
@Test
public void testBonaFideMBeanAndRegularBeanExporterWithAutodetectAll() throws Exception {
BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(Person.class);
DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
factory.registerBeanDefinition(OBJECT_NAME, builder.getBeanDefinition());
String exportedBeanName = "spring:type=TestBean";
factory.registerSingleton(exportedBeanName, new TestBean());
String notToBeExportedBeanName = "spring:type=NotToBeExported";
factory.registerSingleton(notToBeExportedBeanName, new TestBean());
MBeanExporter exporter = new MBeanExporter();
exporter.setServer(getServer());
exporter.setAssembler(new NamedBeanAutodetectCapableMBeanInfoAssemblerStub(exportedBeanName));
exporter.setBeanFactory(factory);
exporter.setAutodetectMode(MBeanExporter.AUTODETECT_ALL);
start(exporter);
assertIsRegistered("Bona fide MBean not autodetected in (AUTODETECT_ALL) mode",
ObjectNameManager.getInstance(OBJECT_NAME));
assertIsRegistered("Bean not autodetected in (AUTODETECT_ALL) mode",
ObjectNameManager.getInstance(exportedBeanName));
assertIsNotRegistered("Bean autodetected and did not satisfy the autodetect info assembler",
ObjectNameManager.getInstance(notToBeExportedBeanName));
}
示例10: testBonaFideMBeanIsNotExportedWithAutodetectAssembler
import org.springframework.jmx.support.ObjectNameManager; //导入依赖的package包/类
@Test
public void testBonaFideMBeanIsNotExportedWithAutodetectAssembler() throws Exception {
BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(Person.class);
DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
factory.registerBeanDefinition(OBJECT_NAME, builder.getBeanDefinition());
String exportedBeanName = "spring:type=TestBean";
factory.registerSingleton(exportedBeanName, new TestBean());
MBeanExporter exporter = new MBeanExporter();
exporter.setServer(getServer());
exporter.setAssembler(new NamedBeanAutodetectCapableMBeanInfoAssemblerStub(exportedBeanName));
exporter.setBeanFactory(factory);
exporter.setAutodetectMode(MBeanExporter.AUTODETECT_ASSEMBLER);
start(exporter);
assertIsNotRegistered("Bona fide MBean was autodetected in AUTODETECT_ASSEMBLER mode - must not have been",
ObjectNameManager.getInstance(OBJECT_NAME));
assertIsRegistered("Bean not autodetected in AUTODETECT_ASSEMBLER mode",
ObjectNameManager.getInstance(exportedBeanName));
}
示例11: testBonaFideMBeanExplicitlyExportedAndAutodetectionIsOn
import org.springframework.jmx.support.ObjectNameManager; //导入依赖的package包/类
/**
* Want to ensure that said MBean is not exported twice.
*/
@Test
public void testBonaFideMBeanExplicitlyExportedAndAutodetectionIsOn() throws Exception {
BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(Person.class);
DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
factory.registerBeanDefinition(OBJECT_NAME, builder.getBeanDefinition());
MBeanExporter exporter = new MBeanExporter();
exporter.setServer(getServer());
Map<String, Object> beansToExport = new HashMap<String, Object>();
beansToExport.put(OBJECT_NAME, OBJECT_NAME);
exporter.setBeans(beansToExport);
exporter.setAssembler(new NamedBeanAutodetectCapableMBeanInfoAssemblerStub(OBJECT_NAME));
exporter.setBeanFactory(factory);
exporter.setAutodetectMode(MBeanExporter.AUTODETECT_ASSEMBLER);
start(exporter);
assertIsRegistered("Explicitly exported bona fide MBean obviously not exported.",
ObjectNameManager.getInstance(OBJECT_NAME));
}
示例12: testMBeanIsNotUnregisteredSpuriouslyIfSomeExternalProcessHasUnregisteredMBean
import org.springframework.jmx.support.ObjectNameManager; //导入依赖的package包/类
/**
* SPR-2158
*/
@Test
public void testMBeanIsNotUnregisteredSpuriouslyIfSomeExternalProcessHasUnregisteredMBean() throws Exception {
MBeanExporter exporter = new MBeanExporter();
exporter.setBeans(getBeanMap());
exporter.setServer(this.server);
MockMBeanExporterListener listener = new MockMBeanExporterListener();
exporter.setListeners(listener);
start(exporter);
assertIsRegistered("The bean was not registered with the MBeanServer",
ObjectNameManager.getInstance(OBJECT_NAME));
this.server.unregisterMBean(new ObjectName(OBJECT_NAME));
exporter.destroy();
assertEquals("Listener should not have been invoked (MBean previously unregistered by external agent)", 0,
listener.getUnregistered().size());
}
示例13: testIgnoreBeanName
import org.springframework.jmx.support.ObjectNameManager; //导入依赖的package包/类
@Test
public void testIgnoreBeanName() throws MalformedObjectNameException {
DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
String firstBeanName = "spring:type=TestBean";
factory.registerSingleton(firstBeanName, new TestBean("test"));
String secondBeanName = "spring:type=TestBean2";
factory.registerSingleton(secondBeanName, new TestBean("test2"));
MBeanExporter exporter = new MBeanExporter();
exporter.setServer(getServer());
exporter.setAssembler(new NamedBeanAutodetectCapableMBeanInfoAssemblerStub(firstBeanName, secondBeanName));
exporter.setBeanFactory(factory);
exporter.setAutodetectMode(MBeanExporter.AUTODETECT_ALL);
exporter.addExcludedBean(secondBeanName);
start(exporter);
assertIsRegistered("Bean not autodetected in (AUTODETECT_ALL) mode",
ObjectNameManager.getInstance(firstBeanName));
assertIsNotRegistered("Bean should have been excluded",
ObjectNameManager.getInstance(secondBeanName));
}
示例14: testRegisterManagedResourceWithGeneratedObjectName
import org.springframework.jmx.support.ObjectNameManager; //导入依赖的package包/类
@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);
}
示例15: testLazyInit
import org.springframework.jmx.support.ObjectNameManager; //导入依赖的package包/类
@Test
public void testLazyInit() throws Exception {
// start the MBeanExporter
ConfigurableApplicationContext ctx = loadContext("org/springframework/jmx/export/notificationPublisherLazyTests.xml");
assertFalse("Should not have instantiated the bean yet", ctx.getBeanFactory().containsSingleton("publisher"));
// need to touch the MBean proxy
server.getAttribute(ObjectNameManager.getInstance("spring:type=Publisher"), "Name");
this.server.addNotificationListener(ObjectNameManager.getInstance("spring:type=Publisher"), listener, null,
null);
MyNotificationPublisher publisher = (MyNotificationPublisher) ctx.getBean("publisher");
assertNotNull("NotificationPublisher should not be null", publisher.getNotificationPublisher());
publisher.sendNotification();
assertEquals("Notification not sent", 1, listener.count);
}