本文整理汇总了Java中org.springframework.jmx.export.annotation.ManagedResource类的典型用法代码示例。如果您正苦于以下问题:Java ManagedResource类的具体用法?Java ManagedResource怎么用?Java ManagedResource使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ManagedResource类属于org.springframework.jmx.export.annotation包,在下文中一共展示了ManagedResource类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: registerEndpoint
import org.springframework.jmx.export.annotation.ManagedResource; //导入依赖的package包/类
protected void registerEndpoint(String beanName, Endpoint<?> endpoint) {
@SuppressWarnings("rawtypes")
Class<? extends Endpoint> type = endpoint.getClass();
if (AnnotationUtils.findAnnotation(type, ManagedResource.class) != null) {
// Already managed
return;
}
if (type.isMemberClass()
&& AnnotationUtils.findAnnotation(type.getEnclosingClass(),
ManagedResource.class) != null) {
// Nested class with @ManagedResource in parent
return;
}
try {
registerBeanNameOrInstance(getEndpointMBean(beanName, endpoint), beanName);
}
catch (MBeanExportException ex) {
logger.error("Could not register MBean for endpoint [" + beanName + "]", ex);
}
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:21,代码来源:EndpointMBeanExporter.java
示例2: formatBean
import org.springframework.jmx.export.annotation.ManagedResource; //导入依赖的package包/类
@Override
protected void formatBean(Object objBean) throws Exception {
IdentityHashMap identityHashMap = new IdentityHashMap();
// root object
Map<String, Object> json = new HashMap<String, Object>();
// set desc and type on root
Class<?> clazz = objBean.getClass();
ManagedResource mr = clazz.getAnnotation(ManagedResource.class);
String strHelp = mr == null ? null : mr.description();
if (strHelp != null)
json.put("description", strHelp);
json.put("bean", clazz.getName());
identityHashMap.put(objBean, Boolean.TRUE);
// add properties and operations, recursively as needed
format(objBean, json, identityHashMap);
ObjectMapper mapper = new ObjectMapper();
mapper.configure(Feature.FAIL_ON_EMPTY_BEANS, false);
// Output
getWriter().print(mapper.writeValueAsString(json));
}
示例3: formatBean
import org.springframework.jmx.export.annotation.ManagedResource; //导入依赖的package包/类
@Override
protected final void formatBean(Object bean) throws Exception {
Class<?> bclass = bean.getClass();
ManagedResource mr = bclass.getAnnotation(ManagedResource.class);
String help = mr == null ? null : mr.description();
formatBean(false, bclass, help);
boolean section = false;
for (PropertyDescriptor pd : Introspector.getBeanInfo(bclass)
.getPropertyDescriptors()) {
Method getter = pd.getReadMethod();
if (!XMLSerializationManager.isHidden(getter)) {
if (!section) {
section = true;
formatSection(false, "Properties");
}
formatProperty(bean, pd);
}
}
if (section) {
formatSection(true, "Properties");
}
section = false;
for (Method method : bean.getClass().getMethods()) {
ManagedOperation mo = method.getAnnotation(ManagedOperation.class);
if (mo != null && method.getParameterTypes().length == 0) {
help = mo.description();
if (!section) {
section = true;
formatSection(false, "Operations");
}
formatOperation(method);
}
if (section) {
formatSection(true, "Operations");
}
}
}
示例4: getResourcePath
import org.springframework.jmx.export.annotation.ManagedResource; //导入依赖的package包/类
private static String getResourcePath(String path, Object bean) {
String rpath = path;
ManagedResource mr = bean.getClass().getAnnotation(ManagedResource.class);
if (mr != null) {
String xpath = mr.objectName();
if (xpath == null || xpath.length() == 0)
xpath = mr.value();
if (xpath != null && xpath.length() > 0) {
rpath = path == null ? "" : xpath.startsWith(PATH_RELATIVE) ? path + PATH_SEPARATOR : PATH_SEPARATOR + path;
rpath = xpath.startsWith(PATH_RELATIVE) ? rpath + xpath.substring(PATH_RELATIVE.length()) : xpath + rpath;
}
}
return rpath;
}
示例5: assemble
import org.springframework.jmx.export.annotation.ManagedResource; //导入依赖的package包/类
public ModelMBean assemble(MBeanServer mBeanServer, Object obj, ObjectName name) throws JMException {
ModelMBeanInfo mbi = null;
// prefer to use the managed instance if it has been annotated with Spring JMX annotations
if (obj instanceof ManagedInstance) {
Object custom = ((ManagedInstance) obj).getInstance();
if (custom != null && ObjectHelper.hasAnnotation(custom.getClass().getAnnotations(), ManagedResource.class)) {
LOG.trace("Assembling MBeanInfo for: {} from custom @ManagedResource object: {}", name, custom);
// get the mbean info from the custom managed object
mbi = springAssembler.getMBeanInfo(custom, name.toString());
// and let the custom object be registered in JMX
obj = custom;
}
}
if (mbi == null) {
if (ObjectHelper.hasAnnotation(obj.getClass().getAnnotations(), ManagedResource.class)) {
// the object has a Spring ManagedResource annotations so assemble the MBeanInfo
LOG.trace("Assembling MBeanInfo for: {} from @ManagedResource object: {}", name, obj);
mbi = springAssembler.getMBeanInfo(obj, name.toString());
} else {
// fallback and let the default mbean assembler handle this instead
return super.assemble(mBeanServer, obj, name);
}
}
LOG.trace("Assembled MBeanInfo {}", mbi);
RequiredModelMBean mbean = (RequiredModelMBean) mBeanServer.instantiate(RequiredModelMBean.class.getName());
mbean.setModelMBeanInfo(mbi);
try {
mbean.setManagedResource(obj, "ObjectReference");
} catch (InvalidTargetObjectTypeException e) {
throw new JMException(e.getMessage());
}
// Allows the managed object to send notifications
if (obj instanceof NotificationSenderAware) {
((NotificationSenderAware)obj).setNotificationSender(new NotificationSenderAdapter(mbean));
}
return mbean;
}