当前位置: 首页>>代码示例>>Java>>正文


Java ObjectNameManager.getInstance方法代码示例

本文整理汇总了Java中org.springframework.jmx.support.ObjectNameManager.getInstance方法的典型用法代码示例。如果您正苦于以下问题:Java ObjectNameManager.getInstance方法的具体用法?Java ObjectNameManager.getInstance怎么用?Java ObjectNameManager.getInstance使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.springframework.jmx.support.ObjectNameManager的用法示例。


在下文中一共展示了ObjectNameManager.getInstance方法的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);
		}
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:30,代码来源:MetadataNamingStrategy.java

示例2: getObjectName

import org.springframework.jmx.support.ObjectNameManager; //导入方法依赖的package包/类
@Override
protected ObjectName getObjectName(Object bean, String beanKey)
		throws MalformedObjectNameException {
	if (bean instanceof SelfNaming) {
		return ((SelfNaming) bean).getObjectName();
	}

	if (bean instanceof EndpointMBean) {
		StringBuilder builder = new StringBuilder();
		builder.append(this.domain);
		builder.append(":type=Endpoint");
		builder.append(",name=" + beanKey);
		if (parentContextContainsSameBean(this.applicationContext, beanKey)) {
			builder.append(",context="
					+ ObjectUtils.getIdentityHexString(this.applicationContext));
		}
		if (this.ensureUniqueRuntimeObjectNames) {
			builder.append(",identity=" + ObjectUtils
					.getIdentityHexString(((EndpointMBean) bean).getEndpoint()));
		}
		builder.append(getStaticNames());
		return ObjectNameManager.getInstance(builder.toString());
	}

	return this.defaultNamingStrategy.getObjectName(bean, beanKey);
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:27,代码来源:EndpointMBeanExporter.java

示例3: 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();
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:20,代码来源:EnableMBeanExportConfigurationTests.java

示例4: getObjectName

import org.springframework.jmx.support.ObjectNameManager; //导入方法依赖的package包/类
private ObjectName getObjectName(String domain, String beanKey,
		ApplicationContext applicationContext) throws MalformedObjectNameException {
	String name = "%s:type=Endpoint,name=%s";
	if (applicationContext.getParent() != null) {
		name = name + ",context=%s";
	}
	if (applicationContext.getEnvironment().getProperty("endpoints.jmx.unique_names",
			Boolean.class, false)) {
		name = name + ",identity=" + ObjectUtils
				.getIdentityHexString(applicationContext.getBean(beanKey));
	}
	if (applicationContext.getParent() != null) {
		return ObjectNameManager.getInstance(String.format(name, domain, beanKey,
				ObjectUtils.getIdentityHexString(applicationContext)));
	}
	else {
		return ObjectNameManager.getInstance(String.format(name, domain, beanKey));
	}
}
 
开发者ID:Nephilim84,项目名称:contestparser,代码行数:20,代码来源:EndpointMBeanExportAutoConfigurationTests.java

示例5: getObjectName

import org.springframework.jmx.support.ObjectNameManager; //导入方法依赖的package包/类
@Override
public ObjectName getObjectName(Object managedBean, String beanKey) throws MalformedObjectNameException {
  ObjectName name = null;

  if (managedBean instanceof DefaultMessageListenerContainer) {
    DefaultMessageListenerContainer container = (DefaultMessageListenerContainer) managedBean;
    String domain = MESSAGE_LISTENER_CONTAINERS_DEFAULT_DOMAIN;
    Hashtable<String, String> keys = new Hashtable<String, String>();
    
    // Type : container type
    keys.put(TYPE_KEY, ClassUtils.getShortName(managedBean.getClass()));
    
    // Add destination...
    keys.put(DESTINATION_KEY, container.getDestinationName());
    
    // ... and selector to distinguish them
    if (!StringUtils.isEmpty(container.getMessageSelector())) {
      keys.put(SELECTOR_KEY, escapeSelector(container.getMessageSelector()));
    }
    name = ObjectNameManager.getInstance(domain, keys);
  } else {
    name = super.getObjectName(managedBean, beanKey);
  }

  return name;
}
 
开发者ID:benjamin-cartereau,项目名称:w4-bpmnplus-module-jms,代码行数:27,代码来源:JmsListenerContainerNamingStrategy.java

示例6: 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}.
 */
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);
		}
	}
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:29,代码来源:MetadataNamingStrategy.java

示例7: 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);
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:26,代码来源:MBeanExporterOperationsTests.java

示例8: 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);

	exporter.afterPropertiesSet();

	ObjectInstance instance = server.getObjectInstance(objectName);
	assertNotNull(instance);
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:19,代码来源:MBeanExporterTests.java

示例9: getObjectName

import org.springframework.jmx.support.ObjectNameManager; //导入方法依赖的package包/类
/**
 * Returns an instance of {@code ObjectName} based on the identity
 * of the managed resource.
 */
@Override
public ObjectName getObjectName(Object managedBean, String beanKey) throws MalformedObjectNameException {
	String domain = ClassUtils.getPackageName(managedBean.getClass());
	Hashtable<String, String> keys = new Hashtable<String, String>();
	keys.put(TYPE_KEY, ClassUtils.getShortName(managedBean.getClass()));
	keys.put(HASH_CODE_KEY, ObjectUtils.getIdentityHexString(managedBean));
	return ObjectNameManager.getInstance(domain, keys);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:13,代码来源:IdentityNamingStrategy.java

示例10: getObjectName

import org.springframework.jmx.support.ObjectNameManager; //导入方法依赖的package包/类
/**
 * Attempts to retrieve the {@code ObjectName} via the given key, trying to
 * find a mapped value in the mappings first.
 */
@Override
public ObjectName getObjectName(Object managedBean, String beanKey) throws MalformedObjectNameException {
	String objectName = null;
	if (this.mergedMappings != null) {
		objectName = this.mergedMappings.getProperty(beanKey);
	}
	if (objectName == null) {
		objectName = beanKey;
	}
	return ObjectNameManager.getInstance(objectName);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:16,代码来源:KeyNamingStrategy.java

示例11: testRegisterManagedResourceWithGeneratedObjectNameWithoutUniqueness

import org.springframework.jmx.support.ObjectNameManager; //导入方法依赖的package包/类
@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());
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:29,代码来源:MBeanExporterOperationsTests.java

示例12: getObjectName

import org.springframework.jmx.support.ObjectNameManager; //导入方法依赖的package包/类
@Override
public ObjectName getObjectName(Object managedBean, String beanKey)
		throws MalformedObjectNameException {
	ObjectName name = super.getObjectName(managedBean, beanKey);
	Hashtable<String, String> properties = new Hashtable<String, String>();
	properties.putAll(name.getKeyPropertyList());
	if (this.ensureUniqueRuntimeObjectNames) {
		properties.put("identity", ObjectUtils.getIdentityHexString(managedBean));
	}
	else if (parentContextContainsSameBean(this.applicationContext, beanKey)) {
		properties.put("context",
				ObjectUtils.getIdentityHexString(this.applicationContext));
	}
	return ObjectNameManager.getInstance(name.getDomain(), properties);
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:16,代码来源:ParentAwareNamingStrategy.java

示例13: lazyNaming

import org.springframework.jmx.support.ObjectNameManager; //导入方法依赖的package包/类
@Test
public void lazyNaming() throws Exception {
	ConfigurableApplicationContext ctx =
			new ClassPathXmlApplicationContext("org/springframework/jmx/export/annotation/lazyNaming.xml");
	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();
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:16,代码来源:AnnotationLazyInitMBeanTests.java

示例14: lazyAssembling

import org.springframework.jmx.support.ObjectNameManager; //导入方法依赖的package包/类
@Test
public void lazyAssembling() throws Exception {
	System.setProperty("domain", "bean");
	ConfigurableApplicationContext ctx =
			new ClassPathXmlApplicationContext("org/springframework/jmx/export/annotation/lazyAssembling.xml");
	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);

		oname = ObjectNameManager.getInstance("bean:name=testBean5");
		assertNotNull(server.getObjectInstance(oname));
		name = (String) server.getAttribute(oname, "Name");
		assertEquals("Invalid name returned", "FACTORY", name);

		oname = ObjectNameManager.getInstance("spring:mbean=true");
		assertNotNull(server.getObjectInstance(oname));
		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 {
		System.clearProperty("domain");
		ctx.close();
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:34,代码来源:AnnotationLazyInitMBeanTests.java

示例15: componentScan

import org.springframework.jmx.support.ObjectNameManager; //导入方法依赖的package包/类
@Test
public void componentScan() throws Exception {
	ConfigurableApplicationContext ctx =
			new ClassPathXmlApplicationContext("org/springframework/jmx/export/annotation/componentScan.xml");
	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");
		assertNull(name);
	}
	finally {
		ctx.close();
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:16,代码来源:AnnotationLazyInitMBeanTests.java


注:本文中的org.springframework.jmx.support.ObjectNameManager.getInstance方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。