User: fleury
Date: 00/09/26 11:58:35
Modified: src/main/org/jboss/ejb/plugins/jrmp/interfaces
EntityProxy.java HomeProxy.java
Log:
new adds for the proper management of Tx and cache
Revision Changes Path
1.17 +185 -192
jboss/src/main/org/jboss/ejb/plugins/jrmp/interfaces/EntityProxy.java
Index: EntityProxy.java
===================================================================
RCS file:
/products/cvs/ejboss/jboss/src/main/org/jboss/ejb/plugins/jrmp/interfaces/EntityProxy.java,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- EntityProxy.java 2000/08/25 02:06:30 1.16
+++ EntityProxy.java 2000/09/26 18:58:34 1.17
@@ -1,192 +1,185 @@
-/*
-* 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.io.IOException;
-import java.rmi.MarshalledObject;
-import java.lang.reflect.Method;
-
-import javax.ejb.EJBObject;
-
-import org.jboss.ejb.plugins.jrmp.server.JRMPContainerInvoker;
-import org.jboss.ejb.CacheKey;
-
-/**
-* <description>
-*
-* @see <related>
-* @author Rickard �berg ([EMAIL PROTECTED])
-* @author <a href="mailto:[EMAIL PROTECTED]">Marc Fleury</a>
-* @version $Revision: 1.16 $
-*/
-public class EntityProxy
-extends GenericProxy
-{
- // Constants -----------------------------------------------------
-
- // Attributes ----------------------------------------------------
- protected CacheKey cacheKey;
-
-
- // Static --------------------------------------------------------
-
- static Method getPrimaryKey;
- static Method getHandle;
- static Method isIdentical;
- static Method toStr;
- static Method eq;
- static Method hash;
-
- static
- {
- try
- {
- // EJB 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 EntityProxy()
- {
- // For externalization to work
- }
-
- public EntityProxy(String name, ContainerRemote container, Object id, boolean
optimize)
- {
- super(name, container, optimize);
-
- if (id == null)
- throw new NullPointerException("Id may not be null");
-
- if (id instanceof CacheKey) {
- this.cacheKey = (CacheKey) id;
- }
- else
- {
- // In case we pass the Object or anything else we encapsulate
- cacheKey = new CacheKey(id);
-
- // Tell it it's fake
- cacheKey.isVirtual = true;
-
- // MF note: although I suspect just passing the "fake" cache
key would
- // work since the container has never mapped it in cache so no
context
- // would be found. We explicitely set it here
- }
- }
-
- // 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+":"+cacheKey.id.toString();
-
- }
- else if (m.equals(eq))
- {
- return invoke(proxy, isIdentical, args);
- }
-
- else if (m.equals(hash))
- {
- return new Integer(cacheKey.id.hashCode());
- }
-
- // Implement local EJB calls
- else if (m.equals(getHandle))
- {
- return new EntityHandleImpl(name, cacheKey.id);
- }
-
- else if (m.equals(getPrimaryKey))
- {
- return cacheKey.id;
- }
- else if (m.equals(isIdentical))
- {
- return new
Boolean(((EJBObject)args[0]).getPrimaryKey().equals(cacheKey.id));
- }
-
- // 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
- cacheKey, m, args,
- // Transaction attributes
- tm != null ? tm.getTransaction() : null,
- // Security attributes
- getPrincipal(), getCredential());
- } else
- {
- // Create a new MethodInvocation for distribution
- RemoteMethodInvocation rmi = new
RemoteMethodInvocation(cacheKey, 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)).get();
- }
- }
- }
-
- // Package protected ---------------------------------------------
-
- // Protected -----------------------------------------------------
- public void writeExternal(java.io.ObjectOutput out)
- throws IOException
- {
- super.writeExternal(out);
- out.writeObject(cacheKey);
- }
-
- public void readExternal(java.io.ObjectInput in)
- throws IOException, ClassNotFoundException
- {
- super.readExternal(in);
- cacheKey = (CacheKey) in.readObject();
- }
-
- // Private -------------------------------------------------------
-
- // Inner classes -------------------------------------------------
-}
-
+/*
+* 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.io.IOException;
+import java.rmi.MarshalledObject;
+import java.lang.reflect.Method;
+
+import javax.ejb.EJBObject;
+
+import org.jboss.ejb.plugins.jrmp.server.JRMPContainerInvoker;
+import org.jboss.ejb.CacheKey;
+
+/**
+* <description>
+*
+* @see <related>
+* @author Rickard �berg ([EMAIL PROTECTED])
+* @author <a href="mailto:[EMAIL PROTECTED]">Marc Fleury</a>
+* @version $Revision: 1.17 $
+*/
+public class EntityProxy
+extends GenericProxy
+{
+ // Constants -----------------------------------------------------
+
+ // Attributes ----------------------------------------------------
+ protected CacheKey cacheKey;
+
+
+ // Static --------------------------------------------------------
+
+ static Method getPrimaryKey;
+ static Method getHandle;
+ static Method isIdentical;
+ static Method toStr;
+ static Method eq;
+ static Method hash;
+
+ static
+ {
+ try
+ {
+ // EJB 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 EntityProxy()
+ {
+ // For externalization to work
+ }
+
+ public EntityProxy(String name, ContainerRemote container, Object id, boolean
optimize)
+ {
+ super(name, container, optimize);
+
+ if (id == null)
+ throw new NullPointerException("Id may not be null");
+
+ if (id instanceof CacheKey) {
+ this.cacheKey = (CacheKey) id;
+ }
+ else
+ {
+ // In case we pass the Object or anything else we encapsulate
+ cacheKey = new CacheKey(id);
+ }
+ }
+
+ // 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+":"+cacheKey.id.toString();
+
+ }
+ else if (m.equals(eq))
+ {
+ return invoke(proxy, isIdentical, args);
+ }
+
+ else if (m.equals(hash))
+ {
+ return new Integer(cacheKey.id.hashCode());
+ }
+
+ // Implement local EJB calls
+ else if (m.equals(getHandle))
+ {
+ return new EntityHandleImpl(name, cacheKey.id);
+ }
+
+ else if (m.equals(getPrimaryKey))
+ {
+ return cacheKey.id;
+ }
+ else if (m.equals(isIdentical))
+ {
+ return new
Boolean(((EJBObject)args[0]).getPrimaryKey().equals(cacheKey.id));
+ }
+
+ // 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
+ cacheKey, m, args,
+ // Transaction attributes
+ tm != null ? tm.getTransaction() : null,
+ // Security attributes
+ getPrincipal(), getCredential());
+ } else
+ {
+ // Create a new MethodInvocation for distribution
+ RemoteMethodInvocation rmi = new RemoteMethodInvocation(cacheKey, 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)).get();
+ }
+ }
+ }
+
+ // Package protected ---------------------------------------------
+
+ // Protected -----------------------------------------------------
+ public void writeExternal(java.io.ObjectOutput out)
+ throws IOException
+ {
+ super.writeExternal(out);
+ out.writeObject(cacheKey);
+ }
+
+ public void readExternal(java.io.ObjectInput in)
+ throws IOException, ClassNotFoundException
+ {
+ super.readExternal(in);
+ cacheKey = (CacheKey) in.readObject();
+ }
+
+ // Private -------------------------------------------------------
+
+ // Inner classes -------------------------------------------------
+}
+
1.18 +4 -4
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.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- HomeProxy.java 2000/08/18 03:21:02 1.17
+++ HomeProxy.java 2000/09/26 18:58:34 1.18
@@ -17,8 +17,8 @@
import javax.ejb.Handle;
import javax.ejb.HomeHandle;
import javax.ejb.EJBMetaData;
+import org.jboss.ejb.CacheKey;
-import org.jboss.util.FastKey;
import org.jboss.ejb.plugins.jrmp.server.JRMPContainerInvoker;
/**
@@ -27,7 +27,7 @@
* @see <related>
* @author Rickard �berg ([EMAIL PROTECTED])
* @author <a href="mailto:[EMAIL PROTECTED]">Marc Fleury</a>
-* @version $Revision: 1.17 $
+* @version $Revision: 1.18 $
*/
public class HomeProxy
extends GenericProxy
@@ -150,7 +150,7 @@
{
return container.invoke(
// The first argument is the id
- new FastKey(args[0]),
+ new CacheKey(args[0]),
// Pass the "removeMethod"
removeObject,
// this is a remove() on the object
@@ -165,7 +165,7 @@
// Build a method invocation that carries the identity of the
target object
RemoteMethodInvocation rmi = new RemoteMethodInvocation(
// The first argument is the id
- new FastKey(args[0]),
+ new CacheKey(args[0]),
// Pass the "removeMethod"
removeObject,
// this is a remove() on the object