Merge branch 'jetty-9' of ssh://git.eclipse.org/gitroot/jetty/org.eclipse.jetty.project into jetty-9
This commit is contained in:
commit
57f16d750d
|
@ -20,15 +20,14 @@ import java.lang.reflect.Field;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.lang.reflect.Modifier;
|
import java.lang.reflect.Modifier;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Enumeration;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.Locale;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.MissingResourceException;
|
import java.util.MissingResourceException;
|
||||||
import java.util.ResourceBundle;
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import javax.management.Attribute;
|
import javax.management.Attribute;
|
||||||
|
@ -47,10 +46,11 @@ import javax.management.ObjectName;
|
||||||
import javax.management.ReflectionException;
|
import javax.management.ReflectionException;
|
||||||
import javax.management.modelmbean.ModelMBean;
|
import javax.management.modelmbean.ModelMBean;
|
||||||
|
|
||||||
import org.eclipse.jetty.util.LazyList;
|
|
||||||
import org.eclipse.jetty.util.Loader;
|
import org.eclipse.jetty.util.Loader;
|
||||||
import org.eclipse.jetty.util.TypeUtil;
|
import org.eclipse.jetty.util.TypeUtil;
|
||||||
import org.eclipse.jetty.util.annotation.Managed;
|
import org.eclipse.jetty.util.annotation.ManagedAttribute;
|
||||||
|
import org.eclipse.jetty.util.annotation.ManagedObject;
|
||||||
|
import org.eclipse.jetty.util.annotation.ManagedOperation;
|
||||||
import org.eclipse.jetty.util.annotation.Name;
|
import org.eclipse.jetty.util.annotation.Name;
|
||||||
import org.eclipse.jetty.util.log.Log;
|
import org.eclipse.jetty.util.log.Log;
|
||||||
import org.eclipse.jetty.util.log.Logger;
|
import org.eclipse.jetty.util.log.Logger;
|
||||||
|
@ -109,21 +109,23 @@ public class ObjectMBean implements DynamicMBean
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Class oClass = o.getClass();
|
Class<?> oClass = o.getClass();
|
||||||
Object mbean = null;
|
Object mbean = null;
|
||||||
|
|
||||||
while (mbean == null && oClass != null)
|
while (mbean == null && oClass != null)
|
||||||
{
|
{
|
||||||
String pName = oClass.getPackage().getName();
|
ManagedObject mo = oClass.getAnnotation(ManagedObject.class);
|
||||||
String cName = oClass.getName().substring(pName.length() + 1);
|
String mName = "";
|
||||||
String mName = pName + ".jmx." + cName + "MBean";
|
if ( mo != null )
|
||||||
|
{
|
||||||
|
mName = mo.wrapper();
|
||||||
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Class mClass = (Object.class.equals(oClass))?oClass=ObjectMBean.class:Loader.loadClass(oClass,mName,true);
|
Class mClass = (Object.class.equals(oClass))?oClass=ObjectMBean.class:Loader.loadClass(oClass,mName,true);
|
||||||
if (LOG.isDebugEnabled())
|
|
||||||
LOG.debug("mbeanFor " + o + " mClass=" + mClass);
|
LOG.debug("ObjectMbean: mbeanFor {} mClass={}", o, mClass);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -140,8 +142,8 @@ public class ObjectMBean implements DynamicMBean
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (LOG.isDebugEnabled())
|
LOG.debug("mbeanFor {} is {}", o, mbean);
|
||||||
LOG.debug("mbeanFor " + o + " is " + mbean);
|
|
||||||
return mbean;
|
return mbean;
|
||||||
}
|
}
|
||||||
catch (ClassNotFoundException e)
|
catch (ClassNotFoundException e)
|
||||||
|
@ -222,27 +224,27 @@ public class ObjectMBean implements DynamicMBean
|
||||||
{
|
{
|
||||||
// Start with blank lazy lists attributes etc.
|
// Start with blank lazy lists attributes etc.
|
||||||
String desc=null;
|
String desc=null;
|
||||||
Object attributes=null;
|
List<MBeanAttributeInfo> attributes = new ArrayList<MBeanAttributeInfo>();
|
||||||
Object constructors=null;
|
List<MBeanConstructorInfo> constructors = new ArrayList<MBeanConstructorInfo>();
|
||||||
Object operations=null;
|
List<MBeanOperationInfo> operations = new ArrayList<MBeanOperationInfo>();
|
||||||
Object notifications=null;
|
List<MBeanNotificationInfo> notifications = new ArrayList<MBeanNotificationInfo>();
|
||||||
|
|
||||||
// Find list of classes that can influence the mbean
|
// Find list of classes that can influence the mbean
|
||||||
Class<?> o_class=_managed.getClass();
|
Class<?> o_class=_managed.getClass();
|
||||||
Object influences = findInfluences(null, _managed.getClass());
|
List<Class<?>> influences = findInfluences(new ArrayList<Class<?>>(), _managed.getClass());
|
||||||
|
|
||||||
LOG.debug("Influence Count: " + LazyList.size(influences) );
|
LOG.debug("Influence Count: " + influences.size() );
|
||||||
|
|
||||||
// Process Type Annotations
|
// Process Type Annotations
|
||||||
Managed primary = o_class.getAnnotation( Managed.class);
|
ManagedObject primary = o_class.getAnnotation( ManagedObject.class);
|
||||||
desc = primary.value();
|
desc = primary.value();
|
||||||
|
|
||||||
// For each influence
|
// For each influence
|
||||||
for (int i=0;i<LazyList.size(influences);i++)
|
for (int i=0;i<influences.size();i++)
|
||||||
{
|
{
|
||||||
Class<?> oClass = (Class<?>)LazyList.get(influences, i);
|
Class<?> oClass = influences.get(i);
|
||||||
|
|
||||||
Managed typeAnnotation = oClass.getAnnotation( Managed.class);
|
ManagedObject typeAnnotation = oClass.getAnnotation( ManagedObject.class);
|
||||||
|
|
||||||
LOG.debug("Influenced by: " + oClass.getCanonicalName() );
|
LOG.debug("Influenced by: " + oClass.getCanonicalName() );
|
||||||
if ( typeAnnotation == null )
|
if ( typeAnnotation == null )
|
||||||
|
@ -257,12 +259,12 @@ public class ObjectMBean implements DynamicMBean
|
||||||
for ( Field field : oClass.getDeclaredFields())
|
for ( Field field : oClass.getDeclaredFields())
|
||||||
{
|
{
|
||||||
LOG.debug("Checking: " + field.getName());
|
LOG.debug("Checking: " + field.getName());
|
||||||
Managed fieldAnnotation = field.getAnnotation(Managed.class);
|
ManagedAttribute fieldAnnotation = field.getAnnotation(ManagedAttribute.class);
|
||||||
|
|
||||||
if ( fieldAnnotation != null )
|
if ( fieldAnnotation != null )
|
||||||
{
|
{
|
||||||
LOG.debug("Field Annotation found for: " + field.getName() );
|
LOG.debug("Field Annotation found for: " + field.getName() );
|
||||||
attributes=LazyList.add(attributes, defineAttribute(field.getName(), fieldAnnotation));
|
attributes.add( defineAttribute(field.getName(), fieldAnnotation));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -270,21 +272,21 @@ public class ObjectMBean implements DynamicMBean
|
||||||
|
|
||||||
for ( Method method : oClass.getDeclaredMethods() )
|
for ( Method method : oClass.getDeclaredMethods() )
|
||||||
{
|
{
|
||||||
Managed methodAnnotation = method.getAnnotation(Managed.class);
|
ManagedAttribute methodAttributeAnnotation = method.getAnnotation(ManagedAttribute.class);
|
||||||
|
|
||||||
if ( methodAnnotation != null )
|
if ( methodAttributeAnnotation != null )
|
||||||
|
{
|
||||||
|
// TODO sort out how a proper name could get here, its a method name as an attribute at this point.
|
||||||
|
LOG.debug("Attribute Annotation found for: " + method.getName() );
|
||||||
|
attributes.add(defineAttribute(method.getName(),methodAttributeAnnotation));
|
||||||
|
}
|
||||||
|
|
||||||
|
ManagedOperation methodOperationAnnotation = method.getAnnotation(ManagedOperation.class);
|
||||||
|
|
||||||
|
if (methodOperationAnnotation != null)
|
||||||
{
|
{
|
||||||
if ( methodAnnotation.attribute() )
|
LOG.debug("Method Annotation found for: " + method.getName());
|
||||||
{
|
operations.add(defineOperation(method,methodOperationAnnotation));
|
||||||
// TODO sort out how a proper name could get here, its a method name as an attribute at this point.
|
|
||||||
LOG.debug("Attribute Annotation found for: " + method.getName() );
|
|
||||||
attributes=LazyList.add(attributes,defineAttribute(method.getName(),methodAnnotation));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
LOG.debug("Method Annotation found for: " + method.getName() );
|
|
||||||
operations=LazyList.add(operations, defineOperation(method, methodAnnotation));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -297,10 +299,10 @@ public class ObjectMBean implements DynamicMBean
|
||||||
|
|
||||||
_info = new MBeanInfo(o_class.getName(),
|
_info = new MBeanInfo(o_class.getName(),
|
||||||
desc,
|
desc,
|
||||||
(MBeanAttributeInfo[])LazyList.toArray(attributes, MBeanAttributeInfo.class),
|
(MBeanAttributeInfo[])attributes.toArray(new MBeanAttributeInfo[attributes.size()]),
|
||||||
(MBeanConstructorInfo[])LazyList.toArray(constructors, MBeanConstructorInfo.class),
|
(MBeanConstructorInfo[])constructors.toArray(new MBeanConstructorInfo[constructors.size()]),
|
||||||
(MBeanOperationInfo[])LazyList.toArray(operations, MBeanOperationInfo.class),
|
(MBeanOperationInfo[])operations.toArray(new MBeanOperationInfo[operations.size()]),
|
||||||
(MBeanNotificationInfo[])LazyList.toArray(notifications, MBeanNotificationInfo.class));
|
(MBeanNotificationInfo[])notifications.toArray(new MBeanNotificationInfo[notifications.size()]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch(RuntimeException e)
|
catch(RuntimeException e)
|
||||||
|
@ -317,7 +319,10 @@ public class ObjectMBean implements DynamicMBean
|
||||||
{
|
{
|
||||||
Method getter = (Method) _getters.get(name);
|
Method getter = (Method) _getters.get(name);
|
||||||
if (getter == null)
|
if (getter == null)
|
||||||
|
{
|
||||||
throw new AttributeNotFoundException(name);
|
throw new AttributeNotFoundException(name);
|
||||||
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Object o = _managed;
|
Object o = _managed;
|
||||||
|
@ -326,7 +331,7 @@ public class ObjectMBean implements DynamicMBean
|
||||||
|
|
||||||
// get the attribute
|
// get the attribute
|
||||||
Object r=getter.invoke(o, (java.lang.Object[]) null);
|
Object r=getter.invoke(o, (java.lang.Object[]) null);
|
||||||
|
|
||||||
// convert to ObjectName if need be.
|
// convert to ObjectName if need be.
|
||||||
if (r!=null && _convert.contains(name))
|
if (r!=null && _convert.contains(name))
|
||||||
{
|
{
|
||||||
|
@ -349,11 +354,13 @@ public class ObjectMBean implements DynamicMBean
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ObjectName mbean = _mbeanContainer.findMBean(r);
|
ObjectName mbean = _mbeanContainer.findMBean(r);
|
||||||
|
|
||||||
if (mbean==null)
|
if (mbean==null)
|
||||||
return null;
|
return null;
|
||||||
r=mbean;
|
r=mbean;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
catch (IllegalAccessException e)
|
catch (IllegalAccessException e)
|
||||||
|
@ -462,8 +469,7 @@ public class ObjectMBean implements DynamicMBean
|
||||||
/* ------------------------------------------------------------ */
|
/* ------------------------------------------------------------ */
|
||||||
public Object invoke(String name, Object[] params, String[] signature) throws MBeanException, ReflectionException
|
public Object invoke(String name, Object[] params, String[] signature) throws MBeanException, ReflectionException
|
||||||
{
|
{
|
||||||
if (LOG.isDebugEnabled())
|
LOG.debug("ObjectMBean:invoke " + name);
|
||||||
LOG.debug("invoke " + name);
|
|
||||||
|
|
||||||
String methodKey = name + "(";
|
String methodKey = name + "(";
|
||||||
if (signature != null)
|
if (signature != null)
|
||||||
|
@ -480,8 +486,11 @@ public class ObjectMBean implements DynamicMBean
|
||||||
throw new NoSuchMethodException(methodKey);
|
throw new NoSuchMethodException(methodKey);
|
||||||
|
|
||||||
Object o = _managed;
|
Object o = _managed;
|
||||||
|
|
||||||
if (method.getDeclaringClass().isInstance(this))
|
if (method.getDeclaringClass().isInstance(this))
|
||||||
|
{
|
||||||
o = this;
|
o = this;
|
||||||
|
}
|
||||||
return method.invoke(o, params);
|
return method.invoke(o, params);
|
||||||
}
|
}
|
||||||
catch (NoSuchMethodException e)
|
catch (NoSuchMethodException e)
|
||||||
|
@ -505,38 +514,42 @@ public class ObjectMBean implements DynamicMBean
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Object findInfluences(Object influences, Class aClass)
|
private static List<Class<?>> findInfluences(List<Class<?>> influences, Class<?> aClass)
|
||||||
{
|
{
|
||||||
if (aClass!=null)
|
if (aClass!=null)
|
||||||
{
|
{
|
||||||
// This class is an influence
|
// This class is an influence
|
||||||
influences=LazyList.add(influences,aClass);
|
influences.add(aClass);
|
||||||
|
|
||||||
/* enabled mbean influence
|
// check for mbean influence
|
||||||
String pack = aClass.getPackage().getName();
|
ManagedObject mo = aClass.getAnnotation(ManagedObject.class);
|
||||||
String clazz = aClass.getSimpleName();
|
|
||||||
|
|
||||||
try
|
if ( mo != null && !"".equals(mo.wrapper()))
|
||||||
{
|
{
|
||||||
Class mbean = Class.forName(pack + ".jmx." + clazz + "MBean");
|
String clazz = mo.wrapper();
|
||||||
|
|
||||||
LOG.debug("MBean Influence found for " + aClass.getSimpleName() );
|
try
|
||||||
influences = LazyList.add(influences, mbean);
|
{
|
||||||
|
Class<?> mbean = Class.forName(clazz);
|
||||||
|
|
||||||
|
LOG.debug("MBean Influence found for " + aClass.getSimpleName() );
|
||||||
|
influences.add(mbean);
|
||||||
|
}
|
||||||
|
catch ( ClassNotFoundException cnfe )
|
||||||
|
{
|
||||||
|
LOG.debug("No MBean Influence for " + aClass.getSimpleName() );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch ( ClassNotFoundException cnfe )
|
|
||||||
{
|
|
||||||
LOG.debug("No MBean Influence for " + aClass.getSimpleName() );
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
// So are the super classes
|
// So are the super classes
|
||||||
influences=findInfluences(influences,aClass.getSuperclass());
|
influences=findInfluences(influences,aClass.getSuperclass());
|
||||||
|
|
||||||
// So are the interfaces
|
// So are the interfaces
|
||||||
Class[] ifs = aClass.getInterfaces();
|
Class<?>[] ifs = aClass.getInterfaces();
|
||||||
for (int i=0;ifs!=null && i<ifs.length;i++)
|
for (int i=0;ifs!=null && i<ifs.length;i++)
|
||||||
influences=findInfluences(influences,ifs[i]);
|
influences=findInfluences(influences,ifs[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return influences;
|
return influences;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -558,26 +571,26 @@ public class ObjectMBean implements DynamicMBean
|
||||||
* </ul>
|
* </ul>
|
||||||
* the access is either "RW" or "RO".
|
* the access is either "RW" or "RO".
|
||||||
*/
|
*/
|
||||||
public MBeanAttributeInfo defineAttribute(String name, Managed fieldAnnotation)
|
public MBeanAttributeInfo defineAttribute(String name, ManagedAttribute attributeAnnotation)
|
||||||
{
|
{
|
||||||
//String name = field.getName();
|
//String name = field.getName();
|
||||||
String description = fieldAnnotation.value();
|
String description = attributeAnnotation.value();
|
||||||
boolean writable = fieldAnnotation.readonly();
|
boolean writable = attributeAnnotation.readonly();
|
||||||
boolean onMBean = fieldAnnotation.proxied();
|
boolean onMBean = attributeAnnotation.proxied();
|
||||||
boolean convert = fieldAnnotation.managed();
|
boolean convert = attributeAnnotation.managed();
|
||||||
|
|
||||||
String uName = name.substring(0, 1).toUpperCase() + name.substring(1);
|
String uName = name.substring(0, 1).toUpperCase() + name.substring(1);
|
||||||
Class oClass = onMBean ? this.getClass() : _managed.getClass();
|
Class oClass = onMBean ? this.getClass() : _managed.getClass();
|
||||||
|
|
||||||
if (LOG.isDebugEnabled())
|
LOG.debug("defineAttribute {} {}:{}:{}:{}",name,onMBean,writable,oClass,description);
|
||||||
LOG.debug("defineAttribute "+name+" "+onMBean+":"+writable+":"+oClass+":"+description);
|
|
||||||
|
|
||||||
Class type = null;
|
Class type = null;
|
||||||
Method getter = null;
|
Method getter = null;
|
||||||
Method setter = null;
|
Method setter = null;
|
||||||
|
|
||||||
String declaredGetter = fieldAnnotation.getter();
|
String declaredGetter = attributeAnnotation.getter();
|
||||||
String declaredSetter = fieldAnnotation.setter();
|
String declaredSetter = attributeAnnotation.setter();
|
||||||
|
|
||||||
|
|
||||||
Method[] methods = oClass.getMethods();
|
Method[] methods = oClass.getMethods();
|
||||||
for (int m = 0; m < methods.length; m++)
|
for (int m = 0; m < methods.length; m++)
|
||||||
|
@ -585,6 +598,9 @@ public class ObjectMBean implements DynamicMBean
|
||||||
if ((methods[m].getModifiers() & Modifier.PUBLIC) == 0)
|
if ((methods[m].getModifiers() & Modifier.PUBLIC) == 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
LOG.debug("Declared Getter: {} vs {}", declaredGetter, methods[m].getName());
|
||||||
|
|
||||||
|
|
||||||
// Check if it is a declared getter
|
// Check if it is a declared getter
|
||||||
if (methods[m].getName().equals(declaredGetter) && methods[m].getParameterTypes().length == 0)
|
if (methods[m].getName().equals(declaredGetter) && methods[m].getParameterTypes().length == 0)
|
||||||
{
|
{
|
||||||
|
@ -739,17 +755,17 @@ public class ObjectMBean implements DynamicMBean
|
||||||
* the "Object","MBean", "MMBean" or "MObject" to indicate the method is on the object, the MBean or on the
|
* the "Object","MBean", "MMBean" or "MObject" to indicate the method is on the object, the MBean or on the
|
||||||
* object but converted to an MBean reference, and impact is either "ACTION","INFO","ACTION_INFO" or "UNKNOWN".
|
* object but converted to an MBean reference, and impact is either "ACTION","INFO","ACTION_INFO" or "UNKNOWN".
|
||||||
*/
|
*/
|
||||||
private MBeanOperationInfo defineOperation(Method method, Managed methodAnnotation)
|
private MBeanOperationInfo defineOperation(Method method, ManagedOperation methodAnnotation)
|
||||||
{
|
{
|
||||||
String description = methodAnnotation.value();
|
String description = methodAnnotation.value();
|
||||||
boolean onMBean = methodAnnotation.proxied();
|
boolean onMBean = methodAnnotation.proxied();
|
||||||
boolean convert = methodAnnotation.managed();
|
boolean convert = methodAnnotation.managed();
|
||||||
String impactName = methodAnnotation.impact();
|
String impactName = methodAnnotation.impact();
|
||||||
|
|
||||||
String signature = method.getName();
|
|
||||||
|
|
||||||
LOG.debug("defineOperation "+method.getName()+" "+onMBean+":"+impactName+":"+description);
|
LOG.debug("defineOperation "+method.getName()+" "+onMBean+":"+impactName+":"+description);
|
||||||
|
|
||||||
|
String signature = method.getName();
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -785,8 +801,21 @@ public class ObjectMBean implements DynamicMBean
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
signature += "(";
|
||||||
|
for ( int i = 0 ; i < methodTypes.length ; ++i )
|
||||||
|
{
|
||||||
|
signature += methodTypes[i].getName();
|
||||||
|
|
||||||
|
if ( i != methodTypes.length - 1 )
|
||||||
|
{
|
||||||
|
signature += ",";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
signature += ")";
|
||||||
|
|
||||||
Class returnClass = method.getReturnType();
|
Class returnClass = method.getReturnType();
|
||||||
|
LOG.debug("Method Cache: " + signature );
|
||||||
_methods.put(signature, method);
|
_methods.put(signature, method);
|
||||||
if (convert)
|
if (convert)
|
||||||
_convert.add(signature);
|
_convert.add(signature);
|
||||||
|
|
|
@ -13,13 +13,15 @@
|
||||||
|
|
||||||
package com.acme;
|
package com.acme;
|
||||||
|
|
||||||
import org.eclipse.jetty.util.annotation.Managed;
|
import org.eclipse.jetty.util.annotation.ManagedAttribute;
|
||||||
|
import org.eclipse.jetty.util.annotation.ManagedObject;
|
||||||
|
import org.eclipse.jetty.util.annotation.ManagedOperation;
|
||||||
import org.eclipse.jetty.util.annotation.Name;
|
import org.eclipse.jetty.util.annotation.Name;
|
||||||
|
|
||||||
@Managed("Test the mbean stuff")
|
@ManagedObject(value="Test the mbean stuff", wrapper="com.acme.jmx.DerivedMBean")
|
||||||
public class Derived extends Base implements Signature
|
public class Derived extends Base implements Signature
|
||||||
{
|
{
|
||||||
@Managed(value="The full name of something", getter="getFullName", setter="setFullName")
|
@ManagedAttribute(value="The full name of something", getter="getFullName", setter="setFullName")
|
||||||
String fname="Full Name";
|
String fname="Full Name";
|
||||||
|
|
||||||
public String getFullName()
|
public String getFullName()
|
||||||
|
@ -32,13 +34,13 @@ public class Derived extends Base implements Signature
|
||||||
fname=name;
|
fname=name;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Managed("publish something")
|
@ManagedOperation("publish something")
|
||||||
public void publish()
|
public void publish()
|
||||||
{
|
{
|
||||||
System.err.println("publish");
|
System.err.println("publish");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Managed("Doodle something")
|
@ManagedOperation("Doodle something")
|
||||||
public void doodle(@Name(value="doodle", description="A description of the argument") String doodle)
|
public void doodle(@Name(value="doodle", description="A description of the argument") String doodle)
|
||||||
{
|
{
|
||||||
System.err.println("doodle "+doodle);
|
System.err.println("doodle "+doodle);
|
||||||
|
|
|
@ -1,27 +1,34 @@
|
||||||
package com.acme.jmx;
|
package com.acme.jmx;
|
||||||
|
|
||||||
import org.eclipse.jetty.util.annotation.Managed;
|
import org.eclipse.jetty.jmx.ObjectMBean;
|
||||||
|
import org.eclipse.jetty.util.annotation.ManagedAttribute;
|
||||||
|
import org.eclipse.jetty.util.annotation.ManagedObject;
|
||||||
|
import org.eclipse.jetty.util.annotation.ManagedOperation;
|
||||||
import org.eclipse.jetty.util.log.Log;
|
import org.eclipse.jetty.util.log.Log;
|
||||||
import org.eclipse.jetty.util.log.Logger;
|
import org.eclipse.jetty.util.log.Logger;
|
||||||
|
|
||||||
import com.acme.Derived;
|
import com.acme.Derived;
|
||||||
|
|
||||||
@Managed("Derived MBean")
|
@ManagedObject("Derived MBean Wrapper")
|
||||||
public class DerivedMBean
|
public class DerivedMBean extends ObjectMBean
|
||||||
{
|
{
|
||||||
private static final Logger LOG = Log.getLogger(DerivedMBean.class);
|
private static final Logger LOG = Log.getLogger(DerivedMBean.class);
|
||||||
|
|
||||||
Derived managedObject;
|
|
||||||
|
|
||||||
public DerivedMBean(Object managedObject)
|
public DerivedMBean(Object managedObject)
|
||||||
{
|
{
|
||||||
this.managedObject = (Derived)managedObject;
|
super(managedObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Managed(value="test of proxy", attribute=true, managed=true, getter="good" )
|
@ManagedOperation(value="test of proxy operations", managed=true)
|
||||||
public String good()
|
public String good()
|
||||||
{
|
{
|
||||||
return "not " + managedObject.bad();
|
return "not " + ((Derived)_managed).bad();
|
||||||
|
}
|
||||||
|
|
||||||
|
@ManagedAttribute(value="test of proxy attributes", getter="goop", proxied=true)
|
||||||
|
public String goop()
|
||||||
|
{
|
||||||
|
return "goop";
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,9 @@ package org.eclipse.jetty.jmx;
|
||||||
|
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
|
import java.lang.management.ManagementFactory;
|
||||||
|
|
||||||
|
import javax.management.Attribute;
|
||||||
import javax.management.AttributeNotFoundException;
|
import javax.management.AttributeNotFoundException;
|
||||||
import javax.management.MBeanAttributeInfo;
|
import javax.management.MBeanAttributeInfo;
|
||||||
import javax.management.MBeanException;
|
import javax.management.MBeanException;
|
||||||
|
@ -43,7 +46,8 @@ public class ObjectMBeanTest
|
||||||
public void testMbeanInfo() throws Exception
|
public void testMbeanInfo() throws Exception
|
||||||
{
|
{
|
||||||
Derived derived = new Derived();
|
Derived derived = new Derived();
|
||||||
ObjectMBean mbean = new ObjectMBean(derived);
|
ObjectMBean mbean = (ObjectMBean)ObjectMBean.mbeanFor(derived);
|
||||||
|
|
||||||
assertTrue(mbean.getMBeanInfo()!=null);
|
assertTrue(mbean.getMBeanInfo()!=null);
|
||||||
|
|
||||||
MBeanInfo info = mbean.getMBeanInfo();
|
MBeanInfo info = mbean.getMBeanInfo();
|
||||||
|
@ -57,13 +61,19 @@ public class ObjectMBeanTest
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* 6 attributes from lifecycle and 1 from Derived
|
* 6 attributes from lifecycle and 1 from Derived and 1 from MBean
|
||||||
*/
|
*/
|
||||||
Assert.assertEquals("attribute count does not match", 7, info.getAttributes().length);
|
Assert.assertEquals("attribute count does not match", 8, info.getAttributes().length);
|
||||||
|
|
||||||
Assert.assertEquals("attribute values does not match", "Full Name", mbean.getAttribute("fname") );
|
Assert.assertEquals("attribute values does not match", "Full Name", mbean.getAttribute("fname") );
|
||||||
|
|
||||||
Assert.assertEquals("operation count does not match", 4, info.getOperations().length);
|
//mbean.setAttribute( new Attribute("fname","Fuller Name"));
|
||||||
|
|
||||||
|
//Assert.assertEquals("set attribute value does not match", "Fuller Name", mbean.getAttribute("fname") );
|
||||||
|
|
||||||
|
Assert.assertEquals("proxy attribute values do not match", "goop", mbean.getAttribute("goop") );
|
||||||
|
|
||||||
|
Assert.assertEquals("operation count does not match", 5, info.getOperations().length);
|
||||||
|
|
||||||
MBeanOperationInfo[] opinfos = info.getOperations();
|
MBeanOperationInfo[] opinfos = info.getOperations();
|
||||||
boolean publish = false;
|
boolean publish = false;
|
||||||
|
@ -94,17 +104,16 @@ public class ObjectMBeanTest
|
||||||
|
|
||||||
if ("good".equals(opinfo.getName()))
|
if ("good".equals(opinfo.getName()))
|
||||||
{
|
{
|
||||||
doodle = true;
|
good = true;
|
||||||
|
|
||||||
Assert.assertEquals("description does not match", "test of proxy", opinfo.getDescription());
|
|
||||||
Assert.assertEquals("execution contexts wrong", "not bad", mbean.invoke("good", new Object[] {}, new String[] {}));
|
|
||||||
|
|
||||||
|
Assert.assertEquals("description does not match", "test of proxy operations", opinfo.getDescription());
|
||||||
|
Assert.assertEquals("execution contexts wrong", "not bad", mbean.invoke("good", new Object[] {}, new String[] {}));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Assert.assertTrue("publish operation was not not found", publish);
|
Assert.assertTrue("publish operation was not not found", publish);
|
||||||
Assert.assertTrue("doodle operation was not not found", doodle);
|
Assert.assertTrue("doodle operation was not not found", doodle);
|
||||||
// Assert.assertTrue("good operation was not not found", good); not wired up yet
|
Assert.assertTrue("good operation was not not found", good);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,7 @@ import org.eclipse.jetty.server.Server;
|
||||||
import org.eclipse.jetty.server.handler.AbstractHandler;
|
import org.eclipse.jetty.server.handler.AbstractHandler;
|
||||||
import org.eclipse.jetty.server.handler.AbstractHandlerContainer;
|
import org.eclipse.jetty.server.handler.AbstractHandlerContainer;
|
||||||
import org.eclipse.jetty.server.handler.ContextHandler;
|
import org.eclipse.jetty.server.handler.ContextHandler;
|
||||||
|
import org.eclipse.jetty.util.annotation.Name;
|
||||||
import org.eclipse.jetty.util.log.Log;
|
import org.eclipse.jetty.util.log.Log;
|
||||||
import org.eclipse.jetty.util.log.Logger;
|
import org.eclipse.jetty.util.log.Logger;
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,7 @@ import java.lang.annotation.Retention;
|
||||||
import java.lang.annotation.RetentionPolicy;
|
import java.lang.annotation.RetentionPolicy;
|
||||||
import java.lang.annotation.Target;
|
import java.lang.annotation.Target;
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
@Documented
|
@Documented
|
||||||
@Target( { ElementType.TYPE, ElementType.METHOD, ElementType.FIELD } )
|
@Target( { ElementType.TYPE, ElementType.METHOD, ElementType.FIELD } )
|
||||||
|
|
|
@ -30,4 +30,5 @@ public @interface ManagedObject
|
||||||
*/
|
*/
|
||||||
String value() default "Not Specified";
|
String value() default "Not Specified";
|
||||||
|
|
||||||
|
String wrapper() default "";
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,4 +42,18 @@ public @interface ManagedOperation
|
||||||
*/
|
*/
|
||||||
String impact() default "UNKNOWN";
|
String impact() default "UNKNOWN";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Is the managed field itself a Managed Object?
|
||||||
|
*
|
||||||
|
* @return true if the target is a Managed Object
|
||||||
|
*/
|
||||||
|
boolean managed() default false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Does the managed field exist on a proxy object?
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @return true if a proxy object is involved
|
||||||
|
*/
|
||||||
|
boolean proxied() default false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,8 @@ package org.eclipse.jetty.util.component;
|
||||||
|
|
||||||
import java.util.concurrent.CopyOnWriteArrayList;
|
import java.util.concurrent.CopyOnWriteArrayList;
|
||||||
|
|
||||||
import org.eclipse.jetty.util.annotation.Managed;
|
import org.eclipse.jetty.util.annotation.ManagedAttribute;
|
||||||
|
import org.eclipse.jetty.util.annotation.ManagedObject;
|
||||||
import org.eclipse.jetty.util.log.Log;
|
import org.eclipse.jetty.util.log.Log;
|
||||||
import org.eclipse.jetty.util.log.Logger;
|
import org.eclipse.jetty.util.log.Logger;
|
||||||
|
|
||||||
|
@ -24,22 +25,22 @@ import org.eclipse.jetty.util.log.Logger;
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@Managed("Abstract Implementation of LifeCycle")
|
@ManagedObject("Abstract Implementation of LifeCycle")
|
||||||
public abstract class AbstractLifeCycle implements LifeCycle
|
public abstract class AbstractLifeCycle implements LifeCycle
|
||||||
{
|
{
|
||||||
private static final Logger LOG = Log.getLogger(AbstractLifeCycle.class);
|
private static final Logger LOG = Log.getLogger(AbstractLifeCycle.class);
|
||||||
|
|
||||||
@Managed(value="instance is stopped", readonly=true, getter="isStopped")
|
@ManagedAttribute(value="instance is stopped", readonly=true, getter="isStopped")
|
||||||
public static final String STOPPED="STOPPED";
|
public static final String STOPPED="STOPPED";
|
||||||
@Managed(value="instance is failed", readonly=true, getter="isFailed")
|
@ManagedAttribute(value="instance is failed", readonly=true, getter="isFailed")
|
||||||
public static final String FAILED="FAILED";
|
public static final String FAILED="FAILED";
|
||||||
@Managed(value="instance is starting", readonly=true, getter="isStarting")
|
@ManagedAttribute(value="instance is starting", readonly=true, getter="isStarting")
|
||||||
public static final String STARTING="STARTING";
|
public static final String STARTING="STARTING";
|
||||||
@Managed(value="instance is started", readonly=true, getter="isStarted")
|
@ManagedAttribute(value="instance is started", readonly=true, getter="isStarted")
|
||||||
public static final String STARTED="STARTED";
|
public static final String STARTED="STARTED";
|
||||||
@Managed(value="instance is stopping", readonly=true, getter="isStopping")
|
@ManagedAttribute(value="instance is stopping", readonly=true, getter="isStopping")
|
||||||
public static final String STOPPING="STOPPING";
|
public static final String STOPPING="STOPPING";
|
||||||
@Managed(value="instance is running", readonly=true, getter="isRunning")
|
@ManagedAttribute(value="instance is running", readonly=true, getter="isRunning")
|
||||||
public static final String RUNNING="RUNNING";
|
public static final String RUNNING="RUNNING";
|
||||||
|
|
||||||
private final CopyOnWriteArrayList<LifeCycle.Listener> _listeners=new CopyOnWriteArrayList<LifeCycle.Listener>();
|
private final CopyOnWriteArrayList<LifeCycle.Listener> _listeners=new CopyOnWriteArrayList<LifeCycle.Listener>();
|
||||||
|
|
|
@ -15,7 +15,8 @@ package org.eclipse.jetty.util.component;
|
||||||
|
|
||||||
import java.util.EventListener;
|
import java.util.EventListener;
|
||||||
|
|
||||||
import org.eclipse.jetty.util.annotation.Managed;
|
import org.eclipse.jetty.util.annotation.ManagedObject;
|
||||||
|
import org.eclipse.jetty.util.annotation.ManagedOperation;
|
||||||
|
|
||||||
/* ------------------------------------------------------------ */
|
/* ------------------------------------------------------------ */
|
||||||
/**
|
/**
|
||||||
|
@ -26,7 +27,7 @@ import org.eclipse.jetty.util.annotation.Managed;
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@Managed("Lifecycle Interface for startable components")
|
@ManagedObject("Lifecycle Interface for startable components")
|
||||||
public interface LifeCycle
|
public interface LifeCycle
|
||||||
{
|
{
|
||||||
/* ------------------------------------------------------------ */
|
/* ------------------------------------------------------------ */
|
||||||
|
@ -37,7 +38,7 @@ public interface LifeCycle
|
||||||
* @see #stop()
|
* @see #stop()
|
||||||
* @see #isFailed()
|
* @see #isFailed()
|
||||||
*/
|
*/
|
||||||
@Managed("Starts the instance")
|
@ManagedOperation("Starts the instance")
|
||||||
public void start()
|
public void start()
|
||||||
throws Exception;
|
throws Exception;
|
||||||
|
|
||||||
|
@ -51,7 +52,7 @@ public interface LifeCycle
|
||||||
* @see #start()
|
* @see #start()
|
||||||
* @see #isFailed()
|
* @see #isFailed()
|
||||||
*/
|
*/
|
||||||
@Managed("Stops the instance")
|
@ManagedOperation("Stops the instance")
|
||||||
public void stop()
|
public void stop()
|
||||||
throws Exception;
|
throws Exception;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue