User: squirest
Date: 02/03/07 16:41:36
Modified: src/main/org/jboss/mx/capability DispatcherFactory.java
OptimizedMBeanDispatcher.java
ReflectedMBeanDispatcher.java
Removed: src/main/org/jboss/mx/capability
AbstractInvocationDispatcher.java
DynamicMBeanDispatcher.java MBeanDelegate.java
ResourceDelegate.java ResourceInvoker.java
Log:
added interceptor to route ModelMBean invocations to a dispatcher
removed all irrelevant code not compatible with accepted strategy for interceptors
Revision Changes Path
1.3 +49 -22 jmx/src/main/org/jboss/mx/capability/DispatcherFactory.java
Index: DispatcherFactory.java
===================================================================
RCS file:
/cvsroot/jboss/jmx/src/main/org/jboss/mx/capability/DispatcherFactory.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- DispatcherFactory.java 28 Feb 2002 20:00:54 -0000 1.2
+++ DispatcherFactory.java 8 Mar 2002 00:41:36 -0000 1.3
@@ -7,7 +7,7 @@
package org.jboss.mx.capability;
-import org.jboss.mx.metadata.AOResolver;
+import org.jboss.mx.metadata.AttributeOperationResolver;
import org.jboss.mx.metadata.MethodMapper;
import org.jboss.mx.server.ServerConstants;
@@ -17,6 +17,8 @@
import javax.management.MBeanAttributeInfo;
import javax.management.MBeanInfo;
import javax.management.MBeanOperationInfo;
+import javax.management.Descriptor;
+import javax.management.modelmbean.ModelMBeanAttributeInfo;
import java.lang.reflect.Method;
/**
@@ -28,27 +30,20 @@
public class DispatcherFactory
implements ServerConstants
{
- /**
- * Creates a Dispatcher for a DynamicMBean
- */
- public static MBeanDelegate create(DynamicMBean mbean)
- {
- return new DynamicMBeanDispatcher(mbean);
- }
/**
* Creates a Dispatcher for an arbitrary resource. Useful for when you don't
care
- * about the AOResolver.
+ * about the AttributeOperationResolver.
*/
- public static MBeanDelegate create(MBeanInfo info, Object resource) throws
IntrospectionException
+ public static DynamicMBean create(MBeanInfo info, Object resource) throws
IntrospectionException
{
- return create(info, resource, new AOResolver(info));
+ return create(info, resource, new AttributeOperationResolver(info));
}
/**
- * Creates a dispatcher for an arbitrary resource using the named AOResolver.
+ * Creates a dispatcher for an arbitrary resource using the named
AttributeOperationResolver.
*/
- public static MBeanDelegate create(MBeanInfo info, Object resource, AOResolver
resolver) throws IntrospectionException
+ public static DynamicMBean create(MBeanInfo info, Object resource,
AttributeOperationResolver resolver) throws IntrospectionException
{
if (null == info)
{
@@ -67,14 +62,14 @@
MethodMapper mmap = new MethodMapper(resource.getClass());
ReflectedMBeanDispatcher dispatcher = new ReflectedMBeanDispatcher(info,
resolver, resource);
-
+
if (System.getProperty(OPTIMIZE_REFLECTED_DISPATCHER,
"false").equalsIgnoreCase("true"))
{
// FIXME: subclassing for now so I can rely on the reflection based
implementation for the parts
- // that aren't implemented yet
+ // that aren't implemented yet
dispatcher = OptimizedMBeanDispatcher.create(info, resource /*, parent
classloader */);
}
-
+
MBeanAttributeInfo[] attributes = info.getAttributes();
for (int i = 0; i < attributes.length; i++)
{
@@ -84,19 +79,51 @@
if (attribute.isReadable())
{
- getter = mmap.lookupGetter(attribute);
- if (getter == null)
+ if (attribute instanceof ModelMBeanAttributeInfo)
+ {
+ ModelMBeanAttributeInfo mmbAttribute = (ModelMBeanAttributeInfo)
attribute;
+ Descriptor desc = mmbAttribute.getDescriptor();
+ if (desc != null && desc.getFieldValue("getMethod") != null)
+ {
+ getter = mmap.lookupGetter(mmbAttribute);
+ if (getter == null)
+ {
+ throw new IntrospectionException("no getter method found for
attribute: " + attribute.getName());
+ }
+ }
+ }
+ else
{
- throw new IntrospectionException("no getter method found for
attribute: " + attribute.getName());
+ getter = mmap.lookupGetter(attribute);
+ if (getter == null)
+ {
+ throw new IntrospectionException("no getter method found for
attribute: " + attribute.getName());
+ }
}
}
if (attribute.isWritable())
{
- setter = mmap.lookupSetter(attribute);
- if (setter == null)
+ if (attribute instanceof ModelMBeanAttributeInfo)
+ {
+ ModelMBeanAttributeInfo mmbAttribute = (ModelMBeanAttributeInfo)
attribute;
+ Descriptor desc = mmbAttribute.getDescriptor();
+ if (desc != null && desc.getFieldValue("setMethod") != null)
+ {
+ setter = mmap.lookupGetter(mmbAttribute);
+ if (setter == null)
+ {
+ throw new IntrospectionException("no setter method found for
attribute: " + attribute.getName());
+ }
+ }
+ }
+ else
{
- throw new IntrospectionException("no setter method found for
attribute: " + attribute.getName());
+ setter = mmap.lookupSetter(attribute);
+ if (setter == null)
+ {
+ throw new IntrospectionException("no setter method found for
attribute: " + attribute.getName());
+ }
}
}
1.3 +121 -121
jmx/src/main/org/jboss/mx/capability/OptimizedMBeanDispatcher.java
Index: OptimizedMBeanDispatcher.java
===================================================================
RCS file:
/cvsroot/jboss/jmx/src/main/org/jboss/mx/capability/OptimizedMBeanDispatcher.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- OptimizedMBeanDispatcher.java 1 Mar 2002 15:52:59 -0000 1.2
+++ OptimizedMBeanDispatcher.java 8 Mar 2002 00:41:36 -0000 1.3
@@ -75,7 +75,7 @@
import org.jboss.mx.loading.LoaderRepository;
-import org.jboss.mx.metadata.AOResolver;
+import org.jboss.mx.metadata.AttributeOperationResolver;
/**
@@ -83,7 +83,7 @@
* an invoke implementation that handles the operation dispatching without
* Java reflection.<p>
*
- * The use of this dispatcher may be controlled by setting a
+ * The use of this dispatcher may be controlled by setting a
* {@link org.jboss.mx.server.ServerConstants#OPTIMIZE_REFLECTED_DISPATCHER
OPTIMIZE_REFLECTED_DISPATCHER}
* property to either <tt>"true"</tt> or <tt>"false"</tt> string value.
*
@@ -91,15 +91,15 @@
* @see org.jboss.mx.capability.DispatchClassLoader
*
* @author <a href="mailto:[EMAIL PROTECTED]">Juha Lindfors</a>.
- * @version $Revision: 1.2 $
- *
+ * @version $Revision: 1.3 $
+ *
*/
public class OptimizedMBeanDispatcher
{
// Constants -----------------------------------------------------
final static Class SUPER_CLASS = ReflectedMBeanDispatcher.class;
-
-
+
+
// Static --------------------------------------------------------
public static ReflectedMBeanDispatcher create(MBeanInfo info, Object resource)
{
@@ -111,35 +111,35 @@
String fileName = className + ".class";
int modifiers = Constants.ACC_PUBLIC;
String[] interfaces = new String[0];
-
+
ClassGen clazz = new ClassGen(className, superClass, fileName,
modifiers, interfaces);
ConstantPoolGen cp = clazz.getConstantPool();
-
+
clazz.addMethod(createConstructor(cp, className).getMethod());
clazz.addMethod(createInvoke(cp, info, className,
resource.getClass().getName()).getMethod());
clazz.update();
-
+
JavaClass c = clazz.getJavaClass();
-
+
ByteArrayOutputStream baos = new ByteArrayOutputStream(2000);
BufferedOutputStream bos = new BufferedOutputStream(baos);
c.dump(bos);
-
+
LoaderRepository rep = LoaderRepository.getDefaultLoaderRepository();
-
+
// FIXME: what about ctx cl?
// FIXME: also I dont know if the parent is right here, have to check later
DispatchClassLoader dcl = new
DispatchClassLoader(resource.getClass().getClassLoader(), className,
baos.toByteArray());
rep.addClassLoader(dcl);
-
+
// FIXME: throw the DLC away when an MBean is unregistered!
-
+
Class dispatcherClass = DefaultLoaderRepository.loadClass(className);
Constructor constr = dispatcherClass.getConstructor(
- new Class[] { MBeanInfo.class, AOResolver.class, Object.class }
+ new Class[] { MBeanInfo.class, AttributeOperationResolver.class,
Object.class }
);
-
- Object o = constr.newInstance(new Object[] { info, new AOResolver(info),
resource });
+
+ Object o = constr.newInstance(new Object[] { info, new
AttributeOperationResolver(info), resource });
return (ReflectedMBeanDispatcher)o;
}
@@ -149,7 +149,7 @@
throw new Error();
}
}
-
+
/**
* Returns the signature of a MBean operation using the grammar required by
* the class file format, excluding the method name. <p>
@@ -159,7 +159,7 @@
* A method descriptor represents the parameters that the method takes and the
value that it returns: <br><i><pre>
*
* MethodDescriptor:
- * ( ParameterDescriptor* ) ReturnDescriptor
+ * ( ParameterDescriptor* ) ReturnDescriptor
* </pre></i>
*
* A parameter descriptor represents a parameter passed to a method:
<br><i><pre>
@@ -189,15 +189,15 @@
*/
public static String getMethodDescriptor(MBeanParameterInfo[] signature, String
returnType)
{
-
+
StringBuffer sign = new StringBuffer(256);
sign.append("(");
-
+
for (int i = 0; i < signature.length; ++i)
sign.append(getDescriptorForType(signature[i].getName()));
sign.append(")" + getDescriptorForType(returnType));
-
+
return sign.toString();
}
@@ -231,7 +231,7 @@
/**
* Checks if a given name matches the <tt>TYPE</tt> name of a primitive wrapper
class.
- *
+ *
* @see java.lang.Integer#TYPE
*
* @param name TYPE.getName()
@@ -247,49 +247,49 @@
name.equals(Long.TYPE.getName()) ||
name.equals(Short.TYPE.getName()) ||
name.equals(Boolean.TYPE.getName()))
-
+
return true;
-
+
return false;
}
-
-
-
+
+
+
// Protected -----------------------------------------------------
-
+
/**
- * creates constructor <tt><init>(MBeanInfo info, AOResolver resolver,
Object resource)</tt>
+ * creates constructor <tt><init>(MBeanInfo info,
AttributeOperationResolver resolver, Object resource)</tt>
* that calls <tt>super(info, resolver, resource)</tt> in its implementation
*
* @param cp constant pool
* @param className name of the class being generated
*/
protected static MethodGen createConstructor(ConstantPoolGen cp, String
className)
- {
+ {
InstructionList constrInstructions = new InstructionList();
-
+
int constrRefIndex = cp.addMethodref(
SUPER_CLASS.getName(),
- "<init>",
+ "<init>",
"(" + getDescriptorForType(MBeanInfo.class.getName())
- + getDescriptorForType(AOResolver.class.getName())
+ + getDescriptorForType(AttributeOperationResolver.class.getName())
+ getDescriptorForType(Object.class.getName())
+ ")V"
);
-
+
constrInstructions.append(new ALOAD(0)); //
Stack: => ..., this
constrInstructions.append(new ALOAD(1)); //
Stack: => ..., this, arg1 [MBeanInfo]
- constrInstructions.append(new ALOAD(2)); //
Stack: => ..., this, arg1 [MBeanInfo], arg2 [AOResolver]
- constrInstructions.append(new ALOAD(3)); //
Stack: => ..., this, arg1 [MBeanInfo], arg2 [AOResolver], arg3 [Object]
+ constrInstructions.append(new ALOAD(2)); //
Stack: => ..., this, arg1 [MBeanInfo], arg2 [AttributeOperationResolver]
+ constrInstructions.append(new ALOAD(3)); //
Stack: => ..., this, arg1 [MBeanInfo], arg2 [AttributeOperationResolver], arg3
[Object]
constrInstructions.append(new INVOKESPECIAL(constrRefIndex)); //
Stack: => ...
constrInstructions.append(new RETURN()); //
Stack: => <empty>
-
+
MethodGen constrMethod = new MethodGen(
Constants.ACC_PUBLIC,
Type.VOID,
- new Type[] {
+ new Type[] {
new ObjectType(MBeanInfo.class.getName()),
- new ObjectType(AOResolver.class.getName()),
+ new ObjectType(AttributeOperationResolver.class.getName()),
new ObjectType(Object.class.getName()) },
new String[] { "info", "resolver", "resource" },
"<init>",
@@ -340,7 +340,7 @@
{
InstructionList invokeInstructions = new InstructionList();
MethodEntry[] operations = getOperations(info);
-
+
// load operation name strings and methods to constant pool
for (int i = 0; i < operations.length; ++i) {
operations[i].nameIndexInCP = cp.addString(operations[i].getName());
@@ -349,14 +349,14 @@
operations[i].getName(),
operations[i].methodDescriptor
);
- }
-
-
+ }
+
+
int invokeIndex = cp.addMethodref(
SUPER_CLASS.getName(),
"invoke",
- "(" + getDescriptorForType(String.class.getName())
- + getDescriptorForType(Object[].class.getName())
+ "(" + getDescriptorForType(String.class.getName())
+ + getDescriptorForType(Object[].class.getName())
+ getDescriptorForType(String[].class.getName())
+
")" + getDescriptorForType(Object.class.getName())
@@ -376,18 +376,18 @@
InstructionHandle beginTryBlock = null;
InstructionHandle endTryBlock = null;
-
+
IFNULL ifOperationEqualsNull = new IFNULL(null);
IFEQ operationElseIfBranch = null;
-
+
if (operations.length > 0)
{
//
// if (actionName != null)
//
invokeInstructions.append(new ALOAD(1));
// Stack: => ..., arg1 [String]
-
- beginTryBlock =
+
+ beginTryBlock =
invokeInstructions.append(ifOperationEqualsNull);
// Stack: => ...
for (int i = 0; i < operations.length; ++i)
@@ -395,28 +395,28 @@
//
// if (actionName.equals(operations[i].getName());
//
- InstructionHandle jumpToNextElse =
+ InstructionHandle jumpToNextElse =
invokeInstructions.append(new ALOAD(1));
// Stack: => ..., arg1 [String]
- invokeInstructions.append(new LDC(operations[i].nameIndexInCP));
// Stack: => ..., opName [String]
+ invokeInstructions.append(new LDC(operations[i].nameIndexInCP));
// Stack: => ..., opName [String]
invokeInstructions.append(new INVOKEVIRTUAL(strEqualsIndex));
// Stack: => ..., 0 | 1 [boolean]
// set the jump target for previous else if branch
if (operationElseIfBranch != null)
operationElseIfBranch.setTarget(jumpToNextElse);
-
+
operationElseIfBranch = new IFEQ(null);
invokeInstructions.append(operationElseIfBranch);
// Stack: => ...
invokeInstructions.append(new ALOAD(0));
// Stack: => ..., this
invokeInstructions.append(new INVOKEVIRTUAL(getResourceObjectIndex));
// Stack: => ..., resource [Object]
-
+
int x = cp.addClass(resourceClassName);
invokeInstructions.append(new CHECKCAST(x));
// Stack: => ..., resource [<resource object type>]
-
+
// if invocation has args, we need to push them into stack
if (operations[i].getSignature().length > 0)
{
-
+
for (int arrayIndex = 0; arrayIndex <
operations[i].getSignature().length; ++arrayIndex)
{
invokeInstructions.append(new ALOAD(2));
// Stack: => ..., resource [<type>], arg2 [Object[]]
@@ -426,33 +426,33 @@
// Args come in as objects. If signature has a primitive type
// we need to convert the arg before we can invoke the operation
String type = operations[i].getSignature() [arrayIndex].getName();
-
+
if (isPrimitive(type))
invokeInstructions.append(convertObjectToPrimitive(cp, type));
// Stack: => ..., resource[<type>], value [<primitive>]
-
+
else
{
x = cp.addClass(type);
- invokeInstructions.append(new CHECKCAST(x));
// Stack: => ..., resource[<type>], value [<reference>]
+ invokeInstructions.append(new CHECKCAST(x));
// Stack: => ..., resource[<type>], value [<reference>]
}
}
}
-
+
//
// resource.<operation>(<arg 1, ... arg n>)
//
x = operations[i].methodIndexInCP;
invokeInstructions.append(new INVOKEVIRTUAL(x));
// Stack: => ..., returnvalue
-
+
// Wrap primitive return values into their corresponding wrapper objects
String type = operations[i].getReturnType();
-
+
if (isPrimitive(type))
{
- invokeInstructions.append(convertPrimitiveToObject(cp, type));
// Stack: => ..., objectref [wrapper]
+ invokeInstructions.append(convertPrimitiveToObject(cp, type));
// Stack: => ..., objectref [wrapper]
invokeInstructions.append(new ARETURN());
// Stack: => <empty>
}
- else if (type.equals(Void.TYPE.getName()))
+ else if (type.equals(Void.TYPE.getName()))
{
invokeInstructions.append(new ACONST_NULL());
// Stack: => ..., null
invokeInstructions.append(new ARETURN());
// Stack: => <empty>
@@ -463,11 +463,11 @@
}
}
}
-
+
//
// super.invoke(actionName, args, signature) if no match was found
//
- InstructionHandle jumpToSuperInvoke =
+ InstructionHandle jumpToSuperInvoke =
invokeInstructions.append(new ALOAD(0));
// Stack: => ..., this
invokeInstructions.append(new ALOAD(1));
// Stack: => ..., this, arg1 [String]
invokeInstructions.append(new ALOAD(2));
// Stack: => ..., this, arg1 [String], arg2 [Object[]]
@@ -477,7 +477,7 @@
// set the jump targets
ifOperationEqualsNull.setTarget(jumpToSuperInvoke);
-
+
if (operations.length > 0)
{
// set the last else branch to call super.invoke
@@ -492,23 +492,23 @@
// exception handler (it's a cheap shot -- if there is any exception,
re-invoke
// on super class and let it handle all exceptions)
- InstructionHandle exceptionHandlerCode =
+ InstructionHandle exceptionHandlerCode =
invokeInstructions.append(new ALOAD(0));
invokeInstructions.append(new ALOAD(1));
invokeInstructions.append(new ALOAD(2));
invokeInstructions.append(new ALOAD(3));
invokeInstructions.append(new INVOKESPECIAL(invokeIndex));
invokeInstructions.append(new ARETURN());
-
+
MethodGen invokeMethod = new MethodGen(
Constants.ACC_PUBLIC,
Type.OBJECT,
- new Type[] {
+ new Type[] {
Type.STRING,
new ArrayType(Object.class.getName(), 1),
new ArrayType(String.class.getName(), 1)
},
- new String[] {
+ new String[] {
"operationName",
"args",
"signature"
@@ -518,22 +518,22 @@
);
invokeMethod.setMaxLocals(7);
invokeMethod.setMaxStack(calculateMaxStackSize(info));
-
+
invokeMethod.addException(ReflectionException.class.getName());
invokeMethod.addException(MBeanException.class.getName());
-
+
if (operations.length > 0) {
invokeMethod.addExceptionHandler(beginTryBlock, endTryBlock,
exceptionHandlerCode, new ObjectType("java.lang.Throwable"));
}
-
+
return invokeMethod;
}
-
+
private static int calculateMaxStackSize(MBeanInfo info)
{
MBeanOperationInfo[] operations = info.getOperations();
int maxSize = 7;
-
+
for (int i = 0; i < operations.length; ++i)
{
if (operations[i].getSignature().length > maxSize + 2)
@@ -542,7 +542,7 @@
return maxSize;
}
-
+
/**
* Converts a reference of a primitve wrapper object into a primite value type.
* This method assumes that the wrapper object reference is already loaded at the
@@ -570,67 +570,67 @@
//
// Assumes the wrapper object reference is on top of the stack
//
-
+
if (type.equals(Integer.TYPE.getName()))
{
int x = cp.addClass("java.lang.Integer");
il.append(new CHECKCAST(x)); //
Stack: => ..., type [Integer]
- il.append(new INVOKEVIRTUAL(intValueIndex)); //
Stack: => ..., value [int]
+ il.append(new INVOKEVIRTUAL(intValueIndex)); //
Stack: => ..., value [int]
}
-
+
else if (type.equals(Byte.TYPE.getName()))
- {
+ {
int x = cp.addClass("java.lang.Byte");
il.append(new CHECKCAST(x)); //
Stack: => ..., type [Boolean]
il.append(new INVOKEVIRTUAL(byteValueIndex)); //
Stack: => ..., 0 | 1 [boolean]
}
-
+
else if (type.equals(Character.TYPE.getName()))
{
int x = cp.addClass("java.lang.Character");
il.append(new CHECKCAST(x)); //
Stack: => ..., type [Character]
il.append(new INVOKEVIRTUAL(charValueIndex)); //
Stack: => ..., value [char]
}
-
+
else if (type.equals(Double.TYPE.getName()))
{
int x = cp.addClass("java.lang.Double");
il.append(new CHECKCAST(x)); //
Stack: => ..., type [Double]
il.append(new INVOKEVIRTUAL(doubleValueIndex)); //
Stack: => ..., value [double]
}
-
+
else if (type.equals(Float.TYPE.getName()))
{
int x = cp.addClass("java.lang.Float");
il.append(new CHECKCAST(x)); //
Stack: => ..., type [Float]
il.append(new INVOKEVIRTUAL(floatValueIndex)); //
Stack: => ..., value [float]
}
-
+
else if (type.equals(Long.TYPE.getName()))
{
int x = cp.addClass("java.lang.Long");
il.append(new CHECKCAST(x)); //
Stack: => ..., type [Long]
il.append(new INVOKEVIRTUAL(longValueIndex)); //
Stack: => ..., value [long]
}
-
+
else if (type.equals(Short.TYPE.getName()))
{
int x = cp.addClass("java.lang.Short");
il.append(new CHECKCAST(x)); //
Stack: => ..., type [Short]
il.append(new INVOKEVIRTUAL(shortValueIndex)); //
Stack: => ..., value [short]
}
-
+
else if (type.equals(Boolean.TYPE.getName()))
{
int x = cp.addClass("java.lang.Boolean");
il.append(new CHECKCAST(x)); //
Stack: => ..., type [Boolean]
il.append(new INVOKEVIRTUAL(booleanValueIndex)); //
Stack: => ..., value [boolean]
}
-
+
return il;
}
-
-
+
+
/**
* Converts a primitive into its corresponding object wrapper reference.
* This method assumes the primitve is already pushed to the top of the operand
@@ -646,12 +646,12 @@
protected static InstructionList convertPrimitiveToObject(ConstantPoolGen cp,
String type)
{
InstructionList il = new InstructionList();
-
+
if (type.equals(Boolean.TYPE.getName()))
{
int x = cp.addClass("java.lang.Boolean");
int constrIndex = cp.addMethodref("java.lang.Boolean", "<init>", "(B)V");
-
+
il.append(new ISTORE(4));
il.append(new NEW(x));
il.append(new ASTORE(5));
@@ -660,12 +660,12 @@
il.append(new INVOKESPECIAL(constrIndex));
il.append(new ALOAD(5));
}
-
+
else if (type.equals(Short.TYPE.getName()))
{
int x = cp.addClass("java.lang.Short");
int constrIndex = cp.addMethodref("java.lang.Short", "<init>", "(S)V");
-
+
il.append(new ISTORE(4));
il.append(new NEW(x));
il.append(new ASTORE(5));
@@ -674,12 +674,12 @@
il.append(new INVOKESPECIAL(constrIndex));
il.append(new ALOAD(5));
}
-
+
else if (type.equals(Long.TYPE.getName()))
{
int x = cp.addClass("java.lang.Long");
int constrIndex = cp.addMethodref("java.lang.Long", "<init>", "(J)V");
-
+
il.append(new LSTORE(4));
il.append(new NEW(x));
il.append(new ASTORE(6));
@@ -688,12 +688,12 @@
il.append(new INVOKESPECIAL(constrIndex));
il.append(new ALOAD(6));
}
-
+
else if (type.equals(Integer.TYPE.getName()))
{
int x = cp.addClass("java.lang.Integer");
int constrIndex = cp.addMethodref("java.lang.Integer", "<init>", "(I)V");
-
+
il.append(new ISTORE(4));
il.append(new NEW(x));
il.append(new ASTORE(5));
@@ -702,12 +702,12 @@
il.append(new INVOKESPECIAL(constrIndex));
il.append(new ALOAD(5));
}
-
+
else if (type.equals(Float.TYPE.getName()))
{
int x = cp.addClass("java.lang.Float");
int constrIndex = cp.addMethodref("java.lang.Float", "<init>", "(F)V");
-
+
il.append(new FSTORE(4));
il.append(new NEW(x));
il.append(new ASTORE(5));
@@ -716,12 +716,12 @@
il.append(new INVOKESPECIAL(constrIndex));
il.append(new ALOAD(5));
}
-
+
else if (type.equals(Double.TYPE.getName()))
{
int x = cp.addClass("java.lang.Double");
int constrIndex = cp.addMethodref("java.lang.Double", "<init>", "(D)V");
-
+
il.append(new DSTORE(4));
il.append(new NEW(x));
il.append(new ASTORE(6));
@@ -730,12 +730,12 @@
il.append(new INVOKESPECIAL(constrIndex));
il.append(new ALOAD(6));
}
-
+
else if (type.equals(Character.TYPE.getName()))
{
int x = cp.addClass("java.lang.Character");
int constrIndex = cp.addMethodref("java.lang.Character", "<init>", "(C)V");
-
+
il.append(new ISTORE(4));
il.append(new NEW(x));
il.append(new ASTORE(5));
@@ -744,12 +744,12 @@
il.append(new INVOKESPECIAL(constrIndex));
il.append(new ALOAD(5));
}
-
+
else if (type.equals(Byte.TYPE.getName()))
{
int x = cp.addClass("java.lang.Byte");
int constrIndex = cp.addMethodref("java.lang.Byte", "<init>", "(B)V");
-
+
il.append(new ISTORE(4));
il.append(new NEW(x));
il.append(new ASTORE(5));
@@ -762,12 +762,12 @@
return il;
}
-
+
/**
* Returns a subset of MBean's operations. Overloaded operations are not
supported yet,
* so they're left out of the list and their invocations are delegated to the
reflection
* based super class. <p>
- *
+ *
* Overloaded operations that differ in their arg list length may be able to
gain in
* performance if implemented directly with byte code. Overloaded operations with
* equal arg list length may not show much difference compared to ternary search
tree
@@ -778,33 +778,33 @@
HashMap operationMap = new HashMap();
ArrayList overloadList = new ArrayList();
MBeanOperationInfo[] operations = info.getOperations();
-
+
for (int i = 0; i < operations.length; ++i)
{
String methodName = operations[i].getName();
-
+
if (operationMap.containsKey(methodName))
- overloadList.add(methodName);
+ overloadList.add(methodName);
else
operationMap.put(methodName, new MethodEntry(operations[i]));
- }
-
+ }
+
// method overloading not supported yet
Iterator it = overloadList.iterator();
while (it.hasNext())
operationMap.remove(it.next());
-
+
return (MethodEntry[])operationMap.values().toArray(new MethodEntry[0]);
}
-
-
- // Inner classes -------------------------------------------------
+
+
+ // Inner classes -------------------------------------------------
private static class MethodEntry extends MBeanOperationInfo {
-
+
String methodDescriptor = null;
int nameIndexInCP = -1;
int methodIndexInCP = -1;
-
+
public MethodEntry(MBeanOperationInfo info)
{
super(info.getName(), info.getDescription(), info.getSignature(),
info.getReturnType(), info.getImpact());
@@ -813,9 +813,9 @@
}
}
-
+
}
-
+
1.3 +10 -78
jmx/src/main/org/jboss/mx/capability/ReflectedMBeanDispatcher.java
Index: ReflectedMBeanDispatcher.java
===================================================================
RCS file:
/cvsroot/jboss/jmx/src/main/org/jboss/mx/capability/ReflectedMBeanDispatcher.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ReflectedMBeanDispatcher.java 28 Feb 2002 19:59:37 -0000 1.2
+++ ReflectedMBeanDispatcher.java 8 Mar 2002 00:41:36 -0000 1.3
@@ -7,23 +7,20 @@
package org.jboss.mx.capability;
-import org.jboss.mx.metadata.AOResolver;
+import org.jboss.mx.metadata.AttributeOperationResolver;
import javax.management.Attribute;
import javax.management.AttributeList;
import javax.management.AttributeNotFoundException;
+import javax.management.DynamicMBean;
import javax.management.InvalidAttributeValueException;
-import javax.management.ListenerNotFoundException;
import javax.management.MBeanAttributeInfo;
import javax.management.MBeanConstructorInfo;
import javax.management.MBeanException;
import javax.management.MBeanInfo;
import javax.management.MBeanNotificationInfo;
import javax.management.MBeanOperationInfo;
-import javax.management.Notification;
import javax.management.NotificationBroadcaster;
-import javax.management.NotificationFilter;
-import javax.management.NotificationListener;
import javax.management.ReflectionException;
import javax.management.RuntimeErrorException;
import javax.management.RuntimeMBeanException;
@@ -33,25 +30,17 @@
import java.util.Iterator;
/**
- * Directs MBean and ResourceInvoker calls to underlying resource via reflection.
- * It's suitable for use as a StandardMBean or as the resource for a ModelMBean.
- *
- * However, in the latter case the ModelMBean itself is expected to manage the
- * MBeanInfo. This makes sense when you consider that any cached attributes must
- * be returned in the ModelMBeanAttributeInfo descriptors anyhow.
- *
- * FIXME THS - currently this class only supports one resource object. I'm actually
- * expecting that JMX1.1 will remove support for multiple target objects from the
- * ModelMBean specification.
+ * Directs DynamicMBean calls to underlying resource via reflection. It's suitable
+ * for use as a StandardMBean or as the resource for a ModelMBean.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Trevor Squires</a>.
* @author <a href="mailto:[EMAIL PROTECTED]">Juha Lindfors</a>
*/
-public class ReflectedMBeanDispatcher extends AbstractInvocationDispatcher
+public class ReflectedMBeanDispatcher implements DynamicMBean
{
private Object resource = null;
- private AOResolver resolver = null;
+ private AttributeOperationResolver resolver = null;
private MBeanConstructorInfo[] constructorInfo = null;
private MBeanAttributeInfo[] attributeInfo = null;
private MBeanOperationInfo[] operationInfo = null;
@@ -60,12 +49,11 @@
private MethodPair[] attributes = null;
private boolean isBroadcaster = false;
- private boolean isListener = false;
private String resourceClassName = null;
private String resourceDescription = null;
- public ReflectedMBeanDispatcher(MBeanInfo mbinfo, AOResolver resolver, Object
resource)
+ public ReflectedMBeanDispatcher(MBeanInfo mbinfo, AttributeOperationResolver
resolver, Object resource)
{
if (null == resource)
{
@@ -88,11 +76,6 @@
this.isBroadcaster = true;
}
- if (resource instanceof NotificationListener)
- {
- this.isListener = true;
- }
-
this.resource = resource;
this.resolver = resolver;
this.resourceClassName = mbinfo.getClassName();
@@ -129,16 +112,6 @@
}
}
- public boolean resourceIsNotificationBroadcaster()
- {
- return isBroadcaster;
- }
-
- public boolean resourceIsNotificationListener()
- {
- return isListener;
- }
-
public String getResourceClassName()
{
return resourceClassName;
@@ -353,35 +326,8 @@
}
- public void addNotificationListener(NotificationListener listener,
- NotificationFilter filter,
- Object handback)
- throws IllegalArgumentException
- {
- if (isBroadcaster)
- {
- ((NotificationBroadcaster) resource).addNotificationListener(listener,
filter, handback);
- }
- else
- {
- throw new RuntimeOperationsException(new
UnsupportedOperationException("resource is not a NotificationBroadcaster"));
- }
- }
-
- public void removeNotificationListener(NotificationListener listener)
- throws ListenerNotFoundException
- {
- if (isBroadcaster)
- {
- ((NotificationBroadcaster) resource).removeNotificationListener(listener);
- }
- else
- {
- throw new RuntimeOperationsException(new
UnsupportedOperationException("resource is not a NotificationBroadcaster"));
- }
- }
-
- public MBeanNotificationInfo[] getNotificationInfo()
+ // Protected -----------------------------------------------------
+ protected MBeanNotificationInfo[] getNotificationInfo()
{
if (isBroadcaster)
{
@@ -393,25 +339,11 @@
}
}
- public void handleNotification(Notification notification,
- Object handback)
- {
- if (isListener)
- {
- ((NotificationListener) resource).handleNotification(notification,
handback);
- }
- else
- {
- throw new RuntimeOperationsException(new
UnsupportedOperationException("resource is not a NotificationListener"));
- }
- }
-
- // Protected -----------------------------------------------------
protected Object getResourceObject()
{
return resource;
}
-
+
// ONLY used for friendly exceptions!
protected final String opKeyString(String name, String[] signature)
{
_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development