本文整理匯總了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;
}