[jboss-cvs] JBossAS SVN: r86050 - in projects/ejb3/trunk/nointerface/src: main/java/org/jboss/ejb3/nointerface/factory and 5 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Mar 18 10:24:35 EDT 2009
Author: jaikiran
Date: 2009-03-18 10:24:35 -0400 (Wed, 18 Mar 2009)
New Revision: 86050
Added:
projects/ejb3/trunk/nointerface/src/main/java/org/jboss/ejb3/nointerface/factory/MCAwareStatefulNoInterfaceViewFactory.java
projects/ejb3/trunk/nointerface/src/main/java/org/jboss/ejb3/nointerface/invocationhandler/MCAwareNoInterfaceViewInvocationHandler.java
Removed:
projects/ejb3/trunk/nointerface/src/main/java/org/jboss/ejb3/nointerface/factory/StatefulNoInterfaceViewFactory.java
projects/ejb3/trunk/nointerface/src/main/java/org/jboss/ejb3/nointerface/invocationhandler/NoInterfaceViewInvocationHandler.java
Modified:
projects/ejb3/trunk/nointerface/src/main/java/org/jboss/ejb3/nointerface/deployers/EJB3NoInterfaceDeployer.java
projects/ejb3/trunk/nointerface/src/main/java/org/jboss/ejb3/nointerface/mc/NoInterfaceViewJNDIBinder.java
projects/ejb3/trunk/nointerface/src/main/java/org/jboss/ejb3/nointerface/mc/StatefulNoInterfaceJNDIBinder.java
projects/ejb3/trunk/nointerface/src/main/java/org/jboss/ejb3/nointerface/mc/StatelessNoInterfaceJNDIBinder.java
projects/ejb3/trunk/nointerface/src/main/java/org/jboss/ejb3/nointerface/objectfactory/StatefulNoInterfaceViewObjectFactory.java
projects/ejb3/trunk/nointerface/src/test/java/org/jboss/ejb3/nointerface/test/deployers/MockContainerDeployer.java
projects/ejb3/trunk/nointerface/src/test/java/org/jboss/ejb3/nointerface/test/viewcreator/unit/NoInterfaceEJBViewCreatorTestCase.java
Log:
EJBTHREE-1727 The no-interface view components are now more MC aware. Dependencies will be on KernelControllerContext of the container, instead of the earlier dependency on the container
Modified: projects/ejb3/trunk/nointerface/src/main/java/org/jboss/ejb3/nointerface/deployers/EJB3NoInterfaceDeployer.java
===================================================================
--- projects/ejb3/trunk/nointerface/src/main/java/org/jboss/ejb3/nointerface/deployers/EJB3NoInterfaceDeployer.java 2009-03-18 14:24:07 UTC (rev 86049)
+++ projects/ejb3/trunk/nointerface/src/main/java/org/jboss/ejb3/nointerface/deployers/EJB3NoInterfaceDeployer.java 2009-03-18 14:24:35 UTC (rev 86050)
@@ -32,8 +32,9 @@
import javax.management.MalformedObjectNameException;
import javax.management.ObjectName;
+import org.jboss.beans.metadata.api.model.FromContext;
+import org.jboss.beans.metadata.plugins.AbstractInjectionValueMetaData;
import org.jboss.beans.metadata.spi.BeanMetaData;
-import org.jboss.beans.metadata.spi.ValueMetaData;
import org.jboss.beans.metadata.spi.builder.BeanMetaDataBuilder;
import org.jboss.dependency.spi.ControllerState;
import org.jboss.deployers.spi.DeploymentException;
@@ -131,7 +132,8 @@
String containerMCBeanName = sessionBeanMetaData.getContainerName();
if (logger.isTraceEnabled())
{
- logger.trace("Container name for bean " + sessionBeanMetaData.getEjbName() + " in unit " + unit + " is " + containerMCBeanName);
+ logger.trace("Container name for bean " + sessionBeanMetaData.getEjbName() + " in unit " + unit + " is "
+ + containerMCBeanName);
}
if (containerMCBeanName == null)
{
@@ -143,33 +145,36 @@
}
- // The no-interface view needs to be a MC bean so that it can "depend" on the container, so let's
- // make the no-interface view a MC bean
- NoInterfaceViewJNDIBinder bean = NoInterfaceViewJNDIBinder.getNoInterfaceViewJndiBinder(beanClass,
+ // The no-interface view needs to be a MC bean so that it can "depend" on the KernelControllerContext
+ // of the container. The NoInterfaceViewJNDIBinder is the MC which will have this dependency
+ NoInterfaceViewJNDIBinder noInterfaceViewJNDIBinder = NoInterfaceViewJNDIBinder.getNoInterfaceViewJndiBinder(beanClass,
sessionBeanMetaData);
- String noInterfaceViewMCBeanName = sessionBeanMetaData.getEjbName() + "@" + ((Object) bean).toString();
- BeanMetaDataBuilder builder = BeanMetaDataBuilder.createBuilder(noInterfaceViewMCBeanName, bean.getClass()
+ String noInterfaceViewMCBeanName = sessionBeanMetaData.getEjbName() + "@" + ((Object) noInterfaceViewJNDIBinder).toString();
+ BeanMetaDataBuilder builder = BeanMetaDataBuilder.createBuilder(noInterfaceViewMCBeanName, noInterfaceViewJNDIBinder.getClass()
.getName());
- builder.setConstructorValue(bean);
+ builder.setConstructorValue(noInterfaceViewJNDIBinder);
- ValueMetaData inject = builder.createInject(containerMCBeanName, null, null, ControllerState.DESCRIBED);
+ //ValueMetaData inject = builder.createInject(containerMCBeanName, null, null, ControllerState.DESCRIBED);
+ AbstractInjectionValueMetaData injectMetaData = new AbstractInjectionValueMetaData(containerMCBeanName);
+ injectMetaData.setDependentState(ControllerState.DESCRIBED);
+ injectMetaData.setFromContext(FromContext.CONTEXT);
+
// Too bad we have to know the field name. Need to do more research on MC to see if we can
// add property metadata based on type instead of field name.
- builder.addPropertyMetaData("container", inject);
-
+ builder.addPropertyMetaData("containerContext", injectMetaData);
+
// for SFSB we also need to inject the StatefulSessionFactory (which at the moment is
// available at the same containerMCBeanName and is infact the container)
if (sessionBeanMetaData.isStateful())
{
- // inject the container (=StatefulSessionFactory)
- builder.addPropertyMetaData("statefulSessionFactory", inject);
+ // inject the KernelControllerContext of the StatefulSessionFactory (which at the moment is the container itself)
+ builder.addPropertyMetaData("statefulSessionFactoryContext", injectMetaData);
}
- logger.info("Added injection on " + bean + " for container " + containerMCBeanName + " cl set to "
- + unit.getClassLoader());
-
// Add this as an attachment
unit.addAttachment(BeanMetaData.class + ":" + noInterfaceViewMCBeanName, builder.getBeanMetaData());
+
+ logger.debug("MC bean for container " + containerMCBeanName + " has been created and added to the deployment unit " + unit);
}
catch (Throwable t)
@@ -287,7 +292,7 @@
// As per section 4.9.8 (bullet 1.3) of EJB3.1 spec
// java.io.Serializable; java.io.Externalizable; any of the interfaces defined by the javax.ejb
// are excluded from interface check
-
+
// Impl detail : We need an ArrayList because it supports removing of elements through iterator, while
// iterating. The List returned through Arrays.asList(...) does not allow this and throws UnsupportedException
List<Class<?>> implementedInterfaces = new ArrayList<Class<?>>(Arrays.asList(interfaces));
Added: projects/ejb3/trunk/nointerface/src/main/java/org/jboss/ejb3/nointerface/factory/MCAwareStatefulNoInterfaceViewFactory.java
===================================================================
--- projects/ejb3/trunk/nointerface/src/main/java/org/jboss/ejb3/nointerface/factory/MCAwareStatefulNoInterfaceViewFactory.java (rev 0)
+++ projects/ejb3/trunk/nointerface/src/main/java/org/jboss/ejb3/nointerface/factory/MCAwareStatefulNoInterfaceViewFactory.java 2009-03-18 14:24:35 UTC (rev 86050)
@@ -0,0 +1,140 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.nointerface.factory;
+
+import java.io.Serializable;
+import java.lang.reflect.InvocationHandler;
+
+import org.jboss.dependency.spi.ControllerState;
+import org.jboss.ejb3.nointerface.NoInterfaceEJBViewCreator;
+import org.jboss.ejb3.nointerface.invocationhandler.MCAwareNoInterfaceViewInvocationHandler;
+import org.jboss.ejb3.proxy.spi.container.StatefulSessionFactory;
+import org.jboss.kernel.spi.dependency.KernelControllerContext;
+import org.jboss.logging.Logger;
+
+/**
+ * StatefulNoInterfaceViewFactory
+ *
+ * Responsible for (not necessarily in the following order)
+ * - Creating a session from the stateful container
+ * - Creating the no-interface view for a stateful session bean
+ *
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+public class MCAwareStatefulNoInterfaceViewFactory
+{
+
+ /**
+ * Logger
+ */
+ private static Logger logger = Logger.getLogger(MCAwareStatefulNoInterfaceViewFactory.class);
+
+ /**
+ * The bean class
+ */
+ protected Class<?> beanClass;
+
+ /**
+ * The KernelControllerContext corresponding to the container of a bean for which
+ * the no-interface view is to be created by this factory. This context
+ * may <i>not</i> be in INSTALLED state. This factory is responsible
+ * for pushing it to INSTALLED state whenever necessary.
+ *
+ */
+ protected KernelControllerContext containerContext;
+
+ /**
+ * The KernelControllerContext corresponding StatefulSessionFactory. This context
+ * may <i>not</i> be in INSTALLED state. This factory is responsible
+ * for pushing it to INSTALLED state whenever necessary.
+ *
+ */
+ protected KernelControllerContext statefulSessionFactoryContext;
+
+ /**
+ * Constructor
+ * @param beanClass
+ * @param container
+ * @param statefulSessionFactory
+ */
+ public MCAwareStatefulNoInterfaceViewFactory(Class<?> beanClass, KernelControllerContext containerContext,
+ KernelControllerContext statefulSessionFactoryContext)
+ {
+ this.beanClass = beanClass;
+ this.containerContext = containerContext;
+ this.statefulSessionFactoryContext = statefulSessionFactoryContext;
+ }
+
+ /**
+ * Creates the no-interface view and other necessary steps including (session creation)
+ * for the bean
+ *
+ * @return
+ * @throws Exception
+ */
+ public Object createNoInterfaceView() throws Exception
+ {
+ logger.debug("Creating no-interface view for " + this.beanClass);
+ try
+ {
+ // first push the statefulSessionFactoryContext to INSTALLED
+ if (logger.isTraceEnabled())
+ {
+ logger.trace("Changing the context " + this.statefulSessionFactoryContext.getName() + " to state "
+ + ControllerState.INSTALLED.getStateString() + " from current state "
+ + this.statefulSessionFactoryContext.getState().getStateString());
+ }
+ this.statefulSessionFactoryContext.getController().change(this.statefulSessionFactoryContext,
+ ControllerState.INSTALLED);
+ }
+ catch (Throwable t)
+ {
+ throw new RuntimeException("Could not push the context " + this.statefulSessionFactoryContext.getName()
+ + " from its current state " + this.statefulSessionFactoryContext.getState().getStateString()
+ + " to INSTALLED", t);
+ }
+
+ // now get hold of the StatefulSessionFactory from the context
+ Object statefulSessionFactory = this.statefulSessionFactoryContext.getTarget();
+ assert statefulSessionFactory instanceof StatefulSessionFactory : "Unexpected object type found "
+ + statefulSessionFactory + " - expected a " + StatefulSessionFactory.class;
+
+ // create the session
+ Serializable session = ((StatefulSessionFactory) statefulSessionFactory).createSession();
+ logger.debug("Created session " + session + " for " + this.beanClass);
+
+ // create an invocation handler
+ InvocationHandler invocationHandler = new MCAwareNoInterfaceViewInvocationHandler(this.containerContext, session);
+ // Now create the view for this bean class and the newly created invocation handler
+ // TODO: Incorrect cardinality
+ NoInterfaceEJBViewCreator noInterfaceViewCreator = new NoInterfaceEJBViewCreator();
+ Object noInterfaceView = noInterfaceViewCreator.createView(invocationHandler, beanClass);
+
+ if (logger.isTraceEnabled())
+ {
+ logger.trace("Created no-interface view " + noInterfaceView + " for bean " + beanClass);
+ }
+ return noInterfaceView;
+ }
+
+}
Deleted: projects/ejb3/trunk/nointerface/src/main/java/org/jboss/ejb3/nointerface/factory/StatefulNoInterfaceViewFactory.java
===================================================================
--- projects/ejb3/trunk/nointerface/src/main/java/org/jboss/ejb3/nointerface/factory/StatefulNoInterfaceViewFactory.java 2009-03-18 14:24:07 UTC (rev 86049)
+++ projects/ejb3/trunk/nointerface/src/main/java/org/jboss/ejb3/nointerface/factory/StatefulNoInterfaceViewFactory.java 2009-03-18 14:24:35 UTC (rev 86050)
@@ -1,107 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2008, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.ejb3.nointerface.factory;
-
-import java.io.Serializable;
-import java.lang.reflect.InvocationHandler;
-
-import org.jboss.ejb3.nointerface.NoInterfaceEJBViewCreator;
-import org.jboss.ejb3.nointerface.invocationhandler.NoInterfaceViewInvocationHandler;
-import org.jboss.ejb3.proxy.spi.container.InvokableContext;
-import org.jboss.ejb3.proxy.spi.container.StatefulSessionFactory;
-import org.jboss.logging.Logger;
-
-/**
- * StatefulNoInterfaceViewFactory
- *
- * Responsible for (not necessarily in the following order)
- * - Creating a session from the stateful container
- * - Creating the no-interface view for a stateful session bean
- *
- * @author Jaikiran Pai
- * @version $Revision: $
- */
-public class StatefulNoInterfaceViewFactory
-{
-
- /**
- * Logger
- */
- private static Logger logger = Logger.getLogger(StatefulNoInterfaceViewFactory.class);
-
- /**
- * The bean class
- */
- protected Class<?> beanClass;
-
- /**
- * The container corresponding to the bean for which
- * the no-interface view is to be created by this factory
- */
- protected InvokableContext container;
-
- /**
- * Responsible for creating sessions
- */
- protected StatefulSessionFactory statefulSessionFactory;
-
- /**
- * Constructor
- * @param beanClass
- * @param container
- * @param statefulSessionFactory
- */
- public StatefulNoInterfaceViewFactory(Class<?> beanClass, InvokableContext container,
- StatefulSessionFactory statefulSessionFactory)
- {
- this.beanClass = beanClass;
- this.container = container;
- this.statefulSessionFactory = statefulSessionFactory;
- }
-
- /**
- * Creates the no-interface view and other necessary steps including (session creation)
- * for the bean
- *
- * @return
- * @throws Exception
- */
- public Object createNoInterfaceView() throws Exception
- {
- logger.debug("Creating no-interface view for " + this.beanClass);
-
- Serializable session = this.statefulSessionFactory.createSession();
- logger.debug("Created session " + session + " for " + this.beanClass);
-
- InvocationHandler invocationHandler = new NoInterfaceViewInvocationHandler(container, session);
- // Now create the view for this bean class and the newly created invocation handler
- NoInterfaceEJBViewCreator noInterfaceViewCreator = new NoInterfaceEJBViewCreator();
- Object noInterfaceView = noInterfaceViewCreator.createView(invocationHandler, beanClass);
-
- if (logger.isTraceEnabled())
- {
- logger.trace("Created no-interface view " + noInterfaceView + " for bean " + beanClass);
- }
- return noInterfaceView;
- }
-
-}
Copied: projects/ejb3/trunk/nointerface/src/main/java/org/jboss/ejb3/nointerface/invocationhandler/MCAwareNoInterfaceViewInvocationHandler.java (from rev 86038, projects/ejb3/trunk/nointerface/src/main/java/org/jboss/ejb3/nointerface/invocationhandler/NoInterfaceViewInvocationHandler.java)
===================================================================
--- projects/ejb3/trunk/nointerface/src/main/java/org/jboss/ejb3/nointerface/invocationhandler/MCAwareNoInterfaceViewInvocationHandler.java (rev 0)
+++ projects/ejb3/trunk/nointerface/src/main/java/org/jboss/ejb3/nointerface/invocationhandler/MCAwareNoInterfaceViewInvocationHandler.java 2009-03-18 14:24:35 UTC (rev 86050)
@@ -0,0 +1,175 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.nointerface.invocationhandler;
+
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+
+
+import org.jboss.dependency.spi.ControllerState;
+import org.jboss.ejb3.common.lang.SerializableMethod;
+import org.jboss.ejb3.proxy.spi.container.InvokableContext;
+import org.jboss.ejb3.proxy.spi.intf.SessionProxy;
+import org.jboss.kernel.spi.dependency.KernelControllerContext;
+import org.jboss.logging.Logger;
+
+/**
+ * MCAwareNoInterfaceViewInvocationHandler
+ *
+ * An {@link InvocationHandler} which corresponds to the
+ * no-interface view of a {@link EJBContainer}. All calls on the no-interface
+ * view are routed through this {@link InvocationHandler} to the container.
+ *
+ *
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+public class MCAwareNoInterfaceViewInvocationHandler implements InvocationHandler
+{
+
+ /**
+ * Logger
+ */
+ private static Logger logger = Logger.getLogger(MCAwareNoInterfaceViewInvocationHandler.class);
+
+ /**
+ * The KernelControllerContext corresponding to the container of a bean for which
+ * the no-interface view is to be created by this factory. This context
+ * may <i>not</i> be in INSTALLED state. This factory is responsible
+ * for pushing it to INSTALLED state whenever necessary.
+ *
+ * All calls to this invocation handler will be forwarded to the container represented
+ * by this context
+ *
+ *
+ */
+ private KernelControllerContext containerContext;
+
+
+ /**
+ * The {@link MCAwareNoInterfaceViewInvocationHandler} and the {@link InvokableContext} interact
+ * with each other through a {@link SessionProxy}
+ */
+ private SessionProxy sessionProxy;
+
+ /**
+ * Constructor
+ * @param container
+ */
+ public MCAwareNoInterfaceViewInvocationHandler(KernelControllerContext containerContext, Object target)
+ {
+ assert containerContext != null : "Container context is null for no-interface view invocation handler";
+ this.containerContext = containerContext;
+ this.sessionProxy = new NoInterfaceViewSessionProxy(target);
+ }
+
+ /**
+ * The entry point when a client calls any methods on the no-interface view of a bean,
+ * returned through JNDI.
+ *
+ *
+ * @param proxy
+ * @param method The invoked method
+ * @param args The arguments to the method
+ */
+ public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
+ {
+ assert this.sessionProxy != null : "Cannot invoke the container without the " + SessionProxy.class.getName();
+ // TODO: Some methods like toString() can be handled locally.
+ // But as of now let's just pass it on to the container.
+
+
+ if (logger.isTraceEnabled())
+ {
+ logger.trace("Pushing the container context to INSTALLED state from its current state = " + this.containerContext.getState().getStateString());
+ }
+ // first push the context corresponding to the container to INSTALLED
+ this.containerContext.getController().change(this.containerContext, ControllerState.INSTALLED);
+ // get hold of the container from its context
+ InvokableContext container = (InvokableContext) this.containerContext.getTarget();
+ // finally pass on the control to the container
+ SerializableMethod serializableMethod = new SerializableMethod(method);
+ return container.invoke(this.sessionProxy, serializableMethod, args);
+ }
+
+ /**
+ * Returns the context corresponding to the container, associated with this invocation handler
+ *
+ * @return
+ */
+ public KernelControllerContext getContainerContext()
+ {
+ return this.containerContext;
+ }
+
+
+
+ /**
+ *
+ * NoInterfaceViewSessionProxy
+ *
+ * A {@link SessionProxy} implementation for the no-interface view.
+ * Used by the {@link MCAwareNoInterfaceViewInvocationHandler} to interact
+ * with the {@link InvokableContext}
+ *
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+ private class NoInterfaceViewSessionProxy implements SessionProxy
+ {
+
+ /**
+ * The target of an invocation on the {@link MCAwareNoInterfaceViewInvocationHandler} - used as a sessionId
+ */
+ private Object target;
+
+ public NoInterfaceViewSessionProxy(Object target)
+ {
+ this.target = target;
+ }
+
+ /**
+ * @see SessionProxy#getTarget()
+ */
+ public Object getTarget()
+ {
+ return this.target;
+ }
+
+ /**
+ * @see SessionProxy#setTarget(Object)
+ */
+ public void setTarget(Object target)
+ {
+ this.target = target;
+ }
+
+ public void removeTarget() throws UnsupportedOperationException
+ {
+ // Is this enough?
+ this.target = null;
+
+ }
+
+ }
+
+}
Property changes on: projects/ejb3/trunk/nointerface/src/main/java/org/jboss/ejb3/nointerface/invocationhandler/MCAwareNoInterfaceViewInvocationHandler.java
___________________________________________________________________
Name: svn:mergeinfo
+
Deleted: projects/ejb3/trunk/nointerface/src/main/java/org/jboss/ejb3/nointerface/invocationhandler/NoInterfaceViewInvocationHandler.java
===================================================================
--- projects/ejb3/trunk/nointerface/src/main/java/org/jboss/ejb3/nointerface/invocationhandler/NoInterfaceViewInvocationHandler.java 2009-03-18 14:24:07 UTC (rev 86049)
+++ projects/ejb3/trunk/nointerface/src/main/java/org/jboss/ejb3/nointerface/invocationhandler/NoInterfaceViewInvocationHandler.java 2009-03-18 14:24:35 UTC (rev 86050)
@@ -1,159 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2008, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.ejb3.nointerface.invocationhandler;
-
-import java.lang.reflect.InvocationHandler;
-import java.lang.reflect.Method;
-
-
-import org.jboss.ejb3.common.lang.SerializableMethod;
-import org.jboss.ejb3.proxy.spi.container.InvokableContext;
-import org.jboss.ejb3.proxy.spi.intf.SessionProxy;
-import org.jboss.logging.Logger;
-
-/**
- * NoInterfaceViewInvocationHandler
- *
- * An {@link InvocationHandler} which corresponds to the
- * no-interface view of a {@link EJBContainer}. All calls on the no-interface
- * view are routed through this {@link InvocationHandler} to the container.
- *
- *
- * @author Jaikiran Pai
- * @version $Revision: $
- */
-public class NoInterfaceViewInvocationHandler implements InvocationHandler
-{
-
- /**
- * Logger
- */
- private static Logger logger = Logger.getLogger(NoInterfaceViewInvocationHandler.class);
-
- /**
- * The container to which this invocation handler corresponds to.
- * All calls to this invocation handler will be forwarded to this
- * container.
- *
- */
- private InvokableContext container;
-
-
- /**
- * The {@link NoInterfaceViewInvocationHandler} and the {@link InvokableContext} interact
- * with each other through a {@link SessionProxy}
- */
- private SessionProxy sessionProxy;
-
- /**
- * Constructor
- * @param container
- */
- public NoInterfaceViewInvocationHandler(InvokableContext container, Object target)
- {
- assert container != null : "Container is null for no-interface view invocation handler";
- this.container = container;
- this.sessionProxy = new NoInterfaceViewSessionProxy(target);
- }
-
- /**
- * The entry point when a client calls any methods on the no-interface view of a bean,
- * returned through JNDI.
- *
- * This method will do the common steps (common for SLSB and SFSB) before passing on the
- * call to {@link #doInvoke(Object, Method, Object[])}
- *
- * @param proxy
- * @param method The invoked method
- * @param args The arguments to the method
- */
- public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
- {
- assert this.sessionProxy != null : "Cannot invoke the container without the " + SessionProxy.class.getName();
- // TODO: Some methods like toString() can be handled locally.
- // But as of now let's just pass it on to the container.
- SerializableMethod serializableMethod = new SerializableMethod(method);
- return getContainer().invoke(this.sessionProxy, serializableMethod, args);
- }
-
- /**
- * Returns the container associated with this invocation handler
- *
- * @return
- */
- public InvokableContext getContainer()
- {
- return this.container;
- }
-
-
-
- /**
- *
- * NoInterfaceViewSessionProxy
- *
- * A {@link SessionProxy} implementation for the no-interface view.
- * Used by the {@link NoInterfaceViewInvocationHandler} to interact
- * with the {@link InvokableContext}
- *
- * @author Jaikiran Pai
- * @version $Revision: $
- */
- private class NoInterfaceViewSessionProxy implements SessionProxy
- {
-
- /**
- * The target of an invocation on the {@link NoInterfaceViewInvocationHandler} - used as a sessionId
- */
- private Object target;
-
- public NoInterfaceViewSessionProxy(Object target)
- {
- this.target = target;
- }
-
- /**
- * @see SessionProxy#getTarget()
- */
- public Object getTarget()
- {
- return this.target;
- }
-
- /**
- * @see SessionProxy#setTarget(Object)
- */
- public void setTarget(Object target)
- {
- this.target = target;
- }
-
- public void removeTarget() throws UnsupportedOperationException
- {
- // Is this enough?
- this.target = null;
-
- }
-
- }
-
-}
Modified: projects/ejb3/trunk/nointerface/src/main/java/org/jboss/ejb3/nointerface/mc/NoInterfaceViewJNDIBinder.java
===================================================================
--- projects/ejb3/trunk/nointerface/src/main/java/org/jboss/ejb3/nointerface/mc/NoInterfaceViewJNDIBinder.java 2009-03-18 14:24:07 UTC (rev 86049)
+++ projects/ejb3/trunk/nointerface/src/main/java/org/jboss/ejb3/nointerface/mc/NoInterfaceViewJNDIBinder.java 2009-03-18 14:24:35 UTC (rev 86050)
@@ -24,15 +24,20 @@
import org.jboss.beans.metadata.api.annotations.Inject;
import org.jboss.beans.metadata.api.annotations.Start;
import org.jboss.beans.metadata.api.annotations.Stop;
-import org.jboss.ejb3.proxy.spi.container.InvokableContext;
+import org.jboss.beans.metadata.api.model.FromContext;
+import org.jboss.kernel.spi.dependency.KernelControllerContext;
import org.jboss.logging.Logger;
import org.jboss.metadata.ejb.jboss.JBossSessionBeanMetaData;
/**
- * NoInterfaceViewMCBean
+ * NoInterfaceViewJNDIBinder
*
* A {@link NoInterfaceViewJNDIBinder} corresponds to a EJB which is eligible
* for a no-interface view
+ *
+ * This MC bean has dependencies (like the container) injected as necessary.
+ * During its START phase this NoInterfaceViewJNDIBinder creates a no-interface view
+ * and binds it to the jndi.
*
* @author Jaikiran Pai
* @version $Revision: $
@@ -49,7 +54,12 @@
* The container for which this {@link NoInterfaceViewJNDIBinder} holds
* an no-interface view
*/
- protected InvokableContext container;
+ // Bean name will be added to this Inject by the deployer.
+ // We need NOT use the annotation here at all, since the deployer adds this
+ // dynamically. But having this here provides a better understanding about how
+ // this field is used
+ @Inject(dependentState = "Described", fromContext = FromContext.CONTEXT)
+ protected KernelControllerContext containerContext;
/**
* The bean class for which the no-interface view corresponds
@@ -82,13 +92,18 @@
}
+ /**
+ * Bind the no-interface view
+ *
+ * @throws Exception
+ */
public abstract void bindNoInterfaceView() throws Exception;
/**
* Will be called when the dependencies of this {@link NoInterfaceViewJNDIBinder} are
* resolved and this MC bean reaches the START state.
*
- * At this point, the <code>container</code> associated with this {@link NoInterfaceViewJNDIBinder}
+ * At this point, the {@link #containerContext} associated with this {@link NoInterfaceViewJNDIBinder}
* is injected and is at a minimal of DESCRIBED state. We now create a no-interface view
* for the corresponding bean.
* Note: No validations (like whether the bean is eligible for no-interface view) is done at this
@@ -102,7 +117,7 @@
{
if (logger.isTraceEnabled())
{
- logger.trace("Creating no-interface view for container " + this.container);
+ logger.trace("Creating no-interface view for container " + this.containerContext);
}
this.bindNoInterfaceView();
@@ -115,14 +130,14 @@
//TODO need to unbind
}
- // Bean name will be added to this Inject by the deployer.
- // We need not use the annotation here at all, since the deployer adds this
- // dynamically. But having this here provides a better understanding about how
- // this field is used
- @Inject(dependentState = "Described")
- public void setContainer(InvokableContext container) throws Exception
+ /**
+ *
+ * @param containerContext The KernelControllerContext corresponding to the container
+ * @throws Exception
+ */
+ public void setContainerContext(KernelControllerContext containerContext) throws Exception
{
- this.container = container;
+ this.containerContext = containerContext;
}
Modified: projects/ejb3/trunk/nointerface/src/main/java/org/jboss/ejb3/nointerface/mc/StatefulNoInterfaceJNDIBinder.java
===================================================================
--- projects/ejb3/trunk/nointerface/src/main/java/org/jboss/ejb3/nointerface/mc/StatefulNoInterfaceJNDIBinder.java 2009-03-18 14:24:07 UTC (rev 86049)
+++ projects/ejb3/trunk/nointerface/src/main/java/org/jboss/ejb3/nointerface/mc/StatefulNoInterfaceJNDIBinder.java 2009-03-18 14:24:35 UTC (rev 86050)
@@ -29,10 +29,11 @@
import org.jboss.beans.metadata.api.annotations.Inject;
import org.jboss.ejb3.nointerface.deployers.EJB3NoInterfaceDeployer;
-import org.jboss.ejb3.nointerface.factory.StatefulNoInterfaceViewFactory;
+import org.jboss.ejb3.nointerface.factory.MCAwareStatefulNoInterfaceViewFactory;
import org.jboss.ejb3.nointerface.objectfactory.NoInterfaceViewProxyFactoryRefAddrTypes;
import org.jboss.ejb3.nointerface.objectfactory.StatefulNoInterfaceViewObjectFactory;
import org.jboss.ejb3.proxy.spi.container.StatefulSessionFactory;
+import org.jboss.kernel.spi.dependency.KernelControllerContext;
import org.jboss.logging.Logger;
import org.jboss.metadata.ejb.jboss.JBossSessionBeanMetaData;
import org.jboss.util.naming.NonSerializableFactory;
@@ -63,7 +64,7 @@
* @see EJB3NoInterfaceDeployer#deploy(org.jboss.deployers.structure.spi.DeploymentUnit)
*/
@Inject(dependentState = "Described")
- private StatefulSessionFactory statefulSessionFactory;
+ private KernelControllerContext statefulSessionFactoryContext;
protected StatefulNoInterfaceJNDIBinder(Class<?> beanClass, JBossSessionBeanMetaData sessionBeanMetadata)
{
@@ -72,7 +73,7 @@
}
/**
- * 1) Creates a {@link StatefulNoInterfaceViewFactory} and binds it to JNDI (let's call
+ * 1) Creates a {@link MCAwareStatefulNoInterfaceViewFactory} and binds it to JNDI (let's call
* this jndi-name "A")
*
* 2) Creates a {@link StatefulNoInterfaceViewObjectFactory} objectfactory and binds a {@link Reference}
@@ -91,8 +92,8 @@
// This factory will be bound to JNDI and will be invoked (through an objectfactory) to create
// the no-interface view for a SFSB
- StatefulNoInterfaceViewFactory statefulNoInterfaceViewFactory = new StatefulNoInterfaceViewFactory(
- this.beanClass, this.container, this.statefulSessionFactory);
+ MCAwareStatefulNoInterfaceViewFactory statefulNoInterfaceViewFactory = new MCAwareStatefulNoInterfaceViewFactory(
+ this.beanClass, this.containerContext, this.statefulSessionFactoryContext);
// TODO - Needs to be a proper jndi name for the factory
String statefulProxyFactoryJndiName = sessionBeanMetadata.getEjbName() + "/no-interface-stateful-proxyfactory";
@@ -124,14 +125,14 @@
}
- public void setStatefulSessionFactory(StatefulSessionFactory statefulSessFactory)
+ public void setStatefulSessionFactoryContext(KernelControllerContext statefulSessFactoryContext)
{
- this.statefulSessionFactory = statefulSessFactory;
+ this.statefulSessionFactoryContext = statefulSessFactoryContext;
}
- public StatefulSessionFactory getStatefulSessionFactory()
+ public KernelControllerContext getStatefulSessionFactoryContext()
{
- return this.statefulSessionFactory;
+ return this.statefulSessionFactoryContext;
}
}
Modified: projects/ejb3/trunk/nointerface/src/main/java/org/jboss/ejb3/nointerface/mc/StatelessNoInterfaceJNDIBinder.java
===================================================================
--- projects/ejb3/trunk/nointerface/src/main/java/org/jboss/ejb3/nointerface/mc/StatelessNoInterfaceJNDIBinder.java 2009-03-18 14:24:07 UTC (rev 86049)
+++ projects/ejb3/trunk/nointerface/src/main/java/org/jboss/ejb3/nointerface/mc/StatelessNoInterfaceJNDIBinder.java 2009-03-18 14:24:35 UTC (rev 86050)
@@ -26,7 +26,7 @@
import javax.naming.Name;
import org.jboss.ejb3.nointerface.NoInterfaceEJBViewCreator;
-import org.jboss.ejb3.nointerface.invocationhandler.NoInterfaceViewInvocationHandler;
+import org.jboss.ejb3.nointerface.invocationhandler.MCAwareNoInterfaceViewInvocationHandler;
import org.jboss.logging.Logger;
import org.jboss.metadata.ejb.jboss.JBossSessionBeanMetaData;
import org.jboss.util.naming.NonSerializableFactory;
@@ -66,9 +66,11 @@
logger.debug("Creating no-interface view for bean " + this.beanClass);
// Create the view and bind to jndi
+ // TODO: Incorrect cardinality
NoInterfaceEJBViewCreator noInterfaceViewCreator = new NoInterfaceEJBViewCreator();
- InvocationHandler invocationHandler = new NoInterfaceViewInvocationHandler(this.container, null);
+ InvocationHandler invocationHandler = new MCAwareNoInterfaceViewInvocationHandler(this.containerContext, null);
+
Object noInterfaceView = noInterfaceViewCreator.createView(invocationHandler, beanClass);
// bind
// TODO: Again, the jndi-names for the no-interface view are a mess now. They need to come from
Modified: projects/ejb3/trunk/nointerface/src/main/java/org/jboss/ejb3/nointerface/objectfactory/StatefulNoInterfaceViewObjectFactory.java
===================================================================
--- projects/ejb3/trunk/nointerface/src/main/java/org/jboss/ejb3/nointerface/objectfactory/StatefulNoInterfaceViewObjectFactory.java 2009-03-18 14:24:07 UTC (rev 86049)
+++ projects/ejb3/trunk/nointerface/src/main/java/org/jboss/ejb3/nointerface/objectfactory/StatefulNoInterfaceViewObjectFactory.java 2009-03-18 14:24:35 UTC (rev 86050)
@@ -29,7 +29,7 @@
import javax.naming.Reference;
import javax.naming.spi.ObjectFactory;
-import org.jboss.ejb3.nointerface.factory.StatefulNoInterfaceViewFactory;
+import org.jboss.ejb3.nointerface.factory.MCAwareStatefulNoInterfaceViewFactory;
import org.jboss.logging.Logger;
/**
@@ -43,6 +43,9 @@
private static Logger logger = Logger.getLogger(StatefulNoInterfaceViewObjectFactory.class);
+ /**
+ * @see ObjectFactory#getObjectInstance(Object, Name, Context, Hashtable)
+ */
public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable<?, ?> environment)
throws Exception
{
@@ -62,15 +65,20 @@
// now lookup the factory
Object proxyFactory = nameCtx.lookup(jndiNameOfStatefulProxyFactory);
- assert proxyFactory instanceof StatefulNoInterfaceViewFactory : "Unexpected type found at jndi name "
- + jndiNameOfStatefulProxyFactory + " Expected type " + StatefulNoInterfaceViewFactory.class.getName();
+ assert proxyFactory instanceof MCAwareStatefulNoInterfaceViewFactory : "Unexpected type found at jndi name "
+ + jndiNameOfStatefulProxyFactory + " Expected type " + MCAwareStatefulNoInterfaceViewFactory.class.getName();
- StatefulNoInterfaceViewFactory statefulNoInterfaceViewFactory = (StatefulNoInterfaceViewFactory) proxyFactory;
+ MCAwareStatefulNoInterfaceViewFactory statefulNoInterfaceViewFactory = (MCAwareStatefulNoInterfaceViewFactory) proxyFactory;
return statefulNoInterfaceViewFactory.createNoInterfaceView();
// TODO: Should not throw an exception, return null instead. see objectfactory reference
}
+ /**
+ * Returns the jndi-name at which the {@link MCAwareStatefulNoInterfaceViewFactory} can be found
+ * @param ref
+ * @return
+ */
protected String getProxyFactoryJNDINameFromReference(Reference ref)
{
RefAddr refAddr = ref
Modified: projects/ejb3/trunk/nointerface/src/test/java/org/jboss/ejb3/nointerface/test/deployers/MockContainerDeployer.java
===================================================================
--- projects/ejb3/trunk/nointerface/src/test/java/org/jboss/ejb3/nointerface/test/deployers/MockContainerDeployer.java 2009-03-18 14:24:07 UTC (rev 86049)
+++ projects/ejb3/trunk/nointerface/src/test/java/org/jboss/ejb3/nointerface/test/deployers/MockContainerDeployer.java 2009-03-18 14:24:35 UTC (rev 86050)
@@ -122,7 +122,7 @@
// install the container in MC. Getting the container name is currently duplicated (copied from)
// Ejb3NoInterfaceDeployer.
String containerName = getContainerName(unit, sessionBeanMetadata);
- BeanMetaDataBuilder builder = BeanMetaDataBuilder.createBuilder(containerName, InvokableContext.class.getName());
+ BeanMetaDataBuilder builder = BeanMetaDataBuilder.createBuilder(containerName, container.getClass().getName());
builder.setConstructorValue(container);
unit.addAttachment(BeanMetaData.class + ":" + containerName, builder.getBeanMetaData());
Modified: projects/ejb3/trunk/nointerface/src/test/java/org/jboss/ejb3/nointerface/test/viewcreator/unit/NoInterfaceEJBViewCreatorTestCase.java
===================================================================
--- projects/ejb3/trunk/nointerface/src/test/java/org/jboss/ejb3/nointerface/test/viewcreator/unit/NoInterfaceEJBViewCreatorTestCase.java 2009-03-18 14:24:07 UTC (rev 86049)
+++ projects/ejb3/trunk/nointerface/src/test/java/org/jboss/ejb3/nointerface/test/viewcreator/unit/NoInterfaceEJBViewCreatorTestCase.java 2009-03-18 14:24:35 UTC (rev 86050)
@@ -32,7 +32,7 @@
import javax.naming.InitialContext;
import javax.naming.NameNotFoundException;
-import org.jboss.ejb3.nointerface.factory.StatefulNoInterfaceViewFactory;
+import org.jboss.ejb3.nointerface.factory.MCAwareStatefulNoInterfaceViewFactory;
import org.jboss.ejb3.nointerface.test.common.AbstractNoInterfaceTestCase;
import org.jboss.ejb3.nointerface.test.viewcreator.ChildBean;
import org.jboss.ejb3.nointerface.test.viewcreator.SimpleSFSBeanWithoutInterfaces;
@@ -124,7 +124,7 @@
String statefulProxyFactoryJndiName = sessionBeanMetadata.getEjbName() + "/no-interface-stateful-proxyfactory";
// check the proxy factory
- assertBoundAndOfExpectedType(ctx, statefulProxyFactoryJndiName, StatefulNoInterfaceViewFactory.class);
+ assertBoundAndOfExpectedType(ctx, statefulProxyFactoryJndiName, MCAwareStatefulNoInterfaceViewFactory.class);
// check the view
assertBoundAndOfExpectedType(ctx, noInterfaceJndiName, SimpleSFSBeanWithoutInterfaces.class);
More information about the jboss-cvs-commits
mailing list