dain 2004/04/09 15:04:00
Modified: modules/core/src/java/org/openejb
AbstractContainerBuilder.java ContainerBuilder.java
ContainerIndex.java EJBContainer.java
GenericEJBContainer.java OpenEJBException.java
Log:
Added jndi naming bindings
Fixed many problems with ContainerIndex GBean
Converted EJB protocol stack to GBeans
Cleaned up code formating of several classes
Revision Changes Path
1.6 +30 -8
openejb/modules/core/src/java/org/openejb/AbstractContainerBuilder.java
Index: AbstractContainerBuilder.java
===================================================================
RCS file:
/home/projects/openejb/scm/openejb/modules/core/src/java/org/openejb/AbstractContainerBuilder.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- AbstractContainerBuilder.java 6 Apr 2004 18:41:45 -0000 1.5
+++ AbstractContainerBuilder.java 9 Apr 2004 19:04:00 -0000 1.6
@@ -89,6 +89,8 @@
private Set unshareableResources;
private UserTransactionImpl userTransaction;
private TransactionPolicySource transactionPolicySource;
+ private String[] jndiNames;
+ private String[] localJndiNames;
private TransactionManager transactionManager;
private TrackedConnectionAssociator trackedConnectionAssociator;
@@ -204,6 +206,22 @@
this.transactionPolicySource = transactionPolicySource;
}
+ public String[] getJndiNames() {
+ return jndiNames;
+ }
+
+ public void setJndiNames(String[] jndiNames) {
+ this.jndiNames = jndiNames;
+ }
+
+ public String[] getLocalJndiNames() {
+ return localJndiNames;
+ }
+
+ public void setLocalJndiNames(String[] localJndiNames) {
+ this.localJndiNames = localJndiNames;
+ }
+
public TransactionManager getTransactionManager() {
return transactionManager;
}
@@ -289,6 +307,8 @@
interceptorBuilder,
pool,
getUserTransaction(),
+ getJndiNames(),
+ getLocalJndiNames(),
getTransactionManager(),
getTrackedConnectionAssociator());
}
@@ -300,13 +320,15 @@
InstancePool pool) throws Exception {
GBeanMBean gbean = new GBeanMBean(GenericEJBContainer.GBEAN_INFO);
- gbean.setAttribute("containerId", getContainerId());
- gbean.setAttribute("ejbName", getEJBName());
- gbean.setAttribute("proxyFactory", proxyFactory);
- gbean.setAttribute("signatures", signatures);
- gbean.setAttribute("interceptorBuilder", interceptorBuilder);
- gbean.setAttribute("pool", pool);
- gbean.setAttribute("userTransaction", getUserTransaction());
+ gbean.setAttribute("ContainerID", getContainerId());
+ gbean.setAttribute("EJBName", getEJBName());
+ gbean.setAttribute("ProxyFactory", proxyFactory);
+ gbean.setAttribute("Signatures", signatures);
+ gbean.setAttribute("InterceptorBuilder", interceptorBuilder);
+ gbean.setAttribute("Pool", pool);
+ gbean.setAttribute("UserTransaction", getUserTransaction());
+ gbean.setAttribute("JndiNames", getJndiNames());
+ gbean.setAttribute("LocalJndiNames", getLocalJndiNames());
return gbean;
}
1.3 +9 -1 openejb/modules/core/src/java/org/openejb/ContainerBuilder.java
Index: ContainerBuilder.java
===================================================================
RCS file:
/home/projects/openejb/scm/openejb/modules/core/src/java/org/openejb/ContainerBuilder.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ContainerBuilder.java 6 Apr 2004 00:43:06 -0000 1.2
+++ ContainerBuilder.java 9 Apr 2004 19:04:00 -0000 1.3
@@ -97,6 +97,14 @@
void setTrackedConnectionAssociator(TrackedConnectionAssociator
trackedConnectionAssociator);
+ String[] getJndiNames();
+
+ void setJndiNames(String[] jndiNames);
+
+ String[] getLocalJndiNames();
+
+ void setLocalJndiNames(String[] localJndiNames);
+
EJBContainer createContainer() throws Exception;
GBeanMBean createConfiguration() throws Exception;
1.5 +48 -13 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.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- ContainerIndex.java 6 Apr 2004 19:37:06 -0000 1.4
+++ ContainerIndex.java 9 Apr 2004 19:04:00 -0000 1.5
@@ -78,14 +78,19 @@
/**
* Index from the container id to the index (Integer) number in the containers
lookup table
*/
- private final HashMap index = new HashMap();
+ private final HashMap containerIdToIndex = new HashMap();
+
+ /**
+ * Index from jndi name to the index (Integer) number in the containers lookup
table
+ */
+ private final HashMap jndiNameToIndex = new HashMap();
/**
* GBean reference collection that we watch for new containers to register
*/
private ReferenceCollection ejbContainers;
- private ContainerIndex() {
+ protected ContainerIndex() {
}
public ContainerIndex(Collection ejbContainers) {
@@ -102,23 +107,36 @@
for (int i = 1; i < containers.length && iterator.hasNext(); i++) {
EJBContainer container = (EJBContainer) iterator.next();
containers[i] = container;
- index.put(container.getContainerID(), new Integer(i));
+ containerIdToIndex.put(container.getContainerID(), new Integer(i));
+ addJNDINames(container, i);
+ }
+ }
+
+ private void addJNDINames(EJBContainer container, int i) {
+ String[] jnidNames = container.getJndiNames();
+ if(jnidNames != null) {
+ for (int j = 0; j < jnidNames.length; j++) {
+ String jnidName = jnidNames[j];
+ jndiNameToIndex.put(jnidName, new Integer(i));
+ }
}
}
public void doStop() throws WaitingException, Exception {
- index.clear();
+ containerIdToIndex.clear();
Arrays.fill(containers, null);
+ jndiNameToIndex.clear();
}
public void doFail() {
- index.clear();
+ containerIdToIndex.clear();
Arrays.fill(containers, null);
+ jndiNameToIndex.clear();
}
public synchronized void addContainer(EJBContainer container) {
Object containerID = container.getContainerID();
- if(index.containsKey(containerID)) {
+ if(containerIdToIndex.containsKey(containerID)) {
return;
}
@@ -129,13 +147,20 @@
containers = newArray;
containers[i] = container;
- index.put(containerID, new Integer(i));
+ containerIdToIndex.put(containerID, new Integer(i));
+ addJNDINames(container, i);
}
public synchronized void removeContainer(EJBContainer container) {
- int i = getContainerIndex(container.getContainerID());
- if(i > 0) {
- containers[i] = null;
+ Integer index = (Integer)
containerIdToIndex.remove(container.getContainerID());
+ if(index != null) {
+ containers[index.intValue()] = null;
+ }
+
+ String[] jnidNames = container.getJndiNames();
+ for (int i = 0; i < jnidNames.length; i++) {
+ String jnidName = jnidNames[i];
+ jndiNameToIndex.remove(jnidName);
}
}
@@ -156,9 +181,13 @@
}
public synchronized int getContainerIndex(String containerID) {
- Integer idCode = (Integer) index.get(containerID);
+ Integer index = (Integer) containerIdToIndex.get(containerID);
+ return (index == null) ? -1 : index.intValue();
+ }
- return (idCode == null) ? -1 : idCode.intValue();
+ public synchronized int getContainerIndexByJndiName(String jndiName) {
+ Integer index = (Integer) jndiNameToIndex.get(jndiName);
+ return (index == null) ? -1 : index.intValue();
}
public synchronized EJBContainer getContainer(String containerID) {
@@ -169,6 +198,10 @@
return (index == null) ? null : getContainer(index.intValue());
}
+ public synchronized EJBContainer getContainerByJndiName(String jndiName) {
+ return getContainer(getContainerIndexByJndiName(jndiName));
+ }
+
public synchronized EJBContainer getContainer(int index) {
return containers[index];
}
@@ -184,9 +217,11 @@
infoFactory.addOperation("getContainerIndex", new Class[]{Object.class});
infoFactory.addOperation("getContainerIndex", new Class[]{String.class});
+ infoFactory.addOperation("getContainerIndexByJndiName", new
Class[]{String.class});
infoFactory.addOperation("getContainer", new Class[]{String.class});
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);
1.3 +11 -1 openejb/modules/core/src/java/org/openejb/EJBContainer.java
Index: EJBContainer.java
===================================================================
RCS file:
/home/projects/openejb/scm/openejb/modules/core/src/java/org/openejb/EJBContainer.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- EJBContainer.java 21 Mar 2004 21:26:34 -0000 1.2
+++ EJBContainer.java 9 Apr 2004 19:04:00 -0000 1.3
@@ -55,6 +55,8 @@
import org.apache.geronimo.core.service.Interceptor;
+import org.openejb.proxy.EJBProxyFactory;
+
/**
* Interface exposed by server side EJB Containers to allow the interceptor
* stack to interact with them.
@@ -118,4 +120,12 @@
* @throws Throwable if a problem occurs while calling the bean
*/
Object invoke(Method callMethod, Object[] args, Object primKey) throws
Throwable;
+
+ String[] getJndiNames();
+
+ String[] getLocalJndiNames();
+
+ EJBProxyFactory getProxyFactory();
+
+ ClassLoader getClassLoader();
}
1.6 +55 -20
openejb/modules/core/src/java/org/openejb/GenericEJBContainer.java
Index: GenericEJBContainer.java
===================================================================
RCS file:
/home/projects/openejb/scm/openejb/modules/core/src/java/org/openejb/GenericEJBContainer.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- GenericEJBContainer.java 6 Apr 2004 18:41:45 -0000 1.5
+++ GenericEJBContainer.java 9 Apr 2004 19:04:00 -0000 1.6
@@ -78,6 +78,7 @@
* @version $Revision$ $Date$
*/
public class GenericEJBContainer implements EJBContainer {
+ private final ClassLoader classLoader;
private final Object containerId;
private final String ejbName;
@@ -86,6 +87,9 @@
private final Map legacyMethodMap;
+ private final String[] jndiNames;
+ private final String[] localJndiNames;
+
public GenericEJBContainer(
Object containerId,
String ejbName,
@@ -94,6 +98,8 @@
InterceptorBuilder interceptorBuilder,
InstancePool pool,
UserTransactionImpl userTransaction,
+ String[] jndiNames,
+ String[] localJndiNames,
TransactionManager transactionManager,
TrackedConnectionAssociator trackedConnectionAssociator) throws
Exception {
@@ -101,11 +107,17 @@
assert (ejbName != null && ejbName.length() > 0);
assert (signatures != null);
assert (interceptorBuilder != null);
+ assert (jndiNames != null);
+ assert (localJndiNames != null);
assert (pool != null);
assert (transactionManager != null);
+ this.classLoader = Thread.currentThread().getContextClassLoader();
+ assert (classLoader != null);
this.containerId = containerId;
this.ejbName = ejbName;
+ this.jndiNames = copyNames(jndiNames);
+ this.localJndiNames = copyNames(localJndiNames);
// initialize the proxy factory
proxyFactory.setContainer(this);
@@ -185,6 +197,10 @@
}
}
+ public ClassLoader getClassLoader() {
+ return classLoader;
+ }
+
public Object getContainerID() {
return containerId;
}
@@ -193,20 +209,32 @@
return ejbName;
}
+ public String[] getJndiNames() {
+ return copyNames(jndiNames);
+ }
+
+ public String[] getLocalJndiNames() {
+ return copyNames(localJndiNames);
+ }
+
public EJBHome getEJBHome() {
- return getProxyFactory().getEJBHome();
+ return proxyFactory.getEJBHome();
}
public EJBObject getEJBObject(Object primaryKey) {
- return getProxyFactory().getEJBObject(primaryKey);
+ return proxyFactory.getEJBObject(primaryKey);
}
public EJBLocalHome getEJBLocalHome() {
- return getProxyFactory().getEJBLocalHome();
+ return proxyFactory.getEJBLocalHome();
}
public EJBLocalObject getEJBLocalObject(Object primaryKey) {
- return getProxyFactory().getEJBLocalObject(primaryKey);
+ return proxyFactory.getEJBLocalObject(primaryKey);
+ }
+
+ public EJBProxyFactory getProxyFactory() {
+ return proxyFactory;
}
private static void addLegacyMethods(Map legacyMethodMap, Class clazz,
InterfaceMethodSignature[] signatures) {
@@ -223,6 +251,15 @@
}
}
+ private static String[] copyNames(String[] names) {
+ if(names == null) {
+ return null;
+ }
+ int length = names.length;
+ String[] copy = new String[length];
+ System.arraycopy(names, 0, copy, 0, length);
+ return copy;
+ }
public static final GBeanInfo GBEAN_INFO;
@@ -230,18 +267,20 @@
GBeanInfoFactory infoFactory = new
GBeanInfoFactory(GenericEJBContainer.class);
infoFactory.setConstructor(
- new String[]{"containerId", "ejbName", "proxyFactory",
"signatures", "interceptorBuilder", "pool", "userTransaction", "transactionManager",
"trackedConnectionAssociator"},
- new Class[]{Object.class, String.class, EJBProxyFactory.class,
InterfaceMethodSignature[].class, InterceptorBuilder.class, InstancePool.class,
UserTransactionImpl.class, TransactionManager.class,
TrackedConnectionAssociator.class});
+ new String[]{"ContainerID", "EJBName", "ProxyFactory",
"Signatures", "InterceptorBuilder", "Pool", "UserTransaction", "JndiNames",
"LocalJndiNames", "TransactionManager", "TrackedConnectionAssociator"},
+ new Class[]{Object.class, String.class, EJBProxyFactory.class,
InterfaceMethodSignature[].class, InterceptorBuilder.class, InstancePool.class,
UserTransactionImpl.class, String[].class, String[].class, TransactionManager.class,
TrackedConnectionAssociator.class});
- infoFactory.addAttribute("containerId", true);
- infoFactory.addAttribute("ejbName", true);
- infoFactory.addAttribute("proxyFactory", true);
- infoFactory.addAttribute("signatures", true);
- infoFactory.addAttribute("interceptorBuilder", true);
- infoFactory.addAttribute("pool", true);
- infoFactory.addAttribute("userTransaction", true);
- infoFactory.addReference("transactionManager", TransactionManager.class);
- infoFactory.addReference("trackedConnectionAssociator",
TrackedConnectionAssociator.class);
+ infoFactory.addAttribute("ContainerID", true);
+ infoFactory.addAttribute("EJBName", true);
+ infoFactory.addAttribute("ProxyFactory", true);
+ infoFactory.addAttribute("Signatures", true);
+ infoFactory.addAttribute("InterceptorBuilder", true);
+ infoFactory.addAttribute("Pool", true);
+ infoFactory.addAttribute("UserTransaction", true);
+ infoFactory.addAttribute("JndiNames", true);
+ infoFactory.addAttribute("LocalJndiNames", true);
+ infoFactory.addReference("TransactionManager", TransactionManager.class);
+ infoFactory.addReference("TrackedConnectionAssociator",
TrackedConnectionAssociator.class);
infoFactory.addAttribute("EJBHome", false);
infoFactory.addAttribute("EJBLocalHome", false);
@@ -253,8 +292,4 @@
public static GBeanInfo getGBeanInfo() {
return GBEAN_INFO;
}
-
- protected EJBProxyFactory getProxyFactory() {
- return proxyFactory;
- }
}
1.2 +48 -48 openejb/modules/core/src/java/org/openejb/OpenEJBException.java
Index: OpenEJBException.java
===================================================================
RCS file:
/home/projects/openejb/scm/openejb/modules/core/src/java/org/openejb/OpenEJBException.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- OpenEJBException.java 1 Mar 2004 07:14:42 -0000 1.1
+++ OpenEJBException.java 9 Apr 2004 19:04:00 -0000 1.2
@@ -44,8 +44,6 @@
*/
package org.openejb;
-import java.io.PrintStream;
-import java.io.PrintWriter;
/**
* The OpenEJBException is the standard exception thrown by all methods in all type
in the
@@ -73,7 +71,7 @@
* thrown within the container (not by a bean) is are good examples. The
org.openejb.SystemException represents a
* serious problem with the Container. The Container should be shut down and
not used for any more processing.
* </ul>
- *
+ *
* @version $Revision$ $Date$
* @see ApplicationException
* @see InvalidateReferenceException
@@ -83,12 +81,12 @@
public class OpenEJBException extends Exception {
/** Error code for unknown errors */
- private String message = "error.unknown";
+// private String message = "error.unknown";
/** Stored <code>Exception</code> for root cause */
- private Throwable rootCause;
+// private Throwable rootCause;
- /**
+ /**
* <p>
* Default constructor, which simply delegates exception
* handling up the inheritance chain to <code>Exception</code>.
@@ -98,7 +96,7 @@
super();
}
- /**
+ /**
* <p>
* This constructor allows a message to be supplied indicating the source
* of the problem that occurred.
@@ -107,8 +105,8 @@
* @param message <code>String</code> identifying the cause of the problem.
*/
public OpenEJBException(String message) {
- super( message );
- this.message = message;
+ super(message);
+// this.message = message;
}
/**
@@ -120,7 +118,8 @@
* @param rootCause <code>Throwable</code> that triggered the problem.
*/
public OpenEJBException(Throwable rootCause) {
- this.rootCause = rootCause;
+ super(rootCause);
+// this.rootCause = rootCause;
}
/**
@@ -128,31 +127,31 @@
* problem that occurred as well as a "root cause" exception
* to be supplied, which may later be used by the wrapping
* application.
- *
+ *
* @param message <code>String</code> identifying the cause of the problem.
* @param rootCause <code>Throwable</code> that triggered this problem.
*/
public OpenEJBException(String message, Throwable rootCause) {
- this( message );
- this.rootCause = rootCause;
+ super(message, rootCause);
+// this.rootCause = rootCause;
}
/**
* <p>
- * This returns the message for the <code>Exception</code>. If there is
+ * This returns the message for the <code>Exception</code>. If there is
* a root cause, the message associated with the root cause
* is appended.
* </p>
*
* @return <code>String</code> - message for this <code>Exception</code>.
*/
- public String getMessage() {
- if (rootCause != null) {
- return super.getMessage() + ": " + rootCause.getMessage();
- } else {
- return super.getMessage();
- }
- }
+// public String getMessage() {
+// if (rootCause != null) {
+// return super.getMessage() + ": " + rootCause.getMessage();
+// } else {
+// return super.getMessage();
+// }
+// }
/**
* <p>
@@ -161,13 +160,13 @@
* is printed right after.
* </p>
*/
- public void printStackTrace() {
- super.printStackTrace();
- if (rootCause != null) {
- System.err.println("Root cause: ");
- rootCause.printStackTrace();
- }
- }
+// public void printStackTrace() {
+// super.printStackTrace();
+// if (rootCause != null) {
+// System.err.println("Root cause: ");
+// rootCause.printStackTrace();
+// }
+// }
/**
* <p>
@@ -178,14 +177,14 @@
*
* @param stream <code>PrintStream</code> to print stack trace to.
*/
- public void printStackTrace(PrintStream stream) {
- super.printStackTrace(stream);
- if (rootCause != null) {
- stream.print("Root cause: ");
- rootCause.printStackTrace(stream);
- }
- }
-
+// public void printStackTrace(PrintStream stream) {
+// super.printStackTrace(stream);
+// if (rootCause != null) {
+// stream.print("Root cause: ");
+// rootCause.printStackTrace(stream);
+// }
+// }
+
/**
* <p>
* This prints the stack trace of the <code>Exception</code>. If there is
@@ -195,13 +194,13 @@
*
* @param writer <code>PrintWriter</code> to print stack trace to.
*/
- public void printStackTrace(PrintWriter writer) {
- super.printStackTrace(writer);
- if (rootCause != null) {
- writer.print("Root cause: ");
- rootCause.printStackTrace(writer);
- }
- }
+// public void printStackTrace(PrintWriter writer) {
+// super.printStackTrace(writer);
+// if (rootCause != null) {
+// writer.print("Root cause: ");
+// rootCause.printStackTrace(writer);
+// }
+// }
/**
* <p>
@@ -211,8 +210,9 @@
*
* @return <code>Throwable</code> - the wrapped <code>Throwable</code>.
*/
- public Throwable getRootCause() {
- return rootCause;
- }
+// public Throwable getRootCause() {
+// super.getCause();
+// return rootCause;
+// }
}