org.springframework.jmx.export.metadata.ManagedResource Java Examples

The following examples show how to use org.springframework.jmx.export.metadata.ManagedResource. 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: MetadataNamingStrategy.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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);
		}
	}
}
 
Example #2
Source File: MetadataNamingStrategy.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
/**
 * 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);
		}
	}
}
 
Example #3
Source File: MetadataNamingStrategy.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * Reads the {@code ObjectName} from the source-level metadata associated
 * with the managed resource's {@code Class}.
 */
@Override
public ObjectName getObjectName(Object managedBean, @Nullable String beanKey) throws MalformedObjectNameException {
	Assert.state(this.attributeSource != null, "No JmxAttributeSource set");
	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 {
		Assert.state(beanKey != null, "No ManagedResource attribute and no bean key specified");
		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<>();
			properties.put("type", ClassUtils.getShortName(managedClass));
			properties.put("name", beanKey);
			return ObjectNameManager.getInstance(domain, properties);
		}
	}
}
 
Example #4
Source File: MetadataMBeanInfoAssembler.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * Adds descriptor fields from the {@code ManagedResource} attribute
 * to the MBean descriptor. Specifically, adds the {@code currencyTimeLimit},
 * {@code persistPolicy}, {@code persistPeriod}, {@code persistLocation}
 * and {@code persistName} descriptor fields if they are present in the metadata.
 */
@Override
protected void populateMBeanDescriptor(Descriptor desc, Object managedBean, String beanKey) {
	ManagedResource mr = obtainAttributeSource().getManagedResource(getClassToExpose(managedBean));
	if (mr == null) {
		throw new InvalidMetadataException(
				"No ManagedResource attribute found for class: " + getClassToExpose(managedBean));
	}

	applyCurrencyTimeLimit(desc, mr.getCurrencyTimeLimit());

	if (mr.isLog()) {
		desc.setField(FIELD_LOG, "true");
	}
	if (StringUtils.hasLength(mr.getLogFile())) {
		desc.setField(FIELD_LOG_FILE, mr.getLogFile());
	}

	if (StringUtils.hasLength(mr.getPersistPolicy())) {
		desc.setField(FIELD_PERSIST_POLICY, mr.getPersistPolicy());
	}
	if (mr.getPersistPeriod() >= 0) {
		desc.setField(FIELD_PERSIST_PERIOD, Integer.toString(mr.getPersistPeriod()));
	}
	if (StringUtils.hasLength(mr.getPersistName())) {
		desc.setField(FIELD_PERSIST_NAME, mr.getPersistName());
	}
	if (StringUtils.hasLength(mr.getPersistLocation())) {
		desc.setField(FIELD_PERSIST_LOCATION, mr.getPersistLocation());
	}
}
 
Example #5
Source File: MetadataNamingStrategy.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * Reads the {@code ObjectName} from the source-level metadata associated
 * with the managed resource's {@code Class}.
 */
@Override
public ObjectName getObjectName(Object managedBean, @Nullable String beanKey) throws MalformedObjectNameException {
	Assert.state(this.attributeSource != null, "No JmxAttributeSource set");
	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 {
		Assert.state(beanKey != null, "No ManagedResource attribute and no bean key specified");
		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<>();
			properties.put("type", ClassUtils.getShortName(managedClass));
			properties.put("name", beanKey);
			return ObjectNameManager.getInstance(domain, properties);
		}
	}
}
 
Example #6
Source File: MetadataMBeanInfoAssembler.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * Adds descriptor fields from the {@code ManagedResource} attribute
 * to the MBean descriptor. Specifically, adds the {@code currencyTimeLimit},
 * {@code persistPolicy}, {@code persistPeriod}, {@code persistLocation}
 * and {@code persistName} descriptor fields if they are present in the metadata.
 */
@Override
protected void populateMBeanDescriptor(Descriptor desc, Object managedBean, String beanKey) {
	ManagedResource mr = obtainAttributeSource().getManagedResource(getClassToExpose(managedBean));
	if (mr == null) {
		throw new InvalidMetadataException(
				"No ManagedResource attribute found for class: " + getClassToExpose(managedBean));
	}

	applyCurrencyTimeLimit(desc, mr.getCurrencyTimeLimit());

	if (mr.isLog()) {
		desc.setField(FIELD_LOG, "true");
	}
	if (StringUtils.hasLength(mr.getLogFile())) {
		desc.setField(FIELD_LOG_FILE, mr.getLogFile());
	}

	if (StringUtils.hasLength(mr.getPersistPolicy())) {
		desc.setField(FIELD_PERSIST_POLICY, mr.getPersistPolicy());
	}
	if (mr.getPersistPeriod() >= 0) {
		desc.setField(FIELD_PERSIST_PERIOD, Integer.toString(mr.getPersistPeriod()));
	}
	if (StringUtils.hasLength(mr.getPersistName())) {
		desc.setField(FIELD_PERSIST_NAME, mr.getPersistName());
	}
	if (StringUtils.hasLength(mr.getPersistLocation())) {
		desc.setField(FIELD_PERSIST_LOCATION, mr.getPersistLocation());
	}
}
 
Example #7
Source File: MetadataMBeanInfoAssembler.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Adds descriptor fields from the {@code ManagedResource} attribute
 * to the MBean descriptor. Specifically, adds the {@code currencyTimeLimit},
 * {@code persistPolicy}, {@code persistPeriod}, {@code persistLocation}
 * and {@code persistName} descriptor fields if they are present in the metadata.
 */
@Override
protected void populateMBeanDescriptor(Descriptor desc, Object managedBean, String beanKey) {
	ManagedResource mr = this.attributeSource.getManagedResource(getClassToExpose(managedBean));
	if (mr == null) {
		throw new InvalidMetadataException(
				"No ManagedResource attribute found for class: " + getClassToExpose(managedBean));
	}

	applyCurrencyTimeLimit(desc, mr.getCurrencyTimeLimit());

	if (mr.isLog()) {
		desc.setField(FIELD_LOG, "true");
	}
	if (StringUtils.hasLength(mr.getLogFile())) {
		desc.setField(FIELD_LOG_FILE, mr.getLogFile());
	}

	if (StringUtils.hasLength(mr.getPersistPolicy())) {
		desc.setField(FIELD_PERSIST_POLICY, mr.getPersistPolicy());
	}
	if (mr.getPersistPeriod() >= 0) {
		desc.setField(FIELD_PERSIST_PERIOD, Integer.toString(mr.getPersistPeriod()));
	}
	if (StringUtils.hasLength(mr.getPersistName())) {
		desc.setField(FIELD_PERSIST_NAME, mr.getPersistName());
	}
	if (StringUtils.hasLength(mr.getPersistLocation())) {
		desc.setField(FIELD_PERSIST_LOCATION, mr.getPersistLocation());
	}
}
 
Example #8
Source File: MetadataMBeanInfoAssembler.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * Adds descriptor fields from the {@code ManagedResource} attribute
 * to the MBean descriptor. Specifically, adds the {@code currencyTimeLimit},
 * {@code persistPolicy}, {@code persistPeriod}, {@code persistLocation}
 * and {@code persistName} descriptor fields if they are present in the metadata.
 */
@Override
protected void populateMBeanDescriptor(Descriptor desc, Object managedBean, String beanKey) {
	ManagedResource mr = this.attributeSource.getManagedResource(getClassToExpose(managedBean));
	if (mr == null) {
		throw new InvalidMetadataException(
				"No ManagedResource attribute found for class: " + getClassToExpose(managedBean));
	}

	applyCurrencyTimeLimit(desc, mr.getCurrencyTimeLimit());

	if (mr.isLog()) {
		desc.setField(FIELD_LOG, "true");
	}
	if (StringUtils.hasLength(mr.getLogFile())) {
		desc.setField(FIELD_LOG_FILE, mr.getLogFile());
	}

	if (StringUtils.hasLength(mr.getPersistPolicy())) {
		desc.setField(FIELD_PERSIST_POLICY, mr.getPersistPolicy());
	}
	if (mr.getPersistPeriod() >= 0) {
		desc.setField(FIELD_PERSIST_PERIOD, Integer.toString(mr.getPersistPeriod()));
	}
	if (StringUtils.hasLength(mr.getPersistName())) {
		desc.setField(FIELD_PERSIST_NAME, mr.getPersistName());
	}
	if (StringUtils.hasLength(mr.getPersistLocation())) {
		desc.setField(FIELD_PERSIST_LOCATION, mr.getPersistLocation());
	}
}
 
Example #9
Source File: MetadataMBeanInfoAssembler.java    From spring-analysis-note with MIT License 4 votes vote down vote up
/**
 * Reads managed resource description from the source level metadata.
 * Returns an empty {@code String} if no description can be found.
 */
@Override
protected String getDescription(Object managedBean, String beanKey) {
	ManagedResource mr = obtainAttributeSource().getManagedResource(getClassToExpose(managedBean));
	return (mr != null ? mr.getDescription() : "");
}
 
Example #10
Source File: MetadataMBeanInfoAssembler.java    From java-technology-stack with MIT License 4 votes vote down vote up
/**
 * Reads managed resource description from the source level metadata.
 * Returns an empty {@code String} if no description can be found.
 */
@Override
protected String getDescription(Object managedBean, String beanKey) {
	ManagedResource mr = obtainAttributeSource().getManagedResource(getClassToExpose(managedBean));
	return (mr != null ? mr.getDescription() : "");
}
 
Example #11
Source File: MetadataMBeanInfoAssembler.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Reads managed resource description from the source level metadata.
 * Returns an empty {@code String} if no description can be found.
 */
@Override
protected String getDescription(Object managedBean, String beanKey) {
	ManagedResource mr = this.attributeSource.getManagedResource(getClassToExpose(managedBean));
	return (mr != null ? mr.getDescription() : "");
}
 
Example #12
Source File: MetadataMBeanInfoAssembler.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
/**
 * Reads managed resource description from the source level metadata.
 * Returns an empty {@code String} if no description can be found.
 */
@Override
protected String getDescription(Object managedBean, String beanKey) {
	ManagedResource mr = this.attributeSource.getManagedResource(getClassToExpose(managedBean));
	return (mr != null ? mr.getDescription() : "");
}