User: fleury
Date: 00/06/04 16:19:02
Modified: src/main/org/jboss/ejb/plugins/jrmp/interfaces
HomeProxy.java MethodInvocation.java
StatefulSessionProxy.java
Log:
Digging out the Alien bug, I put the debug traces (I need to work from home tonight)
I will remove them as soon as it is done.
Note: the MethodInvocation code is fixed now there is something in the container as
well... (wrong number of arguments) something tells me that the lookup is the same and
still very screwed up ... we need to change the container ways of looking the methods
up.
It will speed it up (precalculate and dont use a static map) as well as (hopefully)
make it work
Revision Changes Path
1.6 +4 -2
jboss/src/main/org/jboss/ejb/plugins/jrmp/interfaces/HomeProxy.java
Index: HomeProxy.java
===================================================================
RCS file:
/products/cvs/ejboss/jboss/src/main/org/jboss/ejb/plugins/jrmp/interfaces/HomeProxy.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- HomeProxy.java 2000/05/12 11:43:25 1.5
+++ HomeProxy.java 2000/06/04 23:19:01 1.6
@@ -17,7 +17,7 @@
*
* @see <related>
* @author Rickard �berg ([EMAIL PROTECTED])
- * @version $Revision: 1.5 $
+ * @version $Revision: 1.6 $
*/
public abstract class HomeProxy
extends GenericProxy
@@ -56,7 +56,9 @@
// Isn't this a bug in the proxy call??
if (args == null)
args = new Object[0];
-
+ System.out.println();
+ System.out.println("In creating Home
"+m.getDeclaringClass()+m.getName()+m.getParameterTypes().length);
+
if (m.equals(toStr))
{
return name+" home";
1.5 +101 -4
jboss/src/main/org/jboss/ejb/plugins/jrmp/interfaces/MethodInvocation.java
Index: MethodInvocation.java
===================================================================
RCS file:
/products/cvs/ejboss/jboss/src/main/org/jboss/ejb/plugins/jrmp/interfaces/MethodInvocation.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- MethodInvocation.java 2000/05/12 11:43:26 1.4
+++ MethodInvocation.java 2000/06/04 23:19:01 1.5
@@ -15,11 +15,15 @@
import java.util.HashMap;
/**
- * <description>
+ * MethodInvocation
+ *
+ * This Serializable object carries the method to invoke and an identifier for the
target ojbect
*
* @see <related>
* @author Rickard �berg ([EMAIL PROTECTED])
- * @version $Revision: 1.4 $
+ * @author <a href="mailto:[EMAIL PROTECTED]">Richard
Monson-Haefel</a>.
+ * @author <a href="mailto:[EMAIL PROTECTED]">Marc Fleury</a>.
+ * @version $Revision: 1.5 $
*/
public class MethodInvocation
implements java.io.Serializable
@@ -33,6 +37,9 @@
Object[] args;
// Static --------------------------------------------------------
+ // MF FIXME: this is bad.
+ // It will grow quite large
+ // We need to work from the container context... not the server context it is
silly
static HashMap clazzMap = new HashMap();
static HashMap invokers = new HashMap(); // Prevent DGC
@@ -50,14 +57,32 @@
{
this.id = id;
this.className = m.getDeclaringClass().getName();
- this.hash = m.hashCode();
+ // m.hashCode only hashes on the name / class.
+ // Overriding is not seen and must include parameters
+ this.hash = calculateHash(m);
this.args = args;
+
+ System.out.println("In Method INVOCATION CREATE
"+m.getDeclaringClass()+m.getName()+m.getParameterTypes().length);
+ System.out.println("In Method INVOCATION CREATE hash "+hash);
+
}
// Public --------------------------------------------------------
public Object getId() { return id; }
+ /*
+ * MF FIXME: I am not sure this is a very good idea.
+ *
+ * The use of the synchronized map is going to slow things down.
+ * Also the penalty on the first invocation can be quite high.
+ * It is probably better to have the container pre-map the method.
+ * We can then directly look up in the container and no need to
+ * extract the "method" from here, just the hashCode() (calculated one)
+ * In clear I am saying that this is overkill and slow. Will investigate.
+ *
+ * People will see this as they run their stuff for the first time (setup)
+ */
public Method getMethod()
throws NoSuchMethodException, ClassNotFoundException
{
@@ -74,7 +99,9 @@
methodMap = new HashMap();
for (int i = 0; i < methods.length; i++)
{
- methodMap.put(new Integer(methods[i].hashCode()), methods[i]);
+ System.out.println("Storing
"+methods[i].getDeclaringClass()+methods[i].getName()+methods[i].getParameterTypes().length+
" Hash "+calculateHash(methods[i]));
+
+ methodMap.put(new Integer(calculateHash(methods[i])), methods[i]);
}
clazzMap.put(clazz, methodMap);
}
@@ -84,6 +111,8 @@
{
// Get method based on its hash value
Method m = (Method)methodMap.get(new Integer(hash));
+ System.out.println("In Method INVOCATION LOOKUP
"+m.getDeclaringClass()+m.getName()+m.getParameterTypes().length);
+
if (m == null)
throw new NoSuchMethodException(clazz+":"+hash);
return m;
@@ -96,11 +125,79 @@
return args;
}
+ /*
+ * The use of hashCode is not enough to differenciate methods
+ * we override the hashCode
+ *
+ * This is taken from the RMH code in EJBoss 0.9
+ *
+ */
+ public int calculateHash(Method method) {
+
+ hash =
+ // We use the declaring class
+ method.getDeclaringClass().getName().hashCode() ^ //name of
class
+ // We use the name of the method
+ method.getName().hashCode(); //name of method
+
+ Class[] clazz = method.getParameterTypes();
+
+ for (int i = 0; i < clazz.length; i++) {
+
+ // XOR
+ // We use the constant because
+ // a^b^b = a (thank you norbert)
+ // so that methodA() hashes to methodA(String, String)
+
+ hash = (hash +20000) ^ clazz[i].getName().hashCode();
+ }
+
+ return hash;
+ }
+
+
+
+ /*
+ * equals()
+ *
+ * For MethodInvocations to be equal, the method must be equal but also the
+ * the arguments
+ *
+ * @since EJBoss 0.9
+ */
+ public boolean equals(Object obj) {
+
+ if (obj != null && obj instanceof MethodInvocation) {
+
+ MethodInvocation other = (MethodInvocation)obj;
+
+ if(other.hash == this.hash) {
+
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /*
+ * hashCode
+ *
+ * Base the hashcode on the name of the class, the name of the method and the
+ * first parameter.
+ *
+ */
+ public int hashCode() {
+
+ // See the calculate hashcode it takes everything into account
+ return hash;
+ }
+
// Package protected ---------------------------------------------
// Protected -----------------------------------------------------
// Private -------------------------------------------------------
+
// Inner classes -------------------------------------------------
}
1.6 +4 -1
jboss/src/main/org/jboss/ejb/plugins/jrmp/interfaces/StatefulSessionProxy.java
Index: StatefulSessionProxy.java
===================================================================
RCS file:
/products/cvs/ejboss/jboss/src/main/org/jboss/ejb/plugins/jrmp/interfaces/StatefulSessionProxy.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- StatefulSessionProxy.java 2000/05/12 11:43:25 1.5
+++ StatefulSessionProxy.java 2000/06/04 23:19:01 1.6
@@ -18,7 +18,7 @@
*
* @see <related>
* @author Rickard �berg ([EMAIL PROTECTED])
- * @version $Revision: 1.5 $
+ * @version $Revision: 1.6 $
*/
public abstract class StatefulSessionProxy
extends GenericProxy
@@ -54,6 +54,9 @@
// this.getClass().getClassLoader() ==
Thread.currentThread().getContextClassLoader())
// return container.invoke(id, m, args, null, null);
+
+ System.out.println("In creating Home
"+m.getDeclaringClass()+m.getName()+m.getParameterTypes().length);
+
Object result = container.invoke(new MarshalledObject(new
MethodInvocation(id, m, args)), null, null);
if (result instanceof MarshalledObject)
return ((MarshalledObject)result).get();