User: fleury
Date: 00/08/08 14:29:01
Modified: src/main/org/jboss/ejb/plugins/jrmp/interfaces
StatelessSessionProxy.java
Log:
Local calls implemented, EJBObject implemented
Revision Changes Path
1.8 +154 -83
jboss/src/main/org/jboss/ejb/plugins/jrmp/interfaces/StatelessSessionProxy.java
Index: StatelessSessionProxy.java
===================================================================
RCS file:
/products/cvs/ejboss/jboss/src/main/org/jboss/ejb/plugins/jrmp/interfaces/StatelessSessionProxy.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- StatelessSessionProxy.java 2000/08/06 21:36:01 1.7
+++ StatelessSessionProxy.java 2000/08/08 21:29:00 1.8
@@ -1,9 +1,9 @@
/*
- * jBoss, the OpenSource EJB server
- *
- * Distributable under GPL license.
- * See terms of license at gnu.org.
- */
+* jBoss, the OpenSource EJB server
+*
+* Distributable under GPL license.
+* See terms of license at gnu.org.
+*/
package org.jboss.ejb.plugins.jrmp.interfaces;
import java.lang.reflect.Method;
@@ -16,86 +16,157 @@
import org.jboss.ejb.plugins.jrmp.server.JRMPContainerInvoker;
/**
- * <description>
- *
- * @see <related>
- * @author Rickard �berg ([EMAIL PROTECTED])
- * @version $Revision: 1.7 $
- */
+* <description>
+*
+* @see <related>
+* @author Rickard �berg ([EMAIL PROTECTED])
+* @author <a href="mailto:[EMAIL PROTECTED]">Marc Fleury</a>
+* @version $Revision: 1.8 $
+*/
public class StatelessSessionProxy
- extends GenericProxy
+extends GenericProxy
{
- // Constants -----------------------------------------------------
-
- // Attributes ----------------------------------------------------
-
- // Static --------------------------------------------------------
- static Method getHandle;
- static Method toStr;
-
- static
- {
- try
- {
- getHandle = EJBObject.class.getMethod("getHandle", new Class[0]);
- toStr = Object.class.getMethod("toString", new Class[0]);
- } catch (Exception e)
- {
- e.printStackTrace();
- }
- }
-
- // Constructors --------------------------------------------------
- public StatelessSessionProxy(String name, ContainerRemote container, boolean
optimize)
- {
+ // Constants -----------------------------------------------------
+
+ // Attributes ----------------------------------------------------
+
+ // Static --------------------------------------------------------
+
+ static Method getPrimaryKey;
+ static Method getHandle;
+ static Method isIdentical;
+ static Method toStr;
+ static Method eq;
+ static Method hash;
+
+ static
+ {
+ try
+ {
+ // EJBObject methods
+ getPrimaryKey = EJBObject.class.getMethod("getPrimaryKey", new
Class[0]);
+ getHandle = EJBObject.class.getMethod("getHandle", new
Class[0]);
+ isIdentical = EJBObject.class.getMethod("isIdentical", new
Class[] { EJBObject.class });
+
+ // Object methods
+ toStr = Object.class.getMethod("toString", new Class[0]);
+ eq = Object.class.getMethod("equals", new Class[] {
Object.class });
+ hash = Object.class.getMethod("hashCode", new Class[0]);
+ } catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ }
+
+
+ // Constructors --------------------------------------------------
+ public StatelessSessionProxy(String name, ContainerRemote container, boolean
optimize)
+ {
super(name, container, optimize);
- }
-
- // Public --------------------------------------------------------
-
- // InvocationHandler implementation ------------------------------
- public final Object invoke(Object proxy, Method m, Object[] args)
- throws Throwable
- {
- // Normalize args to always be an array
- // Isn't this a bug in the proxy call??
- if (args == null)
- args = new Object[0];
+ }
+
+ // Public --------------------------------------------------------
+
+ // InvocationHandler implementation ------------------------------
+
+ public final Object invoke(Object proxy, Method m, Object[] args)
+ throws Throwable
+ {
+ // Normalize args to always be an array
+ // Isn't this a bug in the proxy call??
+ if (args == null)
+ args = new Object[0];
+
+ // Implement local methods
+ if (m.equals(toStr))
+ {
+ return name+":Stateless";
+ }
+ else if (m.equals(eq))
+ {
+ return invoke(proxy, isIdentical, args);
+ }
+
+ else if (m.equals(hash))
+ {
+ // We base the stateless hash on the hash of the proxy...
+ // MF XXX: it could be that we want to return the hash of the
name?
+ return new Integer(this.hashCode());
+ }
+
+ // Implement local EJB calls
+ else if (m.equals(getHandle))
+ {
+ return new StatelessHandleImpl(name);
+ }
+
+ else if (m.equals(getPrimaryKey))
+ {
+
+ // MF FIXME
+ // The spec says that SSB PrimaryKeys should not be returned
and the call should throw an exception
+ // However we need to expose the field *somehow* so we can
check for "isIdentical"
+ // For now we use a non-spec compliant implementation and just
return the key as is
+ // See jboss1.0 for the PKHolder and the hack to be
spec-compliant and yet solve the problem
+
+ // This should be the following call
+ //throw new RemoteException("Session Beans do not expose their
keys, RTFS");
- if (m.equals(getHandle))
- {
- return new StatelessHandleImpl(name);
- }
- else if (m.equals(toStr))
- {
- return name;
- } else
- {
- // Delegate to container
- // Optimize if calling another bean in same EJB-application
- if (optimize && isLocal())
- {
- return container.invoke(null, m, args,
- tm != null ?
tm.getTransaction() : null,
-
getPrincipal(), getCredential());
- } else
- {
- RemoteMethodInvocation rmi = new RemoteMethodInvocation(null, m,
args);
- if (tm != null)
- rmi.setTransaction(tm.getTransaction());
- rmi.setPrincipal(getPrincipal());
- rmi.setCredential(getCredential());
-
- return container.invoke(new MarshalledObject(rmi));
- }
- }
- }
-
- // Package protected ---------------------------------------------
-
- // Protected -----------------------------------------------------
-
- // Private -------------------------------------------------------
-
- // Inner classes -------------------------------------------------
+ // This is how it can be solved with a PKHolder (extends
RemoteException)
+ // throw new PKHolder("RTFS", name);
+
+ // This is non-spec compliant but will do for now
+ // We can consider the name of the container to be the primary
key, since all stateless beans
+ // are equal within a home
+ return name;
+ }
+ else if (m.equals(isIdentical))
+ {
+ // All stateless beans are identical within a home, if the
names are equal we are equal
+ return new
Boolean(((EJBObject)args[0]).getPrimaryKey().equals(name));
+ }
+
+ // If not taken care of, go on and call the container
+ else
+ {
+ // Delegate to container
+ // Optimize if calling another bean in same EJB-application
+ if (optimize && isLocal())
+ {
+ return container.invoke( // The entity id, method and
arguments for the invocation
+ null, m, args,
+ // Transaction attributes
+ tm != null ? tm.getTransaction() : null,
+ // Security attributes
+ getPrincipal(), getCredential());
+ } else
+ {
+ // Create a new MethodInvocation for distribution
+ RemoteMethodInvocation rmi = new
RemoteMethodInvocation(null, m, args);
+
+ // Set the transaction context
+ rmi.setTransaction(tm != null? tm.getTransaction() :
null);
+
+ // Set the security stuff
+ // MF fixme this will need to use "thread local" and
therefore same construct as above
+ // rmi.setPrincipal(sm != null? sm.getPrincipal() :
null);
+ // rmi.setCredential(sm != null? sm.getCredential() :
null);
+ // is the credential thread local? (don't think so...
but...)
+ rmi.setPrincipal( getPrincipal() );
+ rmi.setCredential( getCredential() );
+
+ // Invoke on the remote server, enforce marshalling
+ return container.invoke(new MarshalledObject(rmi));
+ }
+ }
+ }
+
+
+// Package protected ---------------------------------------------
+
+// Protected -----------------------------------------------------
+
+// Private -------------------------------------------------------
+
+// Inner classes -------------------------------------------------
}