User: juhalindfors
Date: 02/03/01 07:52:59
Modified: src/main/org/jboss/mx/capability
OptimizedMBeanDispatcher.java
Added: src/main/org/jboss/mx/capability DispatchClassLoader.java
Log:
all the class mungling done in-memory
Revision Changes Path
1.2 +39 -22
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.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- OptimizedMBeanDispatcher.java 28 Feb 2002 19:58:14 -0000 1.1
+++ OptimizedMBeanDispatcher.java 1 Mar 2002 15:52:59 -0000 1.2
@@ -16,7 +16,9 @@
import java.util.Iterator;
import java.util.List;
-import java.io.File;
+import java.io.ByteArrayOutputStream;
+import java.io.BufferedOutputStream;
+
import java.net.URL;
import java.net.URLClassLoader;
@@ -77,12 +79,19 @@
/**
- * Byte code optimized dispatcher for Standard MBeans.
+ * Byte code optimized dispatcher for Standard MBeans. This dispatcher generates
+ * an invoke implementation that handles the operation dispatching without
+ * Java reflection.<p>
+ *
+ * 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.
*
* @see org.jboss.mx.capability.ReflectedMBeanDispatcher
+ * @see org.jboss.mx.capability.DispatchClassLoader
*
* @author <a href="mailto:[EMAIL PROTECTED]">Juha Lindfors</a>.
- * @version $Revision: 1.1 $
+ * @version $Revision: 1.2 $
*
*/
public class OptimizedMBeanDispatcher
@@ -96,16 +105,6 @@
{
try
{
- // FIXME: just a hack for now, we shouldnt use the file system,
- // instead create a custom cl for the generated class and feed
- // the byte stream directly
- //
- // ALSO NOTICE if youre editing the code that creates byte codes to
- // 'build clobber' before you run test to delete the existing classes.
- // Otherwise the system classloader will pick up the classes generated
- // from the previous run
-
-
// construct class template
String className = resource.getClass().getName().replace('.', '_') +
"_Dispatcher";
String superClass = SUPER_CLASS.getName();
@@ -122,8 +121,18 @@
JavaClass c = clazz.getJavaClass();
- File file = new File("output\\classes\\" + fileName);
- c.dump(file);
+ 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(
@@ -220,6 +229,14 @@
else return "L" +
name.replace('.', '/') + ";";
}
+ /**
+ * 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()
+ * @return true if is a primitive type name; false otherwise
+ */
public static boolean isPrimitive(String name)
{
if (name.equals(Byte.TYPE.getName()) ||
@@ -338,10 +355,11 @@
int invokeIndex = cp.addMethodref(
SUPER_CLASS.getName(),
"invoke",
- "(L" + String.class.getName().replace('.', '/') + ";"
- + Object[].class.getName().replace('.', '/')
- + String[].class.getName().replace('.', '/') + ")L"
- + Object.class.getName().replace('.', '/') + ";"
+ "(" + getDescriptorForType(String.class.getName())
+ + getDescriptorForType(Object[].class.getName())
+ + getDescriptorForType(String[].class.getName())
+ +
+ ")" + getDescriptorForType(Object.class.getName())
);
int getResourceObjectIndex = cp.addMethodref(
@@ -353,8 +371,7 @@
int strEqualsIndex = cp.addMethodref(
String.class.getName(),
"equals",
- "(L" + Object.class.getName().replace('.', '/') + ";)"
- + "Z"
+ "(Ljava/lang/Object;)Z"
);
InstructionHandle beginTryBlock = null;
@@ -527,7 +544,7 @@
}
/**
- * Converts a reference to a primitve wrapper object into a primite value type.
+ * 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
* top of the operand stack. The stack is modified so that the object reference
* to a primitive wrapper is replaced by the corresponding value in the stack.
1.1 jmx/src/main/org/jboss/mx/capability/DispatchClassLoader.java
Index: DispatchClassLoader.java
===================================================================
/*
* JBoss, the OpenSource J2EE webOS
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package org.jboss.mx.capability;
/**
* <description>
*
* @see <related>
*
* @author <a href="mailto:[EMAIL PROTECTED]">Juha Lindfors</a>.
* @version $Revision: 1.1 $
*
*/
public class DispatchClassLoader extends ClassLoader
{
// Attributes ----------------------------------------------------
private String name = null;
private byte[] code = null;
// Constructors --------------------------------------------------
DispatchClassLoader(ClassLoader parent, String name, byte[] bytecode)
{
super(parent);
this.name = name;
this.code = bytecode;
}
DispatchClassLoader(String name, byte[] bytecode)
{
super();
this.name = name;
this.code = bytecode;
}
// Protected -----------------------------------------------------
protected Class findClass(String name) throws ClassNotFoundException
{
if (!name.equals(this.name))
throw new ClassNotFoundException("Class not found: " + name + "(I'm a
dispatch loader, I only know " + this.name + ")");
return defineClass(name, code, 0, code.length);
}
}
_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development