dain 2005/12/17 06:02:08
Modified: modules/core/src/java/org/openejb Tag: v2_0
ContainerIndex.java
Log:
Fixed race condition between web applications and ejbs.
Revision Changes Path
No revision
No revision
1.17.2.1 +50 -6
openejb/modules/core/src/java/org/openejb/ContainerIndex.java
Index: ContainerIndex.java
===================================================================
RCS file:
/home/projects/openejb/scm/openejb/modules/core/src/java/org/openejb/ContainerIndex.java,v
retrieving revision 1.17
retrieving revision 1.17.2.1
diff -u -r1.17 -r1.17.2.1
--- ContainerIndex.java 1 Dec 2005 08:34:48 -0000 1.17
+++ ContainerIndex.java 17 Dec 2005 11:02:06 -0000 1.17.2.1
@@ -49,12 +49,18 @@
import java.util.HashMap;
import java.util.Iterator;
+import javax.management.ObjectName;
+import javax.management.MalformedObjectNameException;
+
import org.apache.geronimo.gbean.GBeanInfo;
import org.apache.geronimo.gbean.GBeanInfoBuilder;
import org.apache.geronimo.gbean.GBeanLifecycle;
import org.apache.geronimo.gbean.ReferenceCollection;
import org.apache.geronimo.gbean.ReferenceCollectionEvent;
import org.apache.geronimo.gbean.ReferenceCollectionListener;
+import org.apache.geronimo.kernel.Kernel;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
/**
@@ -69,6 +75,14 @@
return containerIndex;
}
+ private static final Log log = LogFactory.getLog(ContainerIndex.class);
+
+ /**
+ * The kernel in which this index is registered. This is only needed
due to the inability to control the order of
+ * notifications in the kernel.
+ */
+ private final Kernel kernel;
+
/**
* The container lookup table.
*/
@@ -90,9 +104,11 @@
private ReferenceCollection ejbContainers;
protected ContainerIndex() {
+ kernel = null;
}
- public ContainerIndex(Collection ejbContainers) {
+ public ContainerIndex(Collection ejbContainers, Kernel kernel) {
+ this.kernel = kernel;
ContainerIndex.containerIndex = this;
this.ejbContainers = (ReferenceCollection) ejbContainers;
this.ejbContainers.addReferenceCollectionListener(this);
@@ -181,7 +197,35 @@
public synchronized int getContainerIndex(String containerID) {
Integer index = (Integer) containerIdToIndex.get(containerID);
- return (index == null) ? -1 : index.intValue();
+
+ // try to fault in the container using the kernel directly
+ if ((index == null)) {
+ ObjectName name = null;
+ try {
+ name = new ObjectName(containerID);
+ } catch (MalformedObjectNameException e) {
+ log.error("contianerId is not a valid ObjectName: " +
containerID);
+ }
+ EJBContainer ejbContainer = null;
+ try {
+ ejbContainer = (EJBContainer)
kernel.getProxyManager().createProxy(name, EJBContainer.class);
+ } catch (Exception e) {
+ // couldn't find the container
+ log.debug("Container not found: " + containerID, e);
+ return -1;
+ }
+ addContainer(ejbContainer);
+ index = (Integer) containerIdToIndex.get(containerID);
+ if (index == null) {
+ log.error("added ejb container to index but index value was
null: " + containerID);
+ }
+ }
+
+ if (index == null) {
+ return -1;
+ } else {
+ return index.intValue();
+ }
}
public synchronized int getContainerIndexByJndiName(String jndiName) {
@@ -214,7 +258,9 @@
static {
GBeanInfoBuilder infoFactory =
GBeanInfoBuilder.createStatic(ContainerIndex.class); //name apparently hardcoded
- infoFactory.setConstructor(new String[]{"EJBContainers"});
+ infoFactory.addReference("EJBContainers", EJBContainer.class);//many
types, specify type in patterns
+ infoFactory.addAttribute("kernel", Kernel.class, false);
+ infoFactory.setConstructor(new String[]{"EJBContainers", "kernel"});
infoFactory.addOperation("getContainerIndex", new
Class[]{Object.class});
infoFactory.addOperation("getContainerIndex", new
Class[]{String.class});
@@ -223,8 +269,6 @@
infoFactory.addOperation("getContainer", new Class[]{Integer.class});
infoFactory.addOperation("getContainer", new Class[]{Integer.TYPE});
infoFactory.addOperation("getContainerByJndiName", new
Class[]{String.class});
-
- infoFactory.addReference("EJBContainers", EJBContainer.class);//many
types, specify type in patterns
GBEAN_INFO = infoFactory.getBeanInfo();
}