User: osh
Date: 01/02/09 10:56:16
Modified: src/main/org/jboss/ejb/plugins/jrmp/interfaces
EntityProxy.java GenericProxy.java HomeProxy.java
MethodInvocation.java RemoteMethodInvocation.java
StatefulSessionProxy.java
StatelessSessionProxy.java
Log:
Changed tx export/propagation/import in preparation to JTA independence.
Revision Changes Path
1.21 +5 -5
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.20
retrieving revision 1.21
diff -u -r1.20 -r1.21
--- EntityProxy.java 2000/12/07 15:44:42 1.20
+++ EntityProxy.java 2001/02/09 18:56:14 1.21
@@ -23,7 +23,7 @@
* @see <related>
* @author Rickard �berg ([EMAIL PROTECTED])
* @author <a href="mailto:[EMAIL PROTECTED]">Marc Fleury</a>
-* @version $Revision: 1.20 $
+* @version $Revision: 1.21 $
*/
public class EntityProxy
extends GenericProxy
@@ -38,7 +38,7 @@
static Method getPrimaryKey;
static Method getHandle;
- static Method getEJBHome;
+ static Method getEJBHome;
static Method isIdentical;
static Method toStr;
static Method eq;
@@ -52,7 +52,7 @@
getPrimaryKey = EJBObject.class.getMethod("getPrimaryKey", new Class[0]);
getHandle = EJBObject.class.getMethod("getHandle", new Class[0]);
getEJBHome = EJBObject.class.getMethod("getEJBHome", new Class[0]);
- isIdentical = EJBObject.class.getMethod("isIdentical", new Class[] {
EJBObject.class });
+ isIdentical = EJBObject.class.getMethod("isIdentical", new Class[] {
EJBObject.class });
// Object methods
toStr = Object.class.getMethod("toString", new Class[0]);
@@ -146,7 +146,7 @@
return container.invoke( // The entity id, method and arguments for the
invocation
cacheKey, m, args,
// Transaction attributes
- tm != null ? tm.getTransaction() : null,
+ getTransaction(),
// Security attributes
getPrincipal(), getCredential());
} else
@@ -155,7 +155,7 @@
RemoteMethodInvocation rmi = new RemoteMethodInvocation(cacheKey, m,
args);
// Set the transaction context
- rmi.setTransaction(tm != null? tm.getTransaction() : null);
+ rmi.setTransactionPropagationContext(getTransactionPropagationContext());
// Set the security stuff
// MF fixme this will need to use "thread local" and therefore same
construct as above
1.10 +198 -50
jboss/src/main/org/jboss/ejb/plugins/jrmp/interfaces/GenericProxy.java
Index: GenericProxy.java
===================================================================
RCS file:
/products/cvs/ejboss/jboss/src/main/org/jboss/ejb/plugins/jrmp/interfaces/GenericProxy.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- GenericProxy.java 2001/01/10 01:24:01 1.9
+++ GenericProxy.java 2001/02/09 18:56:15 1.10
@@ -9,22 +9,24 @@
import java.io.IOException;
import java.security.Principal;
+import javax.transaction.Transaction;
import javax.transaction.TransactionManager;
+import javax.transaction.SystemException;
import org.jboss.ejb.MethodInvocation;
import org.jboss.ejb.plugins.jrmp.server.JRMPContainerInvoker;
-import org.jboss.tm.TxManager;
+import org.jboss.tm.TransactionPropagationContextFactory;
import java.util.HashMap;
import org.jboss.security.SecurityAssociation;
/**
- * <description>
+ * Abstract superclass of JRMP client-side proxies.
*
- * @see <related>
- * @author Rickard �berg ([EMAIL PROTECTED])
- * @version $Revision: 1.9 $
+ * @see ContainerRemote
+ * @author Rickard �berg ([EMAIL PROTECTED])
+ * @version $Revision: 1.10 $
*/
public abstract class GenericProxy
implements java.io.Externalizable
@@ -32,43 +34,100 @@
// Constants -----------------------------------------------------
// Attributes ----------------------------------------------------
- String name;
- ContainerRemote container;
- long containerStartup = ContainerRemote.startup;
-
- boolean optimize = false;
-
+
// Static --------------------------------------------------------
- static TransactionManager tm;
+ /**
+ * Our transaction manager.
+ *
+ * When set to a non-null value, this is used for getting the
+ * transaction to use for optimized local method invocations.
+ * If <code>null</code>, transactions are not propagated on
+ * optimized local method invocations.
+ */
+ private static TransactionManager tm = null;
+
+ /**
+ * Factory for transaction propagation contexts.
+ *
+ * When set to a non-null value, it is used to get transaction
+ * propagation contexts for remote method invocations.
+ * If <code>null</code>, transactions are not propagated on
+ * remote method invocations.
+ */
+ protected static TransactionPropagationContextFactory tpcFactory = null;
+
+ /**
+ * This map maps JNDI names of containers to the remote interfaces
+ * of the container invokers of these containers.
+ */
static HashMap invokers = new HashMap(); // Prevent DGC
- public static ContainerRemote getLocal(String jndiName) { return
(ContainerRemote)invokers.get(jndiName); }
- public static void addLocal(String jndiName, ContainerRemote invoker) {
invokers.put(jndiName, invoker); }
- public static void removeLocal(String jndiName) { invokers.remove(jndiName); }
-
- public static void setTransactionManager(TransactionManager txMan)
- {
- if (tm == null)
- tm = txMan;
- }
-
- public Principal getPrincipal()
- {
- return SecurityAssociation.getPrincipal();
- }
-
- public Object getCredential()
- {
- return SecurityAssociation.getCredential();
- }
+ /**
+ * Return the remote interface of the container invoker for the
+ * container with the given JNDI name.
+ */
+ private static ContainerRemote getLocal(String jndiName)
+ {
+ return (ContainerRemote)invokers.get(jndiName);
+ }
+
+ /**
+ * Add an invoker to the invokers map.
+ */
+ public static void addLocal(String jndiName, ContainerRemote invoker)
+ {
+ invokers.put(jndiName, invoker);
+ }
+
+ /**
+ * Remove an invoker from the invokers map.
+ */
+ public static void removeLocal(String jndiName)
+ {
+ invokers.remove(jndiName);
+ }
+
+ /**
+ * Set the transaction manager.
+ */
+ public static void setTransactionManager(TransactionManager txMan)
+ {
+ tm = txMan;
+ }
+
+ /**
+ * Set the transaction propagation context factory.
+ */
+ public static void setTPCFactory(TransactionPropagationContextFactory tpcf)
+ {
+ tpcFactory = tpcf;
+ }
+
// Constructors --------------------------------------------------
+
+ /**
+ * A public, no-args constructor for externalization to work.
+ */
public GenericProxy()
{
// For externalization to work
}
-
- protected GenericProxy(String name, ContainerRemote container, boolean optimize)
+
+ /**
+ * Create a new GenericProxy.
+ *
+ * @param name
+ * The JNDI name of the container that we proxy for.
+ * @param container
+ * The remote interface of the container invoker of the
+ * container we proxy for.
+ * @param optimize
+ * If <code>true</true>, this proxy will attempt to optimize
+ * VM-local calls.
+ */
+ protected GenericProxy(String name, ContainerRemote container,
+ boolean optimize)
{
this.name = name;
this.container = container;
@@ -77,30 +136,36 @@
// Public --------------------------------------------------------
- // Package protected ---------------------------------------------
-
- // Protected -----------------------------------------------------
- protected boolean isLocal()
- {
- return containerStartup == ContainerRemote.startup;
- }
-
+ /**
+ * Externalize this instance.
+ *
+ * If this instance lives in a different VM than its container
+ * invoker, the remote interface of the container invoker is
+ * not externalized.
+ */
public void writeExternal(java.io.ObjectOutput out)
throws IOException
{
- out.writeUTF(name);
- out.writeObject(isLocal() ? container : null);
+ out.writeUTF(name);
+ out.writeObject(isLocal() ? container : null);
out.writeLong(containerStartup);
out.writeBoolean(optimize);
}
-
+
+ /**
+ * Un-externalize this instance.
+ *
+ * If this instance is deserialized in the same VM as its container
+ * invoker, the remote interface of the container invoker is
+ * restored by looking up the name in the invokers map.
+ */
public void readExternal(java.io.ObjectInput in)
throws IOException, ClassNotFoundException
{
- name = in.readUTF();
- container = (ContainerRemote)in.readObject();
- containerStartup = in.readLong();
- optimize = in.readBoolean();
+ name = in.readUTF();
+ container = (ContainerRemote)in.readObject();
+ containerStartup = in.readLong();
+ optimize = in.readBoolean();
if (isLocal())
{
@@ -108,9 +173,92 @@
container = getLocal(name);
}
}
-
+
+ // Package protected ---------------------------------------------
+
+ /**
+ * Return the principal to use for invocations with this proxy.
+ */
+ protected Principal getPrincipal()
+ {
+ return SecurityAssociation.getPrincipal();
+ }
+
+ /**
+ * Return the credentials to use for invocations with this proxy.
+ */
+ protected Object getCredential()
+ {
+ return SecurityAssociation.getCredential();
+ }
+
+ /**
+ * Return the transaction associated with the current thread.
+ * Returns <code>null</code> if the transaction manager was never
+ * set, or if no transaction is associated with the current thread.
+ */
+ protected Transaction getTransaction()
+ throws SystemException
+ {
+ return (tm == null) ? null : tm.getTransaction();
+ }
+
+ /**
+ * Return the transaction propagation context of the transaction
+ * associated with the current thread.
+ * Returns <code>null</code> if the transaction manager was never
+ * set, or if no transaction is associated with the current thread.
+ */
+ protected Object getTransactionPropagationContext()
+ throws SystemException
+ {
+ return (tpcFactory == null) ? null :
tpcFactory.getTransactionPropagationContext();
+ }
+
+ // Protected -----------------------------------------------------
+
+ /**
+ * The JNDI name of the container that we proxy for.
+ */
+ protected String name;
+
+ /**
+ * The remote interface of the container invoker of the container
+ * we proxy for.
+ */
+ protected ContainerRemote container;
+
+ /**
+ * If <code>true</true>, this proxy will attempt to optimize
+ * VM-local calls.
+ */
+ protected boolean optimize = false;
+
+
+ /**
+ * Returns <code>true</code> iff this instance lives in the same
+ * VM as its container.
+ */
+ protected boolean isLocal()
+ {
+ return containerStartup == ContainerRemote.startup;
+ }
+
// Private -------------------------------------------------------
-
+
+ /**
+ * Time of <code>ContainerRemote</code> class initialization as
+ * read when this instance was created. This time is used to
+ * determine if this instance lives in the same VM as the container.
+ *
+ * This is not completely fail-safe: If the ContainerRemote class
+ * is initialized in the server and at the client within the same
+ * millisecond, the proxy will think it is local, and the client
+ * will fail. This is, however, very unlikely to happen in real
+ * life, and next time the client is started it would run OK.
+ */
+ private long containerStartup = ContainerRemote.startup;
+
// Inner classes -------------------------------------------------
}
1.20 +6 -6
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.19
retrieving revision 1.20
diff -u -r1.19 -r1.20
--- HomeProxy.java 2000/12/07 15:44:42 1.19
+++ HomeProxy.java 2001/02/09 18:56:15 1.20
@@ -27,7 +27,7 @@
* @see <related>
* @author Rickard �berg ([EMAIL PROTECTED])
* @author <a href="mailto:[EMAIL PROTECTED]">Marc Fleury</a>
-* @version $Revision: 1.19 $
+* @version $Revision: 1.20 $
*/
public class HomeProxy
extends GenericProxy
@@ -156,7 +156,7 @@
// this is a remove() on the object
new Object[0],
// Tx stuff
- tm != null ? tm.getTransaction() : null,
+ getTransaction(),
// Security attributes
getPrincipal(), getCredential());
} else
@@ -172,7 +172,7 @@
new Object[0]);
// Set the transaction context
- rmi.setTransaction(tm != null? tm.getTransaction() : null);
+
rmi.setTransactionPropagationContext(getTransactionPropagationContext());
// Set the security stuff
// MF fixme this will need to use "thread local" and therefore same
construct as above
@@ -198,7 +198,7 @@
return container.invokeHome( // The method and arguments for the
invocation
m, args,
// Transaction attributes
- tm != null ? tm.getTransaction() : null,
+ getTransaction(),
// Security attributes
getPrincipal(), getCredential());
} else
@@ -206,8 +206,8 @@
// 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 transaction propagation context
+
rmi.setTransactionPropagationContext(getTransactionPropagationContext());
// Set the security stuff
// MF fixme this will need to use "thread local" and therefore same
construct as above
1.10 +11 -1
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.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- MethodInvocation.java 2000/12/07 15:44:43 1.9
+++ MethodInvocation.java 2001/02/09 18:56:15 1.10
@@ -19,11 +19,13 @@
*
* This Serializable object carries the method to invoke and an identifier for the
target ojbect
*
+ * @deprecated Unused, will be removed in the near future.
+ *
* @see <related>
* @author Rickard �berg ([EMAIL PROTECTED])
* @author <a href="mailto:[EMAIL PROTECTED]">Richard
Monson-Haefel</a>.
* @author <a href="mailto:[EMAIL PROTECTED]">Marc Fleury</a>.
- * @version $Revision: 1.9 $
+ * @version $Revision: 1.10 $
*/
public class MethodInvocation
implements java.io.Serializable
@@ -48,19 +50,27 @@
public static void removeLocal(String jndiName) { invokers.remove(jndiName); }
// Constructors --------------------------------------------------
+ /** @deprecated Unused, will be removed in the near future. */
public MethodInvocation(Method m, Object[] args)
{
+ throw new RuntimeException("Bang! This was suspected to be unused. Please
report.");
+/*
this(null, m, args);
+*/
}
+ /** @deprecated Unused, will be removed in the near future. */
public MethodInvocation(Object id, Method m, Object[] args)
{
+ throw new RuntimeException("Bang! This was suspected to be unused. Please
report.");
+/*
this.id = id;
this.className = m.getDeclaringClass().getName();
// m.hashCode only hashes on the name / class.
// Overriding is not seen and must include parameters
this.hash = calculateHash(m);
this.args = args;
+*/
}
// Public --------------------------------------------------------
1.11 +81 -81
jboss/src/main/org/jboss/ejb/plugins/jrmp/interfaces/RemoteMethodInvocation.java
Index: RemoteMethodInvocation.java
===================================================================
RCS file:
/products/cvs/ejboss/jboss/src/main/org/jboss/ejb/plugins/jrmp/interfaces/RemoteMethodInvocation.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- RemoteMethodInvocation.java 2000/12/07 15:44:43 1.10
+++ RemoteMethodInvocation.java 2001/02/09 18:56:15 1.11
@@ -19,16 +19,16 @@
import javax.transaction.Transaction;
/**
- * MethodInvocation
+ * RemoteMethodInvocation
*
* This Serializable object carries the method to invoke and an identifier for the
target ojbect
*
- * @see <related>
- * @author Rickard �berg ([EMAIL PROTECTED])
+ * @see <related>
+ * @author Rickard �berg ([EMAIL PROTECTED])
* @author <a href="mailto:[EMAIL PROTECTED]">Richard
Monson-Haefel</a>.
* @author <a href="mailto:[EMAIL PROTECTED]">Marc Fleury</a>.
* @author <a href="mailto:[EMAIL PROTECTED]">Daniel O'Connor</a>.
- * @version $Revision: 1.10 $
+ * @version $Revision: 1.11 $
*/
public final class RemoteMethodInvocation
implements java.io.Externalizable
@@ -41,12 +41,12 @@
int hash;
Object[] args;
-
- Transaction tx;
- Principal identity;
- Object credential;
+
+ private Object tpc; // Transaction propagation context.
+ private Principal identity;
+ private Object credential;
- transient Map methodMap;
+ transient Map methodMap;
// Static --------------------------------------------------------
@@ -57,28 +57,27 @@
* This is taken from the RMH code in EJBoss 0.9
*
*/
- public static int calculateHash(Method method) {
-
- int 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)
+ public static int calculateHash(Method method)
+ {
+ int 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();
- }
+ hash = (hash +20000) ^ clazz[i].getName().hashCode();
+ }
//DEBUGSystem.out.println(method+"="+hash);
- return hash;
+ return hash;
}
// Constructors --------------------------------------------------
@@ -96,8 +95,8 @@
{
this.id = id;
this.args = args;
- this.hash = calculateHash(m);
- this.className = m.getDeclaringClass().getName();
+ this.hash = calculateHash(m);
+ this.className = m.getDeclaringClass().getName();
}
// Public --------------------------------------------------------
@@ -107,7 +106,7 @@
public Method getMethod()
{
- return (Method)methodMap.get(new Integer(hash));
+ return (Method)methodMap.get(new Integer(hash));
}
public Object[] getArguments()
@@ -115,40 +114,40 @@
return args;
}
- public void setMethodMap(Map methods)
- {
- methodMap = methods;
- }
-
- public void setTransaction(Transaction tx)
- {
- this.tx = tx;
- }
-
- public Transaction getTransaction()
- {
- return tx;
- }
-
- public void setPrincipal(Principal identity)
- {
- this.identity = identity;
- }
-
- public Principal getPrincipal()
- {
- return identity;
- }
-
- public Object getCredential()
- {
- return credential;
- }
-
- public void setCredential( Object credential )
- {
- this.credential = credential;
- }
+ public void setMethodMap(Map methods)
+ {
+ methodMap = methods;
+ }
+
+ public void setTransactionPropagationContext(Object tpc)
+ {
+ this.tpc = tpc;
+ }
+
+ public Object getTransactionPropagationContext()
+ {
+ return tpc;
+ }
+
+ public void setPrincipal(Principal identity)
+ {
+ this.identity = identity;
+ }
+
+ public Principal getPrincipal()
+ {
+ return identity;
+ }
+
+ public Object getCredential()
+ {
+ return credential;
+ }
+
+ public void setCredential( Object credential )
+ {
+ this.credential = credential;
+ }
// Package protected ---------------------------------------------
@@ -156,30 +155,31 @@
public void writeExternal(java.io.ObjectOutput out)
throws IOException
{
- out.writeObject(id);
- out.writeUTF(className);
- out.writeInt(hash);
- out.writeObject(args);
- out.writeObject(tx);
- out.writeObject(identity);
- out.writeObject(credential);
+ out.writeObject(id);
+ out.writeUTF(className);
+ out.writeInt(hash);
+ out.writeObject(args);
+
+ out.writeObject(tpc);
+ out.writeObject(identity);
+ out.writeObject(credential);
}
public void readExternal(java.io.ObjectInput in)
throws IOException, ClassNotFoundException
{
- id = in.readObject();
- className = in.readUTF();
- hash = in.readInt();
- args = (Object[])in.readObject();
-
- tx = (Transaction)in.readObject();
- identity = (Principal)in.readObject();
- credential = in.readObject();
+ id = in.readObject();
+ className = in.readUTF();
+ hash = in.readInt();
+ args = (Object[])in.readObject();
+
+ tpc = in.readObject();
+ identity = (Principal)in.readObject();
+ credential = in.readObject();
}
// Private -------------------------------------------------------
- // Inner classes -------------------------------------------------
+ // Inner classes -------------------------------------------------
}
1.18 +3 -3
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.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- StatefulSessionProxy.java 2000/12/07 15:44:43 1.17
+++ StatefulSessionProxy.java 2001/02/09 18:56:15 1.18
@@ -23,7 +23,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 StatefulSessionProxy
extends GenericProxy
@@ -150,7 +150,7 @@
return container.invoke( // The entity id, method and arguments for
the invocation
id, m, args,
// Transaction attributes
- tm != null ? tm.getTransaction() : null,
+ getTransaction(),
// Security attributes
getPrincipal(), getCredential());
} else
@@ -159,7 +159,7 @@
RemoteMethodInvocation rmi = new RemoteMethodInvocation(id, m, args);
// Set the transaction context
- rmi.setTransaction(tm != null? tm.getTransaction() : null);
+ rmi.setTransactionPropagationContext(getTransactionPropagationContext());
// Set the security stuff
// MF fixme this will need to use "thread local" and therefore same
construct as above
1.13 +3 -3
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.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- StatelessSessionProxy.java 2000/12/07 15:44:43 1.12
+++ StatelessSessionProxy.java 2001/02/09 18:56:15 1.13
@@ -23,7 +23,7 @@
* @see <related>
* @author Rickard �berg ([EMAIL PROTECTED])
* @author <a href="mailto:[EMAIL PROTECTED]">Marc Fleury</a>
-* @version $Revision: 1.12 $
+* @version $Revision: 1.13 $
*/
public class StatelessSessionProxy
extends GenericProxy
@@ -152,7 +152,7 @@
return container.invoke( // The entity id, method and
arguments for the invocation
null, m, args,
// Transaction attributes
- tm != null ? tm.getTransaction() : null,
+ getTransaction(),
// Security attributes
getPrincipal(), getCredential());
} else
@@ -161,7 +161,7 @@
RemoteMethodInvocation rmi = new
RemoteMethodInvocation(null, m, args);
// Set the transaction context
- rmi.setTransaction(tm != null? tm.getTransaction() :
null);
+
rmi.setTransactionPropagationContext(getTransactionPropagationContext());
// Set the security stuff
// MF fixme this will need to use "thread local" and
therefore same construct as above