User: patriot1burke
Date: 01/09/26 20:15:20
Modified: src/main/org/jboss/ejb/plugins/jrmp/interfaces
StatelessSessionProxyHA.java HomeProxyHA.java
Removed: src/main/org/jboss/ejb/plugins/jrmp/interfaces
HASLSBTargetsManager.java GenericProxyHA.java
Log:
no message
Revision Changes Path
1.2 +78 -256
jbossmx/src/main/org/jboss/ejb/plugins/jrmp/interfaces/StatelessSessionProxyHA.java
Index: StatelessSessionProxyHA.java
===================================================================
RCS file:
/cvsroot/jboss/jbossmx/src/main/org/jboss/ejb/plugins/jrmp/interfaces/StatelessSessionProxyHA.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- StatelessSessionProxyHA.java 2001/08/19 18:27:49 1.1
+++ StatelessSessionProxyHA.java 2001/09/27 03:15:20 1.2
@@ -1,290 +1,112 @@
/*
- * JBoss, the OpenSource J2EE WebOS
+ * JBoss, the OpenSource J2EE webOS
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
-
package org.jboss.ejb.plugins.jrmp.interfaces;
import java.lang.reflect.Method;
-import java.util.Hashtable;
-import java.io.IOException;
-
-import java.rmi.MarshalledObject;
-import javax.naming.InitialContext;
-import javax.naming.Name;
-
-import javax.ejb.EJBObject;
-import javax.ejb.EJBHome;
import org.jboss.ejb.plugins.jrmp.server.JRMPContainerInvoker;
-
-import org.jboss.ejb.plugins.jrmp.interfaces.StatelessHandleImpl;
-
+import java.io.IOException;
+import java.io.Externalizable;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import org.jboss.ha.HARMIProxy;
/**
- * Branched from StatelessSessionProxy for HA behaviour
- *
- * @see StatelessSessionProxy
- * @author Rickard �berg ([EMAIL PROTECTED])
- * @author <a href="mailto:[EMAIL PROTECTED]">Marc Fleury</a>
- * @author <a href="mailto:[EMAIL PROTECTED]">Sacha Labourey</a>
- * @version $Revision: 1.1 $
- *
- * <p><b>Revisions:</b>
- *
- * <p><b>20010819 Sacha Labourey:</b>
- * <ul>
- * <li> First import of sources
- * </ul>
+ * An EJB stateless session bean proxy class.
+ *
+ * @author <a href="mailto:[EMAIL PROTECTED]">Rickard �berg</a>.
+ * @author <a href="mailto:[EMAIL PROTECTED]">Marc Fleury</a>
+ * @author <a href="mailto:[EMAIL PROTECTED]">Jason Dillon</a>
+ * @version $Revision: 1.2 $
*/
-
-public class StatelessSessionProxyHA extends GenericProxyHA
+public class StatelessSessionProxyHA
+ extends StatelessSessionProxy
{
// Constants -----------------------------------------------------
-
+
// Attributes ----------------------------------------------------
-
+
// Static --------------------------------------------------------
-
- static Method getPrimaryKey;
- static Method getHandle;
- static Method getEJBHome;
- 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]);
- getEJBHome = EJBObject.class.getMethod ("getEJBHome", 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 StatelessSessionProxyHA ()
- {
- // For externalization to work
- }
-
- public StatelessSessionProxyHA (String name,ContainerRemote container,boolean
optimize, TargetsManager mgr)
+
+ /**
+ * No-argument constructor for externalization.
+ */
+ public StatelessSessionProxyHA() {}
+
+ /**
+ * Construct a <tt>StatelessSessionProxy</tt>.
+ *
+ * @param name The JNDI name of the container that we proxy for.
+ * @param container The remote interface of the invoker for which
+ * this is a proxy for.
+ * @param optimize True if the proxy will attempt to optimize
+ * VM-local calls.
+ */
+ public StatelessSessionProxyHA(final String name,
+ final ContainerRemote container,
+ final boolean optimize)
{
- super (name, container, optimize, mgr);
+ super(name, container, optimize);
}
-
+
// Public --------------------------------------------------------
-
+
/**
- * Externalize this instance.
+ * Externalization support.
+ *
+ * @param out
*
+ * @throws IOException
*/
- public void writeExternal (java.io.ObjectOutput out)
- throws IOException
+ public void writeExternal(final ObjectOutput out)
+ throws IOException
{
- super.writeExternal (out);
+ out.writeUTF(name);
+ out.writeObject(container);
+ out.writeBoolean(optimize);
+ out.writeObject(initialContextHandle);
}
-
+
/**
- * Un-externalize this instance.
- *
- */
- public void readExternal (java.io.ObjectInput in)
- throws IOException, ClassNotFoundException
- {
- super.readExternal (in);
+ * Externalization support.
+ *
+ * @param in
+ *
+ * @throws IOException
+ * @throws ClassNotFoundException
+ */
+ public void readExternal(final ObjectInput in)
+ throws IOException, ClassNotFoundException
+ {
+ name = in.readUTF();
+ container = (ContainerRemote)in.readObject();
+ optimize = in.readBoolean();
+ initialContextHandle = (InitialContextHandle)in.readObject();
}
-
- // InvocationHandler implementation ------------------------------
-
- public final Object invoke (Object proxy, Method m, Object[] args)
- throws Throwable
+
+ public void setHAProxy(ContainerRemote proxy)
{
- // 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 (null, 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");
-
- // 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 (getEJBHome))
- {
-
- Hashtable aServerProps = null;
- javax.naming.NamingException lastProblem = null;
-
- while (true)
- {
- synchronized (crs)
- {
- aServerProps = getJndiTarget ();
-
- if (numberOfRegisteredJndiTargets () == 0)
- throw ( (lastProblem==null)? new javax.naming.NamingException
("No more valid HA SLSB container availble") : lastProblem );
- }
-
- try
- {
- return (EJBHome) new InitialContext (aServerProps).lookup (name);
- }
- catch (javax.naming.NamingException e)
- {
- jndiTargetHasFailed (aServerProps);
- lastProblem = e;
- }
- }
- }
-
- 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
- getTransaction (),
- // Security attributes
- getPrincipal (), getCredential ());
- } else
- {
- // Create a new MethodInvocation for distribution
- RemoteMethodInvocation rmi = new RemoteMethodInvocation (null, m, args);
-
- // Set the transaction context
- rmi.setTransactionPropagationContext (getTransactionPropagationContext
());
-
- // 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 marshaling
- if (isLocal ())
- {
- // We need to make sure marshaling of exceptions is done properly
- try
- {
- return container.invoke (new MarshalledObject (rmi)).get ();
- } catch (Throwable e)
- {
- throw (Throwable)new MarshalledObject (e).get ();
- }
- }
- else
- {
- // Marshaling is done by RMI
- //
- ContainerRemote aTarget = null;
- java.rmi.RemoteException lastProblem = null;
-
- tick ();
-
- // this proxy must support concurrent invocations
- //
- while (true)
- {
- synchronized (crs)
- {
- aTarget = getRemoteTarget ();
- if (numberOfRegisteredRemoteTargets () == 0)
- throw ( (lastProblem==null)? new java.rmi.RemoteException
("No more valid HA SLSB container availble") : lastProblem );
-
- }
-
- try
- {
- return aTarget.invoke (new MarshalledObject (rmi)).get ();
- }
- catch (java.rmi.RemoteException e)
- {
- remoteTargetHasFailed (aTarget);
- lastProblem = e;
- }
- }
- }
- }
- }
+ container = proxy;
}
-
-
+
// Package protected ---------------------------------------------
-
+
// Protected -----------------------------------------------------
-
+
+ /**
+ * Returns <code>true</code> iff this instance lives in the same
+ * VM as its container.
+ */
+ protected boolean isLocal()
+ {
+ return ((HARMIProxy)container).isLocal();
+ }
// Private -------------------------------------------------------
-
+
// Inner classes -------------------------------------------------
}
-
1.2 +89 -279
jbossmx/src/main/org/jboss/ejb/plugins/jrmp/interfaces/HomeProxyHA.java
Index: HomeProxyHA.java
===================================================================
RCS file:
/cvsroot/jboss/jbossmx/src/main/org/jboss/ejb/plugins/jrmp/interfaces/HomeProxyHA.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- HomeProxyHA.java 2001/08/19 18:27:49 1.1
+++ HomeProxyHA.java 2001/09/27 03:15:20 1.2
@@ -1,14 +1,15 @@
/*
- * JBoss, the OpenSource J2EE WebOS
+ * JBoss, the OpenSource J2EE webOS
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
-
package org.jboss.ejb.plugins.jrmp.interfaces;
-
import java.io.IOException;
+import java.io.ObjectOutput;
+import java.io.ObjectInput;
+
import java.lang.reflect.Method;
import java.rmi.MarshalledObject;
@@ -19,300 +20,109 @@
import javax.ejb.Handle;
import javax.ejb.HomeHandle;
import javax.ejb.EJBMetaData;
-import org.jboss.ejb.CacheKey;
+import javax.ejb.RemoveException;
+import org.jboss.ejb.CacheKey;
import org.jboss.ejb.plugins.jrmp.server.JRMPContainerInvoker;
-
+import org.jboss.ha.HARMIProxy;
+import org.jboss.ha.RoundRobin;
/**
- * Branched from HomeProxy for HA behaviour
- *
- * @see HomeProxy
- * @author Rickard �berg ([EMAIL PROTECTED])
- * @author <a href="mailto:[EMAIL PROTECTED]">Marc Fleury</a>
- * @author <a href="mailto:[EMAIL PROTECTED]">Sacha Labourey</a>
- * @version $Revision: 1.1 $
- *
- * <p><b>Revisions:</b>
- *
- * <p><b>20010819 Sacha Labourey:</b>
- * <ul>
- * <li> First import of sources
- * </ul>
+ * The client-side proxy for an EJB Home object.
+ *
+ * @author <a href="mailto:[EMAIL PROTECTED]">Rickard �berg</a>.
+ * @author <a href="mailto:[EMAIL PROTECTED]">Marc Fleury</a>
+ * @author <a href="mailto:[EMAIL PROTECTED]">Jason Dillon</a>
+ * @version $Revision: 1.2 $
*/
-
-public class HomeProxyHA extends GenericProxyHA
+public class HomeProxyHA
+ extends HomeProxy
{
// Constants -----------------------------------------------------
-
- // Attributes ----------------------------------------------------
-
- EJBMetaData ejbMetaData;
+
// Static --------------------------------------------------------
- static Method getEJBMetaData;
- static Method getHomeHandle;
- static Method removeByHandle;
- static Method removeByPrimaryKey;
- static Method removeObject;
- static Method toStr;
- static Method eq;
- static Method hash;
-
- static
- {
- try
- {
- // EJB methods
- getEJBMetaData = EJBHome.class.getMethod ("getEJBMetaData", new Class[0]);
- getHomeHandle = EJBHome.class.getMethod ("getHomeHandle", new Class[0]);
- removeByHandle = EJBHome.class.getMethod ("remove", new Class[]
- {Handle.class});
- removeByPrimaryKey = EJBHome.class.getMethod ("remove", new Class[]
- {Object.class});
- // Get the "remove" method from the EJBObject
- removeObject = EJBObject.class.getMethod ("remove", new Class[0]);
-
- // 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 ();
- }
- }
-
+
+ // Attributes ----------------------------------------------------
// Constructors --------------------------------------------------
- public HomeProxyHA ()
- {
- // For Externalizable to work
- }
- public HomeProxyHA (String name, EJBMetaData ejbMetaData,
- ContainerRemote container, boolean optimize,
- TargetsManager mgr)
+ /**
+ * No-argument constructor for externalization.
+ */
+ public HomeProxyHA() {}
+
+ /**
+ * Construct a <tt>HomeProxyHA</tt>.
+ *
+ * @param name The JNDI name of the container that we proxy for.
+ * @param ejbMetaData ???
+ * @param container The remote interface of the invoker for which
+ * this is a proxy for.
+ * @param optimize True if the proxy will attempt to optimize
+ * VM-local calls.
+ */
+ public HomeProxyHA(final String name,
+ final EJBMetaData ejbMetaData,
+ final ContainerRemote container,
+ final boolean optimize)
{
- super (name, container, optimize, mgr);
- this.ejbMetaData = ejbMetaData;
+ super(name, ejbMetaData, container, optimize);
}
-
+
// Public --------------------------------------------------------
-
- // InvocationHandler implementation ------------------------------
- public Object invoke (Object proxy, Method m, Object[] args)
- throws Throwable
+
+ public void setHAProxy(ContainerRemote proxy)
{
-
-
- // 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+"Home";
- }
- else if (m.equals (eq))
- {
- // equality of the proxy home is based on names...
-
- return new Boolean (invoke (proxy,toStr, args).equals (name+"Home"));
- }
-
- else if (m.equals (hash))
- {
-
- return new Integer (this.hashCode ());
- }
-
- // Implement local EJB calls
- else if (m.equals (getHomeHandle))
- {
-
- return new HomeHandleImpl (name);
- }
-
-
- else if (m.equals (getEJBMetaData))
- {
-
- return ejbMetaData;
- }
-
-
- else if (m.equals (removeByHandle))
- {
-
- // First get the EJBObject
- EJBObject object = ((Handle) args[0]).getEJBObject ();
-
- // remove the object from here
- object.remove ();
-
- // Return Void
- return Void.TYPE;
- }
-
- // The trick is simple we trick the container in believe it is a remove() on
the instance
- else if (m.equals (removeByPrimaryKey))
- {
-
- if (optimize && isLocal ())
- {
- return container.invoke (
- // The first argument is the id
- new CacheKey (args[0]),
- // Pass the "removeMethod"
- removeObject,
- // this is a remove() on the object
- new Object[0],
- // Tx stuff
- getTransaction (),
- // Security attributes
- getPrincipal (), getCredential ());
- } else
- {
-
- // Build a method invocation that carries the identity of the target
object
- RemoteMethodInvocation rmi = new RemoteMethodInvocation (
- // The first argument is the id
- new CacheKey (args[0]),
- // Pass the "removeMethod"
- removeObject,
- // this is a remove() on the object
- new Object[0]);
-
- // Set the transaction context
- rmi.setTransactionPropagationContext (getTransactionPropagationContext
());
-
- // 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 marshaling
- if (isLocal ())
- {
- // We need to make sure marshaling of exceptions is done properly
- try
- {
- return container.invoke (new MarshalledObject (rmi)).get ();
- } catch (Throwable e)
- {
- throw (Throwable)new MarshalledObject (e).get ();
- }
- } else
- {
- // Marshaling is done by RMI
- return container.invoke (new MarshalledObject (rmi)).get ();
- }
- }
- }
-
- // 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.invokeHome ( // The method and arguments for the
invocation
- m, args,
- // Transaction attributes
- getTransaction (),
- // Security attributes
- getPrincipal (), getCredential ());
- } else
- {
- // Create a new MethodInvocation for distribution
- RemoteMethodInvocation rmi = new RemoteMethodInvocation (null, m, args);
-
- // 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
- // 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 marshaling
- if (isLocal ())
- {
- // We need to make sure marshaling of exceptions is done properly
- try
- {
- return container.invokeHome (new MarshalledObject (rmi)).get ();
- } catch (Throwable e)
- {
- throw (Throwable)new MarshalledObject (e).get ();
- }
- } else
- {
- // Marshaling is done by RMI
- // Marshaling is done by RMI
- //
- ContainerRemote aTarget = null;
- java.rmi.RemoteException lastProblem = null;
-
- tick ();
-
- // this proxy must support concurrent invocations
- //
- while (true)
- {
- synchronized (crs)
- {
- aTarget = getRemoteTarget ();
- if (numberOfRegisteredRemoteTargets () == 0)
- throw ( (lastProblem==null)? new java.rmi.RemoteException
("No more valid HA SLSB home availble") : lastProblem );
- }
-
- try
- {
- return aTarget.invokeHome (new MarshalledObject (rmi)).get ();
- }
- catch (java.rmi.RemoteException e)
- {
- System.out.println ("A SLSB home target has failed with a
RemoteException");
- remoteTargetHasFailed (aTarget);
- lastProblem = e;
- }
- }
- }
- }
- }
+ container = proxy;
}
-
- public void writeExternal (java.io.ObjectOutput out)
- throws IOException
- {
- super.writeExternal (out);
-
- out.writeObject (ejbMetaData);
+
+ /**
+ * Externalization support.
+ *
+ * @param out
+ *
+ * @throws IOException
+ */
+ public void writeExternal(final ObjectOutput out)
+ throws IOException
+ {
+ out.writeUTF(name);
+ out.writeObject(container);
+ out.writeBoolean(optimize);
+ out.writeObject(initialContextHandle);
+ out.writeObject(ejbMetaData);
+ }
+
+ /**
+ * Externalization support.
+ *
+ * @param in
+ *
+ * @throws IOException
+ * @throws ClassNotFoundException
+ */
+ public void readExternal(final ObjectInput in)
+ throws IOException, ClassNotFoundException
+ {
+ name = in.readUTF();
+ container = (ContainerRemote)in.readObject();
+ optimize = in.readBoolean();
+ initialContextHandle = (InitialContextHandle)in.readObject();
+ ejbMetaData = (EJBMetaData)in.readObject();
}
-
- public void readExternal (java.io.ObjectInput in)
- throws IOException, ClassNotFoundException
+
+ // Package protected ---------------------------------------------
+
+ // Protected -----------------------------------------------------
+
+ /**
+ * Returns <code>true</code> iff this instance lives in the same
+ * VM as its container.
+ */
+ protected boolean isLocal()
{
- super.readExternal (in);
-
- ejbMetaData = (EJBMetaData)in.readObject ();
+ return ((HARMIProxy)container).isLocal();
}
- // Package protected ---------------------------------------------
-
- // Protected -----------------------------------------------------
-
// Private -------------------------------------------------------
-
+
// Inner classes -------------------------------------------------
}
_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development