use of org.eclipse.jetty.util.annotation.ManagedAttribute in project jetty.project by eclipse.
the class ContextHandler method getClassPath.
/* ------------------------------------------------------------ */
/**
* Make best effort to extract a file classpath from the context classloader
*
* @return Returns the classLoader.
*/
@ManagedAttribute("The file classpath")
public String getClassPath() {
if (_classLoader == null || !(_classLoader instanceof URLClassLoader))
return null;
URLClassLoader loader = (URLClassLoader) _classLoader;
URL[] urls = loader.getURLs();
StringBuilder classpath = new StringBuilder();
for (int i = 0; i < urls.length; i++) {
try {
Resource resource = newResource(urls[i]);
File file = resource.getFile();
if (file != null && file.exists()) {
if (classpath.length() > 0)
classpath.append(File.pathSeparatorChar);
classpath.append(file.getAbsolutePath());
}
} catch (IOException e) {
LOG.debug(e);
}
}
if (classpath.length() == 0)
return null;
return classpath.toString();
}
use of org.eclipse.jetty.util.annotation.ManagedAttribute in project jetty.project by eclipse.
the class ContextHandlerMBean method getContextAttributes.
@ManagedAttribute("Map of context attributes")
public Map<String, Object> getContextAttributes() {
Map<String, Object> map = new HashMap<String, Object>();
Attributes attrs = ((ContextHandler) _managed).getAttributes();
Enumeration<String> en = attrs.getAttributeNames();
while (en.hasMoreElements()) {
String name = (String) en.nextElement();
Object value = attrs.getAttribute(name);
map.put(name, value);
}
return map;
}
use of org.eclipse.jetty.util.annotation.ManagedAttribute in project jetty.project by eclipse.
the class ObjectMBean method getMBeanInfo.
public MBeanInfo getMBeanInfo() {
try {
if (_info == null) {
// Start with blank lazy lists attributes etc.
String desc = null;
List<MBeanAttributeInfo> attributes = new ArrayList<MBeanAttributeInfo>();
List<MBeanConstructorInfo> constructors = new ArrayList<MBeanConstructorInfo>();
List<MBeanOperationInfo> operations = new ArrayList<MBeanOperationInfo>();
List<MBeanNotificationInfo> notifications = new ArrayList<MBeanNotificationInfo>();
// Find list of classes that can influence the mbean
Class<?> o_class = _managed.getClass();
List<Class<?>> influences = new ArrayList<Class<?>>();
// always add MBean itself
influences.add(this.getClass());
influences = findInfluences(influences, _managed.getClass());
if (LOG.isDebugEnabled())
LOG.debug("Influence Count: {}", influences.size());
// Process Type Annotations
ManagedObject primary = o_class.getAnnotation(ManagedObject.class);
if (primary != null) {
desc = primary.value();
} else {
if (LOG.isDebugEnabled())
LOG.debug("No @ManagedObject declared on {}", _managed.getClass());
}
// For each influence
for (int i = 0; i < influences.size(); i++) {
Class<?> oClass = influences.get(i);
ManagedObject typeAnnotation = oClass.getAnnotation(ManagedObject.class);
if (LOG.isDebugEnabled())
LOG.debug("Influenced by: " + oClass.getCanonicalName());
if (typeAnnotation == null) {
if (LOG.isDebugEnabled())
LOG.debug("Annotations not found for: {}", oClass.getCanonicalName());
continue;
}
for (Method method : oClass.getDeclaredMethods()) {
ManagedAttribute methodAttributeAnnotation = method.getAnnotation(ManagedAttribute.class);
if (methodAttributeAnnotation != null) {
// TODO sort out how a proper name could get here, its a method name as an attribute at this point.
if (LOG.isDebugEnabled())
LOG.debug("Attribute Annotation found for: {}", method.getName());
MBeanAttributeInfo mai = defineAttribute(method, methodAttributeAnnotation);
if (mai != null) {
attributes.add(mai);
}
}
ManagedOperation methodOperationAnnotation = method.getAnnotation(ManagedOperation.class);
if (methodOperationAnnotation != null) {
if (LOG.isDebugEnabled())
LOG.debug("Method Annotation found for: {}", method.getName());
MBeanOperationInfo oi = defineOperation(method, methodOperationAnnotation);
if (oi != null) {
operations.add(oi);
}
}
}
}
_info = new MBeanInfo(o_class.getName(), desc, (MBeanAttributeInfo[]) attributes.toArray(new MBeanAttributeInfo[attributes.size()]), (MBeanConstructorInfo[]) constructors.toArray(new MBeanConstructorInfo[constructors.size()]), (MBeanOperationInfo[]) operations.toArray(new MBeanOperationInfo[operations.size()]), (MBeanNotificationInfo[]) notifications.toArray(new MBeanNotificationInfo[notifications.size()]));
}
} catch (RuntimeException e) {
LOG.warn(e);
throw e;
}
return _info;
}
Aggregations