User: oberg
Date: 00/06/16 06:10:22
Modified: src/main/org/jboss/ejb Application.java Container.java
ContainerFactory.java ContainerFactoryMBean.java
EntityContainer.java Interceptor.java
StatefulSessionContainer.java
StatelessSessionContainer.java
Added: src/main/org/jboss/ejb ContainerInvokerContainer.java
InstancePoolContainer.java MethodInvocation.java
Log:
Added configuration service
Changed interceptors to be messagebased
Added mini webserver
Changed server bootstrap process
Revision Changes Path
1.4 +49 -1 jboss/src/main/org/jboss/ejb/Application.java
Index: Application.java
===================================================================
RCS file: /products/cvs/ejboss/jboss/src/main/org/jboss/ejb/Application.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- Application.java 2000/05/30 18:32:15 1.3
+++ Application.java 2000/06/16 13:10:19 1.4
@@ -7,9 +7,12 @@
package org.jboss.ejb;
import java.net.URL;
+import java.util.Iterator;
import java.util.Collection;
import java.util.HashMap;
+import org.jboss.util.Service;
+
/**
* An Application represents a collection of beans that are deployed as a unit.
* The beans may use the Application to access other beans within the same
deployment unit
@@ -17,9 +20,10 @@
* @see Container
* @see ContainerFactory
* @author Rickard �berg ([EMAIL PROTECTED])
- * @version $Revision: 1.3 $
+ * @version $Revision: 1.4 $
*/
public class Application
+ implements Service
{
// Constants -----------------------------------------------------
@@ -41,6 +45,7 @@
public void addContainer(Container con)
{
containers.put(con.getMetaData().getEjbName(), con);
+ con.setApplication(this);
}
@@ -125,4 +130,47 @@
if (name.equals(""))
name = url.toString();
}
+
+ // Service implementation ----------------------------------------
+ public void init()
+ throws Exception
+ {
+ Iterator enum = containers.values().iterator();
+ while (enum.hasNext())
+ {
+ Container con = (Container)enum.next();
+ con.init();
+ }
+ }
+
+ public void start()
+ throws Exception
+ {
+ Iterator enum = containers.values().iterator();
+ while (enum.hasNext())
+ {
+ Container con = (Container)enum.next();
+ con.start();
+ }
+ }
+
+ public void stop()
+ {
+ Iterator enum = containers.values().iterator();
+ while (enum.hasNext())
+ {
+ Container con = (Container)enum.next();
+ con.stop();
+ }
+ }
+
+ public void destroy()
+ {
+ Iterator enum = containers.values().iterator();
+ while (enum.hasNext())
+ {
+ Container con = (Container)enum.next();
+ con.destroy();
+ }
+ }
}
1.14 +14 -126 jboss/src/main/org/jboss/ejb/Container.java
Index: Container.java
===================================================================
RCS file: /products/cvs/ejboss/jboss/src/main/org/jboss/ejb/Container.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- Container.java 2000/06/04 23:19:00 1.13
+++ Container.java 2000/06/16 13:10:19 1.14
@@ -63,7 +63,7 @@
* @see ContainerFactory
* @author Rickard �berg ([EMAIL PROTECTED])
* @author <a href="[EMAIL PROTECTED]">Marc Fleury</a>
- * @version $Revision: 1.13 $
+ * @version $Revision: 1.14 $
*/
public abstract class Container
{
@@ -80,13 +80,7 @@
// This is the jBoss-specific metadata. Note that it extends the generic EJB
1.1 class from EJX
protected jBossEnterpriseBean metaData;
-
- // This is the instancepool that is to be used
- protected InstancePool instancePool;
-
- // This is the first interceptor in the chain. The last interceptor must be
provided by the container itself
- protected Interceptor interceptor;
-
+
// This is the Home interface class
protected Class homeInterface;
@@ -98,18 +92,14 @@
// This is the TransactionManager
protected TransactionManager tm;
-
- // These are the mappings between the home interface methods and the container
methods
- protected Map homeMapping;
-
- // These are the mappings between the remote interface methods and the bean
methods
- protected Map beanMapping;
-
- // This is the container invoker for this container
- protected ContainerInvoker containerInvoker;
-
+
// Public --------------------------------------------------------
+ public void setTransactionManager(TransactionManager tm)
+ {
+ this.tm = tm;
+ }
+
public TransactionManager getTransactionManager()
{
return tm;
@@ -121,7 +111,6 @@
throw new IllegalArgumentException("Null application");
application = app;
- app.addContainer(this);
}
public Application getApplication()
@@ -147,61 +136,8 @@
public jBossEnterpriseBean getMetaData()
{
return metaData;
- }
-
- public void setInstancePool(InstancePool ip)
- {
- if (ip == null)
- throw new IllegalArgumentException("Null pool");
-
- this.instancePool = ip;
- ip.setContainer(this);
- }
-
- public InstancePool getInstancePool()
- {
- return instancePool;
- }
-
-
- public ContainerInvoker getContainerInvoker()
- {
- return containerInvoker;
- }
-
- public void addInterceptor(Interceptor in)
- {
- if (interceptor == null)
- {
- interceptor = in;
- } else
- {
-
- Interceptor current = interceptor;
- while ( current.getNext() != null)
- {
- current = current.getNext();
- }
-
- current.setNext(in);
- }
- }
-
- public Interceptor getInterceptor()
- {
- return interceptor;
- }
-
- public Class getHomeClass()
- {
- return homeInterface;
- }
-
- public Class getRemoteClass()
- {
- return remoteInterface;
- }
-
+ }
+
public Class getBeanClass()
{
return beanClass;
@@ -218,70 +154,23 @@
throws Exception
{
// Acquire classes from CL
- homeInterface = classLoader.loadClass(metaData.getHome());
- remoteInterface = classLoader.loadClass(metaData.getRemote());
beanClass = classLoader.loadClass(metaData.getEjbClass());
- // Get transaction manager
- tm = (TransactionManager)new
InitialContext().lookup("TransactionManager");
-
// Setup "java:" namespace
- setupEnvironment();
-
- // Initialize pool
- instancePool.init();
-
- // Initialize the interceptor by calling the chain
- Interceptor in = interceptor;
- while (in != null)
- {
- in.setContainer(this);
- in.init();
- in = in.getNext();
- }
+ setupEnvironment();
}
public void start()
throws Exception
{
- // Start the instance pool
- instancePool.start();
-
- // Start all interceptors in the chain
- Interceptor in = interceptor;
- while (in != null)
- {
- in.start();
- in = in.getNext();
- }
}
public void stop()
{
- // Stop the instance pool
- instancePool.stop();
-
- // Stop all interceptors in the chain
- Interceptor in = interceptor;
- while (in != null)
- {
- in.stop();
- in = in.getNext();
- }
}
public void destroy()
{
- // Destroy the pool
- instancePool.destroy();
-
- // Destroy all the interceptors in the chain
- Interceptor in = interceptor;
- while (in != null)
- {
- in.destroy();
- in = in.getNext();
- }
}
/**
@@ -289,12 +178,11 @@
*
* The Container forwards this call to the interceptor chain for further
processing.
*
- * @param method the method being invoked
- * @param args the parameters
+ * @param mi the object holding all info about this invocation
* @return the result of the home invocation
* @exception Exception
*/
- public abstract Object invokeHome(Method method, Object[] args)
+ public abstract Object invokeHome(MethodInvocation mi)
throws Exception;
/**
@@ -308,7 +196,7 @@
* @return the result of the invocation
* @exception Exception
*/
- public abstract Object invoke(Object id, Method method, Object[] args)
+ public abstract Object invoke(MethodInvocation mi)
throws Exception;
// Protected -----------------------------------------------------
1.21 +134 -217 jboss/src/main/org/jboss/ejb/ContainerFactory.java
Index: ContainerFactory.java
===================================================================
RCS file: /products/cvs/ejboss/jboss/src/main/org/jboss/ejb/ContainerFactory.java,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -r1.20 -r1.21
--- ContainerFactory.java 2000/06/11 18:17:14 1.20
+++ ContainerFactory.java 2000/06/16 13:10:19 1.21
@@ -47,7 +47,7 @@
import org.jboss.logging.ConsoleLoggingMBean;
import org.jboss.util.MBeanProxy;
-import org.jboss.web.WebProviderMBean;
+import org.jboss.web.WebServiceMBean;
import org.jboss.ejb.plugins.*;
@@ -66,10 +66,11 @@
* @author <a href="mailto:[EMAIL PROTECTED]">Marc Fleury</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Juha Lindfors</a>
*
-* @version $Revision: 1.20 $
+* @version $Revision: 1.21 $
*/
public class ContainerFactory
-implements ContainerFactoryMBean, MBeanRegistration
+ extends org.jboss.util.ServiceMBeanSupport
+ implements ContainerFactoryMBean
{
// Constants -----------------------------------------------------
public static String DEFAULT_STATELESS_CONFIGURATION = "Default Stateless
SessionBean";
@@ -79,16 +80,58 @@
// Attributes ----------------------------------------------------
// The logger of this service
- Log log = new Log("Container factory");
+ Log log = new Log(getName());
- // The JMX agent
- MBeanServer server;
-
// A map of current deployments. If a deployment is made and it is already in
this map,
// then undeploy it first (i.e. make it a re-deploy).
HashMap deployments = new HashMap();
+ // Verify EJB-jar contents on deployments
+ boolean verifyDeployments = false;
+
// Public --------------------------------------------------------
+ public ObjectName getObjectName(MBeanServer server, ObjectName name)
+ throws javax.management.MalformedObjectNameException
+ {
+ return new ObjectName(OBJECT_NAME);
+ }
+
+ public String getName()
+ {
+ return "Container factory";
+ }
+
+ public void stopService()
+ {
+ Iterator apps = deployments.values().iterator();
+ while (apps.hasNext())
+ {
+ Application app = (Application)apps.next();
+ app.stop();
+ }
+ }
+
+ public void destroyService()
+ {
+ Iterator apps = deployments.values().iterator();
+ while (apps.hasNext())
+ {
+ Application app = (Application)apps.next();
+ app.destroy();
+ }
+
+ deployments.clear();
+ }
+
+ public void setVerifyDeployments(boolean verify)
+ {
+ verifyDeployments = verify;
+ }
+
+ public boolean getVerifyDeployments()
+ {
+ return verifyDeployments;
+ }
/**
* Deploy the file at this URL. This method is typically called from
remote administration
@@ -99,7 +142,7 @@
* @exception DeploymentException
*/
public void deploy(String url)
- throws MalformedURLException, DeploymentException
+ throws MalformedURLException, DeploymentException
{
// Delegate to "real" deployment
deploy(new URL(url));
@@ -115,7 +158,7 @@
* @exception DeploymentException
*/
public void undeploy(String url)
- throws MalformedURLException, DeploymentException
+ throws MalformedURLException, DeploymentException
{
// Delegate to "real" undeployment
undeploy(new URL(url));
@@ -133,8 +176,11 @@
* @exception DeploymentException
*/
public synchronized void deploy(URL url)
- throws DeploymentException
+ throws DeploymentException
{
+ // Create application
+ Application app = new Application();
+
try
{
Log.setLog(log);
@@ -143,24 +189,22 @@
if (deployments.containsKey(url))
undeploy(url);
- // [JPL] for now, use verifier only for testing..
- boolean useVerifier = Boolean.getBoolean("jboss.verifier.isEnabled");
-
- if (useVerifier) {
- BeanVerifier verifier = new BeanVerifier();
-
- verifier.addVerificationListener(new VerificationListener() {
-
- public void beanChecked(VerificationEvent event) {
- System.out.println(event.getMessage());
- }
- });
-
- verifier.verify(url);
- }
+ // Check validity
+ if (verifyDeployments)
+ {
+ BeanVerifier verifier = new BeanVerifier();
+
+ verifier.addVerificationListener(new VerificationListener()
+ {
+ public void beanChecked(VerificationEvent event)
+ {
+ System.out.println(event.getMessage());
+ }
+ });
+
+ verifier.verify(url);
+ }
- // Create application
- Application app = new Application();
app.setURL(url);
log.log("Deploying:"+url);
@@ -188,20 +232,16 @@
}
// Create classloader for this application
- // ClassLoader cl = new EJBClassLoader(new URL[]
{url}, getClass().getClassLoader(), jar.isSecure());
+// ClassLoader cl = new EJBClassLoader(new URL[] {url}, null,
jar.isSecure());
ClassLoader cl = efm.getClassLoader();
// Get list of beans for which we will create containers
Iterator beans = jar.getEnterpriseBeans().iterator();
- // Create list of containers
- ArrayList containers = new ArrayList();
-
// Deploy beans
Context ctx = new InitialContext();
while(beans.hasNext())
{
- Container con = null;
jBossEnterpriseBean bean =
(jBossEnterpriseBean)beans.next();
log.log("Deploying "+bean.getEjbName());
@@ -211,16 +251,16 @@
if
(((jBossSession)bean).getSessionType().equals("Stateless")) // Is stateless?
{
// Create container
- con = new StatelessSessionContainer();
+ StatelessSessionContainer container =
new StatelessSessionContainer();
// Create classloader for this
container
- con.setClassLoader(new
BeanClassLoader(cl));
+ container.setClassLoader(new
BeanClassLoader(cl));
// Set metadata
- con.setMetaData(bean);
+ container.setMetaData(bean);
// Get container configuration
- ContainerConfiguration conf =
jar.getContainerConfigurations().getContainerConfiguration(bean.getConfigurationName());
+ ContainerConfiguration conf =
bean.getContainerConfiguration();
// Make sure we have a default
configuration
if (conf == null)
@@ -235,25 +275,23 @@
}
// Set container invoker
-
((StatelessSessionContainer)con).setContainerInvoker((ContainerInvoker)cl.loadClass(conf.getContainerInvoker()).newInstance());
+
container.setContainerInvoker((ContainerInvoker)cl.loadClass(conf.getContainerInvoker()).newInstance());
// Set instance pool
-
con.setInstancePool((InstancePool)cl.loadClass(conf.getInstancePool()).newInstance());
+
container.setInstancePool((InstancePool)cl.loadClass(conf.getInstancePool()).newInstance());
// Create interceptors
-
- //
con.addInterceptor(new LogInterceptor());
- //
con.addInterceptor(new SecurityInterceptor());
- //
con.addInterceptor(new TxInterceptor());
- con.addInterceptor(new
StatelessSessionInstanceInterceptor());
+ container.addInterceptor(new
LogInterceptor());
+ container.addInterceptor(new
SecurityInterceptor());
+ container.addInterceptor(new
TxInterceptor());
+ container.addInterceptor(new
StatelessSessionInstanceInterceptor());
// Finally we add the last interceptor
from the container
-
con.addInterceptor(con.createContainerInterceptor());
+
container.addInterceptor(container.createContainerInterceptor());
// Add container to application
- containers.add(con);
-
+ app.addContainer(container);
} else // Stateful
{
boolean implemented = false;
@@ -261,16 +299,16 @@
//if (!implemented) throw new
Error("Stateful Container not implemented yet");
// Create container
- con = new StatefulSessionContainer();
+ StatefulSessionContainer container =
new StatefulSessionContainer();
// Create classloader for this
container
- con.setClassLoader(new
BeanClassLoader(cl));
+ container.setClassLoader(new
BeanClassLoader(cl));
// Set metadata
- con.setMetaData(bean);
+ container.setMetaData(bean);
// Get container configuration
- ContainerConfiguration conf =
jar.getContainerConfigurations().getContainerConfiguration(bean.getConfigurationName());
+ ContainerConfiguration conf =
bean.getContainerConfiguration();
// Make sure we have a default
configuration
if (conf == null)
@@ -284,43 +322,41 @@
}
// Set container invoker
-
((StatefulSessionContainer)con).setContainerInvoker((ContainerInvoker)cl.loadClass(conf.getContainerInvoker()).newInstance());
+
container.setContainerInvoker((ContainerInvoker)cl.loadClass(conf.getContainerInvoker()).newInstance());
// Set instance cache
-
((StatefulSessionContainer)con).setInstanceCache((InstanceCache)cl.loadClass(conf.getInstanceCache()).newInstance());
-
- // Set persistence manager
-
((StatefulSessionContainer)con).setPersistenceManager((StatefulSessionPersistenceManager)cl.loadClass(conf.getPersistenceManager()).newInstance());
+
container.setInstanceCache((InstanceCache)cl.loadClass(conf.getInstanceCache()).newInstance());
- // Set instance pools (this is bogus
anyway) should be set through default stuff
-
con.setInstancePool((InstancePool)cl.loadClass("org.jboss.ejb.plugins.StatefulSessionInstancePool").newInstance());
+ // Set instance pool
+
container.setInstancePool((InstancePool)cl.loadClass(conf.getInstancePool()).newInstance());
+ // Set persistence manager
+
container.setPersistenceManager((StatefulSessionPersistenceManager)cl.loadClass(conf.getPersistenceManager()).newInstance());
// Create interceptors
- //con.addInterceptor(new
LogInterceptor());
- //con.addInterceptor(new
TxInterceptor());
- con.addInterceptor(new
StatefulSessionInstanceInterceptor());
- //con.addInterceptor(new
SecurityInterceptor());
+ container.addInterceptor(new
LogInterceptor());
+ container.addInterceptor(new
TxInterceptor());
+ container.addInterceptor(new
StatefulSessionInstanceInterceptor());
+ container.addInterceptor(new
SecurityInterceptor());
-
con.addInterceptor(con.createContainerInterceptor());
+
container.addInterceptor(container.createContainerInterceptor());
// Add container to application
- containers.add(con);
-
+ app.addContainer(container);
}
} else // Entity
{
// Create container
- con = new EntityContainer();
+ EntityContainer container = new
EntityContainer();
// Create classloader for this container
- con.setClassLoader(new BeanClassLoader(cl));
+ container.setClassLoader(new
BeanClassLoader(cl));
// Set metadata
- con.setMetaData(bean);
+ container.setMetaData(bean);
// Get container configuration
- ContainerConfiguration conf =
jar.getContainerConfigurations().getContainerConfiguration(bean.getConfigurationName());
+ ContainerConfiguration conf =
bean.getContainerConfiguration();
// Make sure we have a default configuration
if (conf == null)
@@ -345,83 +381,39 @@
}
// Set container invoker
-
((EntityContainer)con).setContainerInvoker((ContainerInvoker)cl.loadClass(conf.getContainerInvoker()).newInstance());
+
container.setContainerInvoker((ContainerInvoker)cl.loadClass(conf.getContainerInvoker()).newInstance());
// Set instance cache
-
((EntityContainer)con).setInstanceCache((InstanceCache)cl.loadClass(conf.getInstanceCache()).newInstance());
+
container.setInstanceCache((InstanceCache)cl.loadClass(conf.getInstanceCache()).newInstance());
// Set instance pool
-
con.setInstancePool((InstancePool)cl.loadClass(conf.getInstancePool()).newInstance());
+
container.setInstancePool((InstancePool)cl.loadClass(conf.getInstancePool()).newInstance());
// Set persistence manager
-
((EntityContainer)con).setPersistenceManager((EntityPersistenceManager)cl.loadClass(conf.getPersistenceManager()).newInstance());
+
container.setPersistenceManager((EntityPersistenceManager)cl.loadClass(conf.getPersistenceManager()).newInstance());
-
// Create interceptors
- //
con.addInterceptor(new LogInterceptor());
- //
con.addInterceptor(new SecurityInterceptor());
- //
con.addInterceptor(new TxInterceptor());
- con.addInterceptor(new
EntityInstanceInterceptor());
- con.addInterceptor(new
EntitySynchronizationInterceptor());
+ container.addInterceptor(new LogInterceptor());
+ container.addInterceptor(new
SecurityInterceptor());
+ container.addInterceptor(new TxInterceptor());
+ container.addInterceptor(new
EntityInstanceInterceptor());
+ container.addInterceptor(new
EntitySynchronizationInterceptor());
-
con.addInterceptor(con.createContainerInterceptor());
+
container.addInterceptor(container.createContainerInterceptor());
// Add container to application
- containers.add(con);
+ app.addContainer(container);
}
-
- // Set callback to application
- if (con != null)
- con.setApplication(app);
}
- // Init/Start container
- for (int i = 0; i < containers.size(); i++)
- {
- Container con = (Container)containers.get(i);
-
- // Init container
- con.init();
-
- // Start
- con.start();
- log.log("Started: "+con.getMetaData().getEjbName());
- }
+ // Init application
+ app.init();
- // Bind container in global JNDI namespace
- for (int i = 0; i < containers.size(); i++)
- {
- Container con = (Container)containers.get(i);
-
- // Use rebind to make sure you overwrite the name
- rebind(ctx, con.getMetaData().getJndiName(),
con.getContainerInvoker().getEJBHome());
-
- // Done
- log.log("Bound "+con.getMetaData().getEjbName() + " to
" + con.getMetaData().getJndiName());
-
- /*if (con instanceof EntityContainer)
- {
- rebind(ctx, con.getMetaData().getJndiName(),
((EntityContainer)con).getContainerInvoker().getEJBHome());
-
- // Done
- log.log("Bound
"+con.getMetaData().getEjbName() + " to " + con.getMetaData().getJndiName());
- } else if (con instanceof StatelessSessionContainer)
- {
- rebind(ctx, con.getMetaData().getJndiName(),
((StatelessSessionContainer)con).getContainerInvoker().getEJBHome());
-
- // Done
- log.log("Bound
"+con.getMetaData().getEjbName() + " to " + con.getMetaData().getJndiName());
- } else if (con instanceof StatefulSessionContainer)
- {
- rebind(ctx, con.getMetaData().getJndiName(),
((StatefulSessionContainer) con).getContainerInvoker().getEJBHome());
- log.log("Bound "+con.getMetaData().getEjbName() + " to " +
con.getMetaData().getJndiName());
- }
- */
-
- }
+ // Start application
+ app.start();
// Add to webserver so client can access classes through
dynamic class downloading
- WebProviderMBean webServer =
(WebProviderMBean)MBeanProxy.create(WebProviderMBean.class,
WebProviderMBean.OBJECT_NAME);
+ WebServiceMBean webServer =
(WebServiceMBean)MBeanProxy.create(WebServiceMBean.class, WebServiceMBean.OBJECT_NAME);
webServer.addClassLoader(cl);
// Done
@@ -429,10 +421,14 @@
// Register deployment
deployments.put(url, app);
- } catch (Exception e)
+ } catch (Throwable e)
{
e.printStackTrace();
- throw new DeploymentException("Could not deploy
"+url.toString(),e);
+
+ app.stop();
+ app.destroy();
+
+ throw new DeploymentException("Could not deploy
"+url.toString());
} finally
{
Log.unsetLog();
@@ -461,96 +457,17 @@
// Undeploy application
Log.setLog(log);
log.log("Undeploying:"+url);
- try
- {
- // Unbind in JNDI
- Iterator enum = app.getContainers().iterator();
- Context ctx = new InitialContext();
- while (enum.hasNext())
- {
- Container con = (Container)enum.next();
- ctx.unbind(con.getMetaData().getJndiName());
-
- // Done
- log.log("Unbound: "+con.getMetaData().getJndiName());
- }
-
- // Stop/destroy container
- enum = app.getContainers().iterator();
- while (enum.hasNext())
- {
- Container con = (Container)enum.next();
-
- // Stop container
- con.stop();
-
- // Destroy container
- con.destroy();
-
- // Done
- log.log("Removed: "+con.getMetaData().getEjbName());
- }
-
- // Remove deployment
- deployments.remove(url);
-
- // Done
- log.log("Undeployed application: "+app.getName());
- } catch (Exception e)
- {
- log.error("Undeploy failed");
- log.exception(e);
+ app.stop();
+ app.destroy();
+
+ // Remove deployment
+ deployments.remove(url);
- throw new DeploymentException("Undeploy failed", e);
- } finally
- {
- Log.unsetLog();
- }
- }
-
- // MBeanRegistration ---------------------------------------------
- public ObjectName preRegister(MBeanServer server, ObjectName name)
- throws java.lang.Exception
- {
- this.server = server;
+ // Done
+ log.log("Undeployed application: "+app.getName());
- return new ObjectName(OBJECT_NAME);
- // return name;
- }
-
- public void postRegister(java.lang.Boolean registrationDone)
- {
- }
-
- public void preDeregister()
- throws java.lang.Exception
- {
+ Log.unsetLog();
}
- public void postDeregister()
- {
- }
-
// Protected -----------------------------------------------------
- protected void rebind(Context ctx, String name, Object val)
- throws NamingException
- {
- // Bind val to name in ctx, and make sure that all intermediate
contexts exist
-
- Name n = ctx.getNameParser("").parse(name);
- while (n.size() > 1)
- {
- String ctxName = n.get(0);
- try
- {
- ctx = (Context)ctx.lookup(ctxName);
- } catch (NameNotFoundException e)
- {
- ctx = ctx.createSubcontext(ctxName);
- }
- n = n.getSuffix(1);
- }
-
- ctx.rebind(n.get(0), val);
- }
}
1.3 +6 -1 jboss/src/main/org/jboss/ejb/ContainerFactoryMBean.java
Index: ContainerFactoryMBean.java
===================================================================
RCS file:
/products/cvs/ejboss/jboss/src/main/org/jboss/ejb/ContainerFactoryMBean.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ContainerFactoryMBean.java 2000/05/30 18:32:16 1.2
+++ ContainerFactoryMBean.java 2000/06/16 13:10:19 1.3
@@ -13,9 +13,10 @@
*
* @see ContainerFactory
* @author Rickard �berg ([EMAIL PROTECTED])
- * @version $Revision: 1.2 $
+ * @version $Revision: 1.3 $
*/
public interface ContainerFactoryMBean
+ extends org.jboss.util.ServiceMBean
{
// Constants -----------------------------------------------------
public static String OBJECT_NAME = "EJB:service=ContainerFactory";
@@ -42,5 +43,9 @@
*/
public void undeploy(String url)
throws MalformedURLException, DeploymentException;
+
+ public void setVerifyDeployments(boolean verify);
+
+ public boolean getVerifyDeployments();
}
1.9 +167 -61 jboss/src/main/org/jboss/ejb/EntityContainer.java
Index: EntityContainer.java
===================================================================
RCS file: /products/cvs/ejboss/jboss/src/main/org/jboss/ejb/EntityContainer.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- EntityContainer.java 2000/06/04 23:19:00 1.8
+++ EntityContainer.java 2000/06/16 13:10:19 1.9
@@ -33,27 +33,37 @@
* @see EntityEnterpriseContext
* @author Rickard �berg ([EMAIL PROTECTED])
* @author <a href="mailto:[EMAIL PROTECTED]">Marc Fleury</a>
- * @version $Revision: 1.8 $
+ * @version $Revision: 1.9 $
*/
public class EntityContainer
extends Container
+ implements ContainerInvokerContainer, InstancePoolContainer
{
// Constants -----------------------------------------------------
// Attributes ----------------------------------------------------
- // These are the mappings between the create methods and the ejbCreate methods
- protected Map createMapping;
+ // These are the mappings between the home interface methods and the container
methods
+ protected Map homeMapping;
- // These are the mappings between the create methods and the ejbPostCreate
methods
- protected Map postCreateMapping;
+ // These are the mappings between the remote interface methods and the bean
methods
+ protected Map beanMapping;
+ // This is the container invoker for this container
+ protected ContainerInvoker containerInvoker;
+
// This is the persistence manager for this container
protected EntityPersistenceManager persistenceManager;
// This is the instance cache for this container
protected InstanceCache instanceCache;
+ // This is the instancepool that is to be used
+ protected InstancePool instancePool;
+
+ // This is the first interceptor in the chain. The last interceptor must be
provided by the container itself
+ protected Interceptor interceptor;
+
// Public --------------------------------------------------------
public void setContainerInvoker(ContainerInvoker ci)
{
@@ -64,6 +74,25 @@
ci.setContainer(this);
}
+ public ContainerInvoker getContainerInvoker()
+ {
+ return containerInvoker;
+ }
+
+ public void setInstancePool(InstancePool ip)
+ {
+ if (ip == null)
+ throw new IllegalArgumentException("Null pool");
+
+ this.instancePool = ip;
+ ip.setContainer(this);
+ }
+
+ public InstancePool getInstancePool()
+ {
+ return instancePool;
+ }
+
public void setInstanceCache(InstanceCache ic)
{
if (ic == null)
@@ -92,6 +121,39 @@
pm.setContainer(this);
}
+ public void addInterceptor(Interceptor in)
+ {
+ if (interceptor == null)
+ {
+ interceptor = in;
+ } else
+ {
+
+ Interceptor current = interceptor;
+ while ( current.getNext() != null)
+ {
+ current = current.getNext();
+ }
+
+ current.setNext(in);
+ }
+ }
+
+ public Interceptor getInterceptor()
+ {
+ return interceptor;
+ }
+
+ public Class getHomeClass()
+ {
+ return homeInterface;
+ }
+
+ public Class getRemoteClass()
+ {
+ return remoteInterface;
+ }
+
// Container implementation --------------------------------------
public void init()
throws Exception
@@ -100,9 +162,22 @@
ClassLoader oldCl = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(getClassLoader());
+ // Acquire classes from CL
+ homeInterface = classLoader.loadClass(metaData.getHome());
+ remoteInterface = classLoader.loadClass(metaData.getRemote());
+
// Call default init
- super.init();
+ super.init();
+
+ // Map the bean methods
+ setupBeanMapping();
+ // Map the home methods
+ setupHomeMapping();
+
+ // Initialize pool
+ instancePool.init();
+
// Init container invoker
containerInvoker.init();
@@ -112,8 +187,14 @@
// Init persistence
persistenceManager.init();
- setupBeanMapping();
- setupHomeMapping();
+ // Initialize the interceptor by calling the chain
+ Interceptor in = interceptor;
+ while (in != null)
+ {
+ in.setContainer(this);
+ in.init();
+ in = in.getNext();
+ }
// Reset classloader
Thread.currentThread().setContextClassLoader(oldCl);
@@ -138,6 +219,17 @@
// Start persistence
persistenceManager.start();
+ // Start the instance pool
+ instancePool.start();
+
+ // Start all interceptors in the chain
+ Interceptor in = interceptor;
+ while (in != null)
+ {
+ in.start();
+ in = in.getNext();
+ }
+
// Reset classloader
Thread.currentThread().setContextClassLoader(oldCl);
}
@@ -160,6 +252,17 @@
// Stop persistence
persistenceManager.stop();
+ // Stop the instance pool
+ instancePool.stop();
+
+ // Stop all interceptors in the chain
+ Interceptor in = interceptor;
+ while (in != null)
+ {
+ in.stop();
+ in = in.getNext();
+ }
+
// Reset classloader
Thread.currentThread().setContextClassLoader(oldCl);
}
@@ -182,99 +285,108 @@
// Destroy persistence
persistenceManager.destroy();
+ // Destroy the pool
+ instancePool.destroy();
+
+ // Destroy all the interceptors in the chain
+ Interceptor in = interceptor;
+ while (in != null)
+ {
+ in.destroy();
+ in = in.getNext();
+ }
+
// Reset classloader
Thread.currentThread().setContextClassLoader(oldCl);
}
- public Object invokeHome(Method method, Object[] args)
+ public Object invokeHome(MethodInvocation mi)
throws Exception
{
- return getInterceptor().invokeHome(method, args, null);
+ return getInterceptor().invokeHome(mi);
}
- public Object invoke(Object id, Method method, Object[] args)
+ public Object invoke(MethodInvocation mi)
throws Exception
{
// Invoke through interceptors
- return getInterceptor().invoke(id, method, args, null);
+ return getInterceptor().invoke(mi);
}
// EJBObject implementation --------------------------------------
- public void remove(Method m, Object[] args, EntityEnterpriseContext ctx)
+ public void remove(MethodInvocation mi)
throws java.rmi.RemoteException, RemoveException
{
- getPersistenceManager().removeEntity(ctx);
- ctx.setId(null);
+
getPersistenceManager().removeEntity((EntityEnterpriseContext)mi.getEnterpriseContext());
+ mi.getEnterpriseContext().setId(null);
}
- public Handle getHandle(Method m, Object[] args, EntityEnterpriseContext ctx)
+ public Handle getHandle(MethodInvocation mi)
throws java.rmi.RemoteException
{
// TODO
throw new Error("Not yet implemented");
}
- public Object getPrimaryKey(Method m, Object[] args, EntityEnterpriseContext ctx)
+ public Object getPrimaryKey(MethodInvocation mi)
throws java.rmi.RemoteException
{
// TODO
throw new Error("Not yet implemented");
}
- public EJBHome getEJBHome(Method m, Object[] args, EntityEnterpriseContext ctx)
+ public EJBHome getEJBHome(MethodInvocation mi)
throws java.rmi.RemoteException
{
return containerInvoker.getEJBHome();
}
- public boolean isIdentical(Method m, Object[] args, EntityEnterpriseContext ctx)
+ public boolean isIdentical(MethodInvocation mi)
throws java.rmi.RemoteException
{
- return ((EJBObject)args[0]).getPrimaryKey().equals(ctx.getId());
+ return
((EJBObject)mi.getArguments()[0]).getPrimaryKey().equals(mi.getEnterpriseContext().getId());
// TODO - should also check type
}
// Home interface implementation ---------------------------------
- public Object find(Method m, Object[] args, EntityEnterpriseContext ctx)
+ public Object find(MethodInvocation mi)
throws java.rmi.RemoteException, FinderException
{
// Multi-finder?
- if (!m.getReturnType().equals(getRemoteClass()))
+ if (!mi.getMethod().getReturnType().equals(getRemoteClass()))
{
// Iterator finder
- Collection c = getPersistenceManager().findEntities(m, args, ctx);
+ Collection c = getPersistenceManager().findEntities(mi.getMethod(),
mi.getArguments(), (EntityEnterpriseContext)mi.getEnterpriseContext());
return containerInvoker.getEntityCollection(c);
} else
{
// Single entity finder
- Object id = getPersistenceManager().findEntity(m, args, ctx);
- return (EJBObject)containerInvoker.getEntityEJBObject(id);
+ Object id = getPersistenceManager().findEntity(mi.getMethod(),
mi.getArguments(), (EntityEnterpriseContext)mi.getEnterpriseContext());
+ return (EJBObject)containerInvoker.getEntityEJBObject(mi.getId());
}
}
- public EJBObject createHome(Method m, Object[] args, EntityEnterpriseContext ctx)
+ public EJBObject createHome(MethodInvocation mi)
throws java.rmi.RemoteException, CreateException
{
- System.out.println("In creating Home
"+m.getDeclaringClass()+m.getName()+m.getParameterTypes().length);
-
- getPersistenceManager().createEntity(m, args, ctx);
- return ctx.getEJBObject();
+ getPersistenceManager().createEntity(mi.getMethod(), mi.getArguments(),
(EntityEnterpriseContext)mi.getEnterpriseContext());
+ return ((EntityEnterpriseContext)mi.getEnterpriseContext()).getEJBObject();
}
// EJBHome implementation ----------------------------------------
- public void removeHome(Method m, Object[] args, EntityEnterpriseContext ctx)
+ public void removeHome(MethodInvocation mi)
throws java.rmi.RemoteException, RemoveException
{
throw new Error("Not yet implemented");
}
- public EJBMetaData getEJBMetaDataHome(Method m, Object[] args,
EntityEnterpriseContext ctx)
+ public EJBMetaData getEJBMetaDataHome(MethodInvocation mi)
throws java.rmi.RemoteException
{
return getContainerInvoker().getEJBMetaData();
}
- public HomeHandle getHomeHandleHome(Method m, Object[] args,
EntityEnterpriseContext ctx)
+ public HomeHandle getHomeHandleHome(MethodInvocation mi)
throws java.rmi.RemoteException
{
// TODO
@@ -290,17 +402,16 @@
Method[] m = homeInterface.getMethods();
for (int i = 0; i < m.length; i++)
{
- System.out.println("THE NEW METHOD IS
"+m[i].getName()+m[i].getParameterTypes().length);
try
{
// Implemented by container
if (m[i].getName().startsWith("find"))
- map.put(m[i], getClass().getMethod("find", new Class[] {
Method.class, Object[].class, EntityEnterpriseContext.class }));
+ map.put(m[i], getClass().getMethod("find", new Class[] {
MethodInvocation.class }));
else
- map.put(m[i], getClass().getMethod(m[i].getName()+"Home", new
Class[] { Method.class, Object[].class, EntityEnterpriseContext.class }));
+ map.put(m[i], getClass().getMethod(m[i].getName()+"Home", new
Class[] { MethodInvocation.class }));
} catch (NoSuchMethodException e)
{
- throw new DeploymentException("Could not find matching
method for "+m[i], e);
+ throw new DeploymentException("Could not find matching
method for "+m[i]);
}
}
@@ -325,7 +436,7 @@
else
{
// Implemented by container
- map.put(m[i], getClass().getMethod(m[i].getName(), new Class[] {
Method.class, Object[].class , EntityEnterpriseContext.class}));
+ map.put(m[i], getClass().getMethod(m[i].getName(), new Class[] {
MethodInvocation.class }));
}
} catch (NoSuchMethodException e)
{
@@ -356,27 +467,26 @@
public void stop() {}
public void destroy() {}
- public Object invokeHome(Method method, Object[] args, EnterpriseContext ctx)
+ public Object invokeHome(MethodInvocation mi)
throws Exception
{
- //Debug
- System.out.println("InvokingHome "+method.getName());
- //Debug
+ //Debug
+ System.out.println("Invoking Home "+mi.getMethod().getName());
- Method m = (Method)homeMapping.get(method);
// Invoke and handle exceptions
+ Method m = (Method)homeMapping.get(mi.getMethod());
- try
+ try
{
- return m.invoke(EntityContainer.this, new Object[] { method, args,
ctx});
+ return m.invoke(EntityContainer.this, new Object[] { mi.getArguments()
});
} catch (InvocationTargetException e)
{
- //Debug
- e.printStackTrace();
- System.out.println("Home Exception seen "+e.getMessage());
- //Debug
- Throwable ex = e.getTargetException();
+ //Debug
+ e.printStackTrace();
+ System.out.println("Home Exception seen
"+e.getMessage());
+
+ Throwable ex = e.getTargetException();
if (ex instanceof Exception)
throw (Exception)ex;
else
@@ -384,29 +494,25 @@
}
}
- public Object invoke(Object id, Method method, Object[] args,
EnterpriseContext ctx)
+ public Object invoke(MethodInvocation mi)
throws Exception
{
// Get method
- Method m = (Method)beanMapping.get(method);
+ Method m = (Method)beanMapping.get(mi.getMethod());
- //Debug
- System.out.println("InvokingBean "+method.getName());
- //Debug
-
// Select instance to invoke (container or bean)
if (m.getDeclaringClass().equals(EntityContainer.class))
{
// Invoke and handle exceptions
try
{
- return m.invoke(EntityContainer.this, new Object[] { method, args,
ctx });
+ return m.invoke(EntityContainer.this, new Object[] { mi });
} catch (InvocationTargetException e)
{
//Debug
- System.out.println("Bean Exception seen "+e.getMessage());
- //Debug
- Throwable ex = e.getTargetException();
+ System.out.println("Bean Exception seen
"+e.getMessage());
+
+ Throwable ex = e.getTargetException();
if (ex instanceof Exception)
throw (Exception)ex;
else
@@ -417,7 +523,7 @@
// Invoke and handle exceptions
try
{
- return m.invoke(ctx.getInstance(), args);
+ return m.invoke(mi.getEnterpriseContext().getInstance(),
mi.getArguments());
} catch (InvocationTargetException e)
{
Throwable ex = e.getTargetException();
1.2 +3 -3 jboss/src/main/org/jboss/ejb/Interceptor.java
Index: Interceptor.java
===================================================================
RCS file: /products/cvs/ejboss/jboss/src/main/org/jboss/ejb/Interceptor.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- Interceptor.java 2000/04/22 14:30:10 1.1
+++ Interceptor.java 2000/06/16 13:10:20 1.2
@@ -16,7 +16,7 @@
*
* @see <related>
* @author Rickard �berg ([EMAIL PROTECTED])
- * @version $Revision: 1.1 $
+ * @version $Revision: 1.2 $
*/
public interface Interceptor
extends ContainerPlugin
@@ -29,10 +29,10 @@
public void setNext(Interceptor interceptor);
public Interceptor getNext();
- public Object invokeHome(Method method, Object[] args, EnterpriseContext
instance)
+ public Object invokeHome(MethodInvocation mi)
throws Exception;
- public Object invoke(Object id, Method method, Object[] args, EnterpriseContext
instance)
+ public Object invoke(MethodInvocation mi)
throws Exception;
}
1.10 +187 -74 jboss/src/main/org/jboss/ejb/StatefulSessionContainer.java
Index: StatefulSessionContainer.java
===================================================================
RCS file:
/products/cvs/ejboss/jboss/src/main/org/jboss/ejb/StatefulSessionContainer.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- StatefulSessionContainer.java 2000/06/04 23:19:00 1.9
+++ StatefulSessionContainer.java 2000/06/16 13:10:20 1.10
@@ -31,20 +31,33 @@
*
* @see <related>
* @author Rickard �berg ([EMAIL PROTECTED])
- * @version $Revision: 1.9 $
+ * @version $Revision: 1.10 $
*/
public class StatefulSessionContainer
extends Container
+ implements ContainerInvokerContainer, InstancePoolContainer
{
// Constants -----------------------------------------------------
// Attributes ----------------------------------------------------
- Map createMapping;
- Map postCreateMapping;
-
+ // These are the mappings between the home interface methods and the container
methods
+ protected Map homeMapping;
+ // These are the mappings between the remote interface methods and the bean
methods
+ protected Map beanMapping;
+
+ // This is the container invoker for this container
+ protected ContainerInvoker containerInvoker;
+
+ // This is the first interceptor in the chain. The last interceptor must be
provided by the container itself
+ protected Interceptor interceptor;
+
+ // This is the instancepool that is to be used
+ protected InstancePool instancePool;
+
// This is the persistence manager for this container
protected StatefulSessionPersistenceManager persistenceManager;
+
protected InstanceCache instanceCache;
// Static --------------------------------------------------------
@@ -61,6 +74,11 @@
ci.setContainer(this);
}
+ public ContainerInvoker getContainerInvoker()
+ {
+ return containerInvoker;
+ }
+
public void setInstanceCache(InstanceCache ic)
{
this.instanceCache = ic;
@@ -72,6 +90,20 @@
return instanceCache;
}
+ public void setInstancePool(InstancePool ip)
+ {
+ if (ip == null)
+ throw new IllegalArgumentException("Null pool");
+
+ this.instancePool = ip;
+ ip.setContainer(this);
+ }
+
+ public InstancePool getInstancePool()
+ {
+ return instancePool;
+ }
+
public StatefulSessionPersistenceManager getPersistenceManager()
{
return persistenceManager;
@@ -83,6 +115,39 @@
pm.setContainer(this);
}
+ public void addInterceptor(Interceptor in)
+ {
+ if (interceptor == null)
+ {
+ interceptor = in;
+ } else
+ {
+
+ Interceptor current = interceptor;
+ while ( current.getNext() != null)
+ {
+ current = current.getNext();
+ }
+
+ current.setNext(in);
+ }
+ }
+
+ public Interceptor getInterceptor()
+ {
+ return interceptor;
+ }
+
+ public Class getHomeClass()
+ {
+ return homeInterface;
+ }
+
+ public Class getRemoteClass()
+ {
+ return remoteInterface;
+ }
+
// Container implementation --------------------------------------
public void init()
throws Exception
@@ -91,29 +156,42 @@
ClassLoader oldCl = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(getClassLoader());
- // Call default init
- super.init();
+ // Acquire classes from CL
+ homeInterface = classLoader.loadClass(metaData.getHome());
+ remoteInterface = classLoader.loadClass(metaData.getRemote());
+
+ // Call default init
+ super.init();
// Map the bean methods
setupBeanMapping();
// Map the home methods
- setupHomeMapping();
+ setupHomeMapping();
- // Init container invoker
- containerInvoker.init();
+ // Init container invoker
+ containerInvoker.init();
// Init instance cache
- instanceCache.init();
+ instanceCache.init();
- // Init persistence
- persistenceManager.init();
+ // Initialize pool
+ instancePool.init();
+
+ // Init persistence
+ persistenceManager.init();
- setupBeanMapping();
- setupHomeMapping();
-
- // Reset classloader
- Thread.currentThread().setContextClassLoader(oldCl);
+ // Initialize the interceptor by calling the chain
+ Interceptor in = interceptor;
+ while (in != null)
+ {
+ in.setContainer(this);
+ in.init();
+ in = in.getNext();
+ }
+
+ // Reset classloader
+ Thread.currentThread().setContextClassLoader(oldCl);
}
public void start()
@@ -132,34 +210,59 @@
// Start instance cache
instanceCache.start();
+ // Start pool
+ instancePool.start();
+
// Start persistence
persistenceManager.start();
+ // Start all interceptors in the chain
+ Interceptor in = interceptor;
+ while (in != null)
+ {
+ in.start();
+ in = in.getNext();
+ }
+
// Reset classloader
Thread.currentThread().setContextClassLoader(oldCl);
}
- public void stop() {
-
+ public void stop()
+ {
// Associate thread with classloader
- ClassLoader oldCl = Thread.currentThread().getContextClassLoader();
- Thread.currentThread().setContextClassLoader(getClassLoader());
-
+ ClassLoader oldCl = Thread.currentThread().getContextClassLoader();
+ Thread.currentThread().setContextClassLoader(getClassLoader());
+
// Call default stop
- super.stop();
+ super.stop();
+
+ // Stop container invoker
+ containerInvoker.stop();
+
+ // Stop instance cache
+ instanceCache.stop();
+
+ // Stop pool
+ instancePool.stop();
- // Stop container invoker
- containerInvoker.stop();
-
- // Stop instance cache
- instanceCache.stop();
-
- // Stop persistence
- persistenceManager.stop();
-
- // Reset classloader
- Thread.currentThread().setContextClassLoader(oldCl);
+ // Stop persistence
+ persistenceManager.stop();
+
+ // Stop the instance pool
+ instancePool.stop();
+
+ // Stop all interceptors in the chain
+ Interceptor in = interceptor;
+ while (in != null)
+ {
+ in.stop();
+ in = in.getNext();
+ }
+
+ // Reset classloader
+ Thread.currentThread().setContextClassLoader(oldCl);
}
public void destroy()
@@ -177,102 +280,112 @@
// Destroy instance cache
instanceCache.destroy();
+ // Destroy pool
+ instancePool.destroy();
+
// Destroy persistence
persistenceManager.destroy();
+ // Destroy all the interceptors in the chain
+ Interceptor in = interceptor;
+ while (in != null)
+ {
+ in.destroy();
+ in = in.getNext();
+ }
+
// Reset classloader
Thread.currentThread().setContextClassLoader(oldCl);
}
- public Object invokeHome(Method method, Object[] args)
+ public Object invokeHome(MethodInvocation mi)
throws Exception
{
- return getInterceptor().invokeHome(method, args, null);
+ return getInterceptor().invokeHome(mi);
}
/**
* This method retrieves the instance from an object table, and invokes the
method
* on the particular instance through the chain of interceptors
*
- * @param id
- * @param m
- * @param args
+ * @param mi
* @return
* @exception Exception
*/
- public Object invoke(Object id, Method method, Object[] args)
+ public Object invoke(MethodInvocation mi)
throws Exception
{
// Invoke through interceptors
- return getInterceptor().invoke(id, method, args, null);
+ return getInterceptor().invoke(mi);
}
// EJBObject implementation --------------------------------------
- public void remove(Method m, Object[] args, StatefulSessionEnterpriseContext ctx)
+ public void remove(MethodInvocation mi)
throws java.rmi.RemoteException, RemoveException
{
- getPersistenceManager().removeSession(ctx);
- ctx.setId(null);
+
getPersistenceManager().removeSession((StatefulSessionEnterpriseContext)mi.getEnterpriseContext());
+ mi.getEnterpriseContext().setId(null);
}
- public Handle getHandle(Method m, Object[] args,
StatefulSessionEnterpriseContext ctx)
+ public Handle getHandle(MethodInvocation mi)
throws java.rmi.RemoteException
{
// TODO
return null;
}
- public Object getPrimaryKey(Method m, Object[] args,
StatefulSessionEnterpriseContext ctx)
+ public Object getPrimaryKey(MethodInvocation mi)
throws java.rmi.RemoteException
{
// TODO
return null;
}
- public EJBHome getEJBHome(Method m, Object[] args,
StatefulSessionEnterpriseContext ctx)
+ public EJBHome getEJBHome(MethodInvocation mi)
throws java.rmi.RemoteException
{
return containerInvoker.getEJBHome();
}
- public boolean isIdentical(Method m, Object[] args,
StatefulSessionEnterpriseContext ctx)
+ public boolean isIdentical(MethodInvocation mi)
throws java.rmi.RemoteException
{
return false; // TODO
}
// Home interface implementation ---------------------------------
- public EJBObject createHome(Method m, Object[] args,
StatefulSessionEnterpriseContext ctx)
+ public EJBObject createHome(MethodInvocation mi)
throws java.rmi.RemoteException, CreateException
{
-
- System.out.println("The context is "+ctx);
-
- System.out.println("In creating Home
"+m.getDeclaringClass()+m.getName()+m.getParameterTypes().length);
-
- getPersistenceManager().createSession(m, args, ctx);
- return ctx.getEJBObject();
+ getPersistenceManager().createSession(mi.getMethod(), mi.getArguments(),
(StatefulSessionEnterpriseContext)mi.getEnterpriseContext());
+ return
((StatefulSessionEnterpriseContext)mi.getEnterpriseContext()).getEJBObject();
}
// EJBHome implementation ----------------------------------------
- public void removeHome(Method m, Object[] args, StatefulSessionEnterpriseContext
ctx)
- throws java.rmi.RemoteException, RemoveException
+ public void removeHome(Handle handle)
+ throws java.rmi.RemoteException, RemoveException
{
- // TODO
+ // TODO
}
- public EJBMetaData getEJBMetaDataHome(Method m, Object[] args,
StatefulSessionEnterpriseContext ctx)
- throws java.rmi.RemoteException
+ public void removeHome(Object primaryKey)
+ throws java.rmi.RemoteException, RemoveException
{
- return getContainerInvoker().getEJBMetaData();
+ // TODO
}
- public HomeHandle getHomeHandleHome(Method m, Object[] args,
StatefulSessionEnterpriseContext ctx)
- throws java.rmi.RemoteException
+ public EJBMetaData getEJBMetaDataHome()
+ throws java.rmi.RemoteException
{
- // TODO
- return null;
+ return getContainerInvoker().getEJBMetaData();
+ }
+
+ public HomeHandle getHomeHandleHome()
+ throws java.rmi.RemoteException
+ {
+ // TODO
+ return null;
}
// Private -------------------------------------------------------
@@ -285,7 +398,7 @@
for (int i = 0; i < m.length; i++)
{
// Implemented by container
- map.put(m[i], getClass().getMethod(m[i].getName()+"Home", new Class[] {
Method.class, Object[].class, StatefulSessionEnterpriseContext.class }));
+ map.put(m[i], getClass().getMethod(m[i].getName()+"Home", new Class[] {
MethodInvocation.class }));
}
homeMapping = map;
@@ -343,15 +456,15 @@
public void stop() {}
public void destroy() {}
- public Object invokeHome(Method method, Object[] args, EnterpriseContext ctx)
+ public Object invokeHome(MethodInvocation mi)
throws Exception
{
- Method m = (Method)homeMapping.get(method);
+ Method m = (Method)homeMapping.get(mi.getMethod());
// Invoke and handle exceptions
try
{
- return m.invoke(StatefulSessionContainer.this, new Object[] { method,
args, ctx});
+ return m.invoke(StatefulSessionContainer.this, new Object[] { mi });
} catch (InvocationTargetException e)
{
Throwable ex = e.getTargetException();
@@ -362,11 +475,11 @@
}
}
- public Object invoke(Object id, Method method, Object[] args,
EnterpriseContext ctx)
+ public Object invoke(MethodInvocation mi)
throws Exception
{
// Get method
- Method m = (Method)beanMapping.get(method);
+ Method m = (Method)beanMapping.get(mi.getMethod());
// Select instance to invoke (container or bean)
if (m.getDeclaringClass().equals(StatefulSessionContainer.this.getClass()))
@@ -374,7 +487,7 @@
// Invoke and handle exceptions
try
{
- return m.invoke(StatefulSessionContainer.this, new Object[] {
method, args, ctx });
+ return m.invoke(StatefulSessionContainer.this, new Object[] { mi });
} catch (InvocationTargetException e)
{
Throwable ex = e.getTargetException();
@@ -388,7 +501,7 @@
// Invoke and handle exceptions
try
{
- return m.invoke(ctx.getInstance(), args);
+ return m.invoke(mi.getEnterpriseContext().getInstance(),
mi.getArguments());
} catch (InvocationTargetException e)
{
Throwable ex = e.getTargetException();
1.7 +193 -80 jboss/src/main/org/jboss/ejb/StatelessSessionContainer.java
Index: StatelessSessionContainer.java
===================================================================
RCS file:
/products/cvs/ejboss/jboss/src/main/org/jboss/ejb/StatelessSessionContainer.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- StatelessSessionContainer.java 2000/06/01 23:15:46 1.6
+++ StatelessSessionContainer.java 2000/06/16 13:10:20 1.7
@@ -26,15 +26,30 @@
* @see <related>
* @author Rickard �berg ([EMAIL PROTECTED])
* @author <a href="[EMAIL PROTECTED]">Marc Fleury</a>
-* @version $Revision: 1.6 $
+* @version $Revision: 1.7 $
*/
public class StatelessSessionContainer
-extends Container
+ extends Container
+ implements ContainerInvokerContainer, InstancePoolContainer
{
// Constants -----------------------------------------------------
// Attributes ----------------------------------------------------
+ // These are the mappings between the home interface methods and the container
methods
+ protected Map homeMapping;
+ // These are the mappings between the remote interface methods and the bean
methods
+ protected Map beanMapping;
+
+ // This is the container invoker for this container
+ protected ContainerInvoker containerInvoker;
+
+ // This is the instancepool that is to be used
+ protected InstancePool instancePool;
+
+ // This is the first interceptor in the chain. The last interceptor must be
provided by the container itself
+ protected Interceptor interceptor;
+
// Static --------------------------------------------------------
// Constructors --------------------------------------------------
@@ -49,34 +64,100 @@
ci.setContainer(this);
}
+ public ContainerInvoker getContainerInvoker()
+ {
+ return containerInvoker;
+ }
+
+ public void setInstancePool(InstancePool ip)
+ {
+ if (ip == null)
+ throw new IllegalArgumentException("Null pool");
+
+ this.instancePool = ip;
+ ip.setContainer(this);
+ }
+
+ public InstancePool getInstancePool()
+ {
+ return instancePool;
+ }
+
+ public void addInterceptor(Interceptor in)
+ {
+ if (interceptor == null)
+ {
+ interceptor = in;
+ } else
+ {
+
+ Interceptor current = interceptor;
+ while ( current.getNext() != null)
+ {
+ current = current.getNext();
+ }
+
+ current.setNext(in);
+ }
+ }
+
+ public Interceptor getInterceptor()
+ {
+ return interceptor;
+ }
+ public Class getHomeClass()
+ {
+ return homeInterface;
+ }
+
+ public Class getRemoteClass()
+ {
+ return remoteInterface;
+ }
+
// Container implementation --------------------------------------
public void init()
- throws Exception
+ throws Exception
{
// Associate thread with classloader
ClassLoader oldCl = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(getClassLoader());
+ // Acquire classes from CL
+ homeInterface = classLoader.loadClass(metaData.getHome());
+ remoteInterface = classLoader.loadClass(metaData.getRemote());
+
// Call default init
super.init();
- // Init container invoker
- containerInvoker.init();
-
-
// Map the bean methods
setupBeanMapping();
// Map the home methods
setupHomeMapping();
+ // Initialize pool
+ instancePool.init();
+
+ // Init container invoker
+ containerInvoker.init();
+
+ // Initialize the interceptor by calling the chain
+ Interceptor in = interceptor;
+ while (in != null)
+ {
+ in.setContainer(this);
+ in.init();
+ in = in.getNext();
+ }
+
// Reset classloader
Thread.currentThread().setContextClassLoader(oldCl);
}
public void start()
- throws Exception
+ throws Exception
{
// Associate thread with classloader
ClassLoader oldCl = Thread.currentThread().getContextClassLoader();
@@ -88,6 +169,17 @@
// Start container invoker
containerInvoker.start();
+ // Start the instance pool
+ instancePool.start();
+
+ // Start all interceptors in the chain
+ Interceptor in = interceptor;
+ while (in != null)
+ {
+ in.start();
+ in = in.getNext();
+ }
+
// Reset classloader
Thread.currentThread().setContextClassLoader(oldCl);
}
@@ -104,6 +196,17 @@
// Stop container invoker
containerInvoker.stop();
+ // Stop the instance pool
+ instancePool.stop();
+
+ // Stop all interceptors in the chain
+ Interceptor in = interceptor;
+ while (in != null)
+ {
+ in.stop();
+ in = in.getNext();
+ }
+
// Reset classloader
Thread.currentThread().setContextClassLoader(oldCl);
}
@@ -120,14 +223,25 @@
// Destroy container invoker
containerInvoker.destroy();
+ // Destroy the pool
+ instancePool.destroy();
+
+ // Destroy all the interceptors in the chain
+ Interceptor in = interceptor;
+ while (in != null)
+ {
+ in.destroy();
+ in = in.getNext();
+ }
+
// Reset classloader
Thread.currentThread().setContextClassLoader(oldCl);
}
- public Object invokeHome(Method method, Object[] args)
- throws Exception
+ public Object invokeHome(MethodInvocation mi)
+ throws Exception
{
- return getInterceptor().invokeHome(method, args, null);
+ return getInterceptor().invokeHome(mi);
}
/**
@@ -141,81 +255,75 @@
* @return
* @exception Exception
*/
- public Object invoke(Object id, Method method, Object[] args)
+ public Object invoke(MethodInvocation mi)
throws Exception
{
// Invoke through interceptors
- return getInterceptor().invoke(id, method, args, null);
+ return getInterceptor().invoke(mi);
}
// EJBObject implementation --------------------------------------
- public void remove()
- throws java.rmi.RemoteException, RemoveException
+ public void remove(MethodInvocation mi)
+ throws java.rmi.RemoteException, RemoveException
{
- // TODO
- }
-
- public void remove(Method m, Object[] args, StatelessSessionEnterpriseContext
ctx)
- throws java.rmi.RemoteException, RemoveException
- {
//TODO
}
- public Handle getHandle(Method m, Object[] args,
StatelessSessionEnterpriseContext ctx)
- throws java.rmi.RemoteException
+ public Handle getHandle(MethodInvocation mi)
+ throws java.rmi.RemoteException
{
// TODO
return null;
}
- public Object getPrimaryKey(Method m, Object[] args,
StatelessSessionEnterpriseContext ctx)
- throws java.rmi.RemoteException
+ public Object getPrimaryKey(MethodInvocation mi)
+ throws java.rmi.RemoteException
{
// TODO
return null;
}
- public EJBHome getEJBHome(Method m, Object[] args,
StatelessSessionEnterpriseContext ctx)
- throws java.rmi.RemoteException
+ public EJBHome getEJBHome(MethodInvocation mi)
+ throws java.rmi.RemoteException
{
return containerInvoker.getEJBHome();
}
- public boolean isIdentical(Method m, Object[] args,
StatelessSessionEnterpriseContext ctx)
- throws java.rmi.RemoteException
+ public boolean isIdentical(MethodInvocation mi)
+ throws java.rmi.RemoteException
{
return false; // TODO
}
// EJBHome implementation ----------------------------------------
- public EJBObject create()
- throws java.rmi.RemoteException, CreateException
+ public EJBObject createHome()
+ throws java.rmi.RemoteException, CreateException
{
Object obj = containerInvoker.getStatelessSessionEJBObject();
return (EJBObject)obj;
}
- public void remove(Handle handle)
- throws java.rmi.RemoteException, RemoveException
+ public void removeHome(Handle handle)
+ throws java.rmi.RemoteException, RemoveException
{
// TODO
}
- public void remove(java.lang.Object primaryKey)
- throws java.rmi.RemoteException, RemoveException
+ public void removeHome(Object primaryKey)
+ throws java.rmi.RemoteException, RemoveException
{
// TODO
}
- public EJBMetaData getEJBMetaData()
- throws java.rmi.RemoteException
+ public EJBMetaData getEJBMetaDataHome()
+ throws java.rmi.RemoteException
{
// TODO
return null;
}
- public HomeHandle getHomeHandle()
- throws java.rmi.RemoteException
+ public HomeHandle getHomeHandleHome()
+ throws java.rmi.RemoteException
{
// TODO
return null;
@@ -223,7 +331,7 @@
// Protected ----------------------------------------------------
protected void setupHomeMapping()
- throws NoSuchMethodException
+ throws NoSuchMethodException
{
Map map = new HashMap();
@@ -231,15 +339,15 @@
for (int i = 0; i < m.length; i++)
{
// Implemented by container
- //System.out.println("Mapping "+m[i].getName());
- map.put(m[i], getClass().getMethod(m[i].getName(),
m[i].getParameterTypes()));
+// System.out.println("Mapping "+m[i].getName());
+ map.put(m[i], getClass().getMethod(m[i].getName()+"Home",
m[i].getParameterTypes()));
}
homeMapping = map;
}
protected void setupBeanMapping()
- throws NoSuchMethodException
+ throws NoSuchMethodException
{
Map map = new HashMap();
Method[] m = remoteInterface.getMethods();
@@ -257,7 +365,7 @@
{
// Implemented by container
//System.out.println("Mapped Container method
"+m[i].getName() +" HASH "+m[i].hashCode());
- map.put(m[i],
getClass().getMethod(m[i].getName(), new Class[] { Method.class, Object[].class,
StatelessSessionEnterpriseContext.class}));
+ map.put(m[i],
getClass().getMethod(m[i].getName(), new Class[] { MethodInvocation.class }));
} catch (NoSuchMethodException e)
@@ -291,56 +399,61 @@
public void stop() {}
public void destroy() {}
- public Object invokeHome(Method method, Object[] args,
EnterpriseContext ctx)
- throws Exception
+ public Object invokeHome(MethodInvocation mi)
+ throws Exception
{
- Method m = (Method)homeMapping.get(method);
- return m.invoke(StatelessSessionContainer.this, args);
+ Method m = (Method)homeMapping.get(mi.getMethod());
+ try
+ {
+ return m.invoke(StatelessSessionContainer.this,
mi.getArguments());
+ } catch (InvocationTargetException e)
+ {
+ //Debug
+ e.printStackTrace();
+ System.out.println("Home Exception seen
"+e.getMessage());
+
+ Throwable ex = e.getTargetException();
+ if (ex instanceof Exception)
+ throw (Exception)ex;
+ else
+ throw (Error)ex;
+ }
}
- public Object invoke(Object id, Method method, Object[] args,
EnterpriseContext ctx)
- throws Exception
+ public Object invoke(MethodInvocation mi)
+ throws Exception
{
// Get method and instance to invoke upon
- Method m = (Method)beanMapping.get(method);
-
- Object instance;
+ Method m = (Method)beanMapping.get(mi.getMethod());
- //If we have a method that needs to be fielded by the container
- if
(m.getDeclaringClass().equals(StatelessSessionContainer.this.getClass())) {
-
- try {
-
- // Return by the present container, adapt the
method invocation parameters
- return
m.invoke(StatelessSessionContainer.this, new Object[] { method, args, ctx });
-
- } catch (InvocationTargetException e) {
-
- Throwable ex = e.getTargetException();
+ //If we have a method that needs to be done by the container
(EJBObject methods)
+ if
(m.getDeclaringClass().equals(StatelessSessionContainer.class))
+ {
+ try
+ {
+ return
m.invoke(StatelessSessionContainer.this, new Object[] { mi });
+ } catch (InvocationTargetException e)
+ {
+ Throwable ex = e.getTargetException();
- if (ex instanceof Exception) throw
(Exception)ex;
- else throw (Error)ex;
- }
- }
-
- // we have a method that needs to be fielded by a bean instance
- else {
-
+ if (ex instanceof Exception) throw (Exception)ex;
+ else throw (Error)ex;
+ }
+ } else // we have a method that needs to be done by a bean
instance
+ {
// Invoke and handle exceptions
- try {
-
- return m.invoke(ctx.getInstance(), args);
-
- }
- catch (InvocationTargetException e) {
-
+ try
+ {
+ return
m.invoke(mi.getEnterpriseContext().getInstance(), mi.getArguments());
+ } catch (InvocationTargetException e)
+ {
Throwable ex = e.getTargetException();
if (ex instanceof Exception) throw
(Exception)ex;
else throw (Error)ex;
- }
}
}
+ }
}
}
1.1 jboss/src/main/org/jboss/ejb/ContainerInvokerContainer.java
Index: ContainerInvokerContainer.java
===================================================================
/*
* jBoss, the OpenSource EJB server
*
* Distributable under GPL license.
* See terms of license at gnu.org.
*/
package org.jboss.ejb;
import java.rmi.RemoteException;
import java.util.Collection;
import javax.ejb.EJBMetaData;
import javax.ejb.EJBHome;
import javax.ejb.EJBObject;
import javax.naming.Name;
/**
* This is an interface for Containers that uses ContainerInvokers.
*
* ContainerInvokers may communicate with the Container through this interface
*
* @see ContainerInvoker
* @author Rickard �berg ([EMAIL PROTECTED])
* @version $Revision: 1.1 $
*/
public interface ContainerInvokerContainer
{
// Public --------------------------------------------------------
public Class getHomeClass();
public Class getRemoteClass();
public ContainerInvoker getContainerInvoker();
}
1.1 jboss/src/main/org/jboss/ejb/InstancePoolContainer.java
Index: InstancePoolContainer.java
===================================================================
/*
* jBoss, the OpenSource EJB server
*
* Distributable under GPL license.
* See terms of license at gnu.org.
*/
package org.jboss.ejb;
import java.rmi.RemoteException;
import java.util.Collection;
import javax.ejb.EJBMetaData;
import javax.ejb.EJBHome;
import javax.ejb.EJBObject;
import javax.naming.Name;
/**
* This is an interface for Containers that uses InstancePools.
*
* Plugins wanting to access pools from containers should use this interface
*
* @see InstancePool
* @author Rickard �berg ([EMAIL PROTECTED])
* @version $Revision: 1.1 $
*/
public interface InstancePoolContainer
{
// Public --------------------------------------------------------
public InstancePool getInstancePool();
}
1.1 jboss/src/main/org/jboss/ejb/MethodInvocation.java
Index: MethodInvocation.java
===================================================================
/*
* jBoss, the OpenSource EJB server
*
* Distributable under GPL license.
* See terms of license at gnu.org.
*/
package org.jboss.ejb;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.IOException;
import java.lang.reflect.Method;
import java.util.Map;
import java.security.Principal;
import javax.transaction.Transaction;
/**
* MethodInvocation
*
* This object carries the method to invoke and an identifier for the target ojbect
*
* @see <related>
* @author Rickard �berg ([EMAIL PROTECTED])
* @author <a href="mailto:[EMAIL PROTECTED]">Marc Fleury</a>.
* @version $Revision: 1.1 $
*/
public class MethodInvocation
{
// Constants -----------------------------------------------------
// Attributes ----------------------------------------------------
Object id;
Object[] args;
Transaction tx;
Principal identity;
Method m;
EnterpriseContext ctx;
// Static --------------------------------------------------------
// Constructors --------------------------------------------------
public MethodInvocation(Object id, Method m, Object[] args, Transaction tx,
Principal identity)
{
this.id = id;
this.m = m;
this.args = args;
this.tx = tx;
this.identity = identity;
}
// Public --------------------------------------------------------
public Object getId() { return id; }
public Method getMethod()
{
return m;
}
public Object[] getArguments()
{
return args;
}
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 void setEnterpriseContext(EnterpriseContext ctx)
{
this.ctx = ctx;
}
public EnterpriseContext getEnterpriseContext()
{
return ctx;
}
// Package protected ---------------------------------------------
// Protected -----------------------------------------------------
// Private -------------------------------------------------------
// Inner classes -------------------------------------------------
}