[jboss-cvs] JBossAS SVN: r64273 - in trunk/ejb3/src: main/org/jboss/ejb3/cache/simple and 9 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Jul 25 09:57:51 EDT 2007
Author: wolfc
Date: 2007-07-25 09:57:50 -0400 (Wed, 25 Jul 2007)
New Revision: 64273
Added:
trunk/ejb3/src/main/org/jboss/ejb3/EJBContextFactory.java
trunk/ejb3/src/main/org/jboss/ejb3/EJBContextImpl.java
trunk/ejb3/src/main/org/jboss/ejb3/mdb/MessageDrivenContextImpl.java
trunk/ejb3/src/main/org/jboss/ejb3/session/SessionBeanContext.java
trunk/ejb3/src/main/org/jboss/ejb3/session/SessionContextImpl.java
trunk/ejb3/src/main/org/jboss/ejb3/stateful/StatefulSessionContextImpl.java
trunk/ejb3/src/test/org/jboss/ejb3/test/interceptormetadata/
trunk/ejb3/src/test/org/jboss/ejb3/test/interceptormetadata/MockDependencyPolicy.java
Removed:
trunk/ejb3/src/main/org/jboss/ejb3/BaseSessionContext.java
Modified:
trunk/ejb3/src/main/org/jboss/ejb3/AbstractPool.java
trunk/ejb3/src/main/org/jboss/ejb3/BaseContext.java
trunk/ejb3/src/main/org/jboss/ejb3/BeanContext.java
trunk/ejb3/src/main/org/jboss/ejb3/Container.java
trunk/ejb3/src/main/org/jboss/ejb3/EJBContainer.java
trunk/ejb3/src/main/org/jboss/ejb3/Ejb3Registry.java
trunk/ejb3/src/main/org/jboss/ejb3/Pool.java
trunk/ejb3/src/main/org/jboss/ejb3/StrictMaxPool.java
trunk/ejb3/src/main/org/jboss/ejb3/ThreadlocalPool.java
trunk/ejb3/src/main/org/jboss/ejb3/cache/simple/StatefulSessionFilePersistenceManager.java
trunk/ejb3/src/main/org/jboss/ejb3/mdb/MDBContext.java
trunk/ejb3/src/main/org/jboss/ejb3/mdb/MessagingContainer.java
trunk/ejb3/src/main/org/jboss/ejb3/service/ServiceBeanContext.java
trunk/ejb3/src/main/org/jboss/ejb3/service/ServiceContainer.java
trunk/ejb3/src/main/org/jboss/ejb3/stateful/NestedStatefulBeanContext.java
trunk/ejb3/src/main/org/jboss/ejb3/stateful/ProxiedStatefulBeanContext.java
trunk/ejb3/src/main/org/jboss/ejb3/stateful/StatefulBeanContext.java
trunk/ejb3/src/main/org/jboss/ejb3/stateful/StatefulBeanContextReference.java
trunk/ejb3/src/main/org/jboss/ejb3/stateful/StatefulContainer.java
trunk/ejb3/src/main/org/jboss/ejb3/stateful/StatefulInstanceInterceptor.java
trunk/ejb3/src/main/org/jboss/ejb3/stateless/StatelessBeanContext.java
trunk/ejb3/src/main/org/jboss/ejb3/stateless/StatelessContainer.java
trunk/ejb3/src/main/org/jboss/ejb3/stateless/StatelessInstanceInterceptor.java
trunk/ejb3/src/test/org/jboss/ejb3/test/stateful/nested/base/BeanMonitorBean.java
trunk/ejb3/src/test/org/jboss/ejb3/test/strictpool/BogusPool.java
Log:
EJBTHREE-1016: Refactored bean context
Modified: trunk/ejb3/src/main/org/jboss/ejb3/AbstractPool.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/AbstractPool.java 2007-07-25 13:43:49 UTC (rev 64272)
+++ trunk/ejb3/src/main/org/jboss/ejb3/AbstractPool.java 2007-07-25 13:57:50 UTC (rev 64273)
@@ -21,6 +21,9 @@
*/
package org.jboss.ejb3;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+
import org.jboss.injection.Injector;
import org.jboss.annotation.ejb.cache.tree.CacheConfig;
import org.jboss.aop.Advisor;
@@ -36,10 +39,8 @@
*/
public abstract class AbstractPool implements Pool
{
- private static final Logger log = Logger.getLogger(EJBContainer.class);
+ private static final Logger log = Logger.getLogger(AbstractPool.class);
- protected Class beanClass;
- protected Class contextClass;
protected Injector[] injectors;
protected Container container;
@@ -48,40 +49,22 @@
}
- public void initialize(Container container, Class contextClass, Class beanClass, int maxSize, long timeout)
+ public void initialize(Container container, int maxSize, long timeout)
{
- this.beanClass = beanClass;
- this.contextClass = contextClass;
+ assert container != null : "container is null";
+
this.container = container;
}
- public void setMaxSize(int maxSize)
- {
- }
+ public abstract void setMaxSize(int maxSize);
- protected BeanContext create()
+ protected BeanContext<?> create()
{
- Object bean;
- BeanContext ctx;
- try
- {
- bean = container.construct();
- ctx = (BeanContext) contextClass.newInstance();
- ctx.setContainer(container);
- ctx.setInstance(bean);
- }
- catch (InstantiationException e)
- {
- throw new RuntimeException(e); //To change body of catch statement use Options | File Templates.
- }
- catch (IllegalAccessException e)
- {
- throw new RuntimeException(e); //To change body of catch statement use Options | File Templates.
- }
+ BeanContext<?> ctx;
+ ctx = createBeanContext();
if (ctx instanceof StatefulBeanContext)
{
StatefulBeanContext sfctx = (StatefulBeanContext) ctx;
- sfctx.setId(new GUID());
// Tell context how to handle replication
Advisor advisor = (Advisor) container;
CacheConfig config = (CacheConfig) advisor.resolveAnnotation(CacheConfig.class);
@@ -92,6 +75,7 @@
// this is for propagated extended PC's
ctx = sfctx = sfctx.pushContainedIn();
}
+ container.pushContext(ctx);
try
{
if (injectors != null)
@@ -107,6 +91,7 @@
}
finally
{
+ container.popContext();
if (ctx instanceof StatefulBeanContext)
{
// this is for propagated extended PC's
@@ -116,35 +101,19 @@
}
//TODO This needs to be reimplemented as replacement for create() on home interface
- container.invokeInit(bean);
+ container.invokeInit(ctx.getInstance());
container.invokePostConstruct(ctx, new Object[0]);
return ctx;
}
- protected BeanContext create(Class[] initTypes, Object[] initValues)
+ protected BeanContext<?> create(Class[] initTypes, Object[] initValues)
{
- Object bean;
BeanContext ctx;
- try
- {
- bean = container.construct();
- ctx = (BeanContext) contextClass.newInstance();
- ctx.setContainer(container);
- ctx.setInstance(bean);
- }
- catch (InstantiationException e)
- {
- throw new RuntimeException(e); //To change body of catch statement use Options | File Templates.
- }
- catch (IllegalAccessException e)
- {
- throw new RuntimeException(e); //To change body of catch statement use Options | File Templates.
- }
+ ctx = createBeanContext();
if (ctx instanceof StatefulBeanContext)
{
StatefulBeanContext sfctx = (StatefulBeanContext) ctx;
- sfctx.setId(new GUID());
// Tell context how to handle replication
Advisor advisor = (Advisor) container;
CacheConfig config = (CacheConfig) advisor.resolveAnnotation(CacheConfig.class);
@@ -155,6 +124,7 @@
// this is for propagated extended PC's
ctx = sfctx = sfctx.pushContainedIn();
}
+ container.pushContext(ctx);
try
{
if (injectors != null)
@@ -170,6 +140,7 @@
}
finally
{
+ container.popContext();
if (ctx instanceof StatefulBeanContext)
{
// this is for propagated extended PC's
@@ -178,12 +149,17 @@
}
}
//TODO This needs to be reimplemented as replacement for create() on home interface
- container.invokeInit(bean, initTypes, initValues);
+ container.invokeInit(ctx.getInstance(), initTypes, initValues);
container.invokePostConstruct(ctx, initValues);
return ctx;
}
+ private BeanContext createBeanContext()
+ {
+ return container.createBeanContext();
+ }
+
public void remove(BeanContext ctx)
{
try
Modified: trunk/ejb3/src/main/org/jboss/ejb3/BaseContext.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/BaseContext.java 2007-07-25 13:43:49 UTC (rev 64272)
+++ trunk/ejb3/src/main/org/jboss/ejb3/BaseContext.java 2007-07-25 13:57:50 UTC (rev 64273)
@@ -23,15 +23,11 @@
import java.util.HashMap;
import java.util.HashSet;
-import javax.ejb.EJBContext;
-import javax.naming.InitialContext;
-import javax.naming.NamingEnumeration;
import org.jboss.aop.metadata.SimpleMetaData;
import org.jboss.ejb3.interceptor.InterceptorInfo;
import org.jboss.ejb3.interceptor.InterceptorInjector;
import org.jboss.logging.Logger;
-import org.jboss.naming.Util;
import org.jboss.security.RealmMapping;
/**
@@ -40,38 +36,52 @@
* @author <a href="mailto:bill at jboss.org">Bill Burke</a>
* @version $Revision$
*/
-public abstract class BaseContext implements BeanContext
+public abstract class BaseContext<T extends Container> implements BeanContext<T>
{
protected static Logger log = Logger.getLogger(BaseContext.class);
- protected Container container;
+ protected T container;
protected Object bean;
protected RealmMapping rm;
protected SimpleMetaData metadata;
- protected EJBContext ejbContext;
protected HashMap<Class, Object> interceptorInstances;
- public BaseContext()
+ /**
+ * Use with extreme caution, must not break getInstance post condition.
+ *
+ * @param container
+ */
+ protected BaseContext(T container)
{
+ assert container != null : "container is null";
+
+ this.container = container;
}
+ protected BaseContext(T container, Object bean)
+ {
+ this(container);
+
+ assert bean != null : "bean is null";
+
+ this.bean = bean;
+ }
+
public Object getId()
{
return null;
}
+ /**
+ * Returns the enterprise bean, never returns null.
+ */
public Object getInstance()
{
return bean;
}
- public void setInstance(Object instance)
+ public T getContainer()
{
- bean = instance;
- }
-
- public Container getContainer()
- {
return container;
}
@@ -81,25 +91,6 @@
return metadata;
}
- public void setContainer(Container container)
- {
- this.container = container;
- bindEJBContext();
- }
-
- public void bindEJBContext()
- {
- try
- {
- Util.rebind(container.getEnc(), "EJBContext", getEJBContext());
- }
- catch (javax.naming.NamingException e)
- {
- e.printStackTrace();
- throw new RuntimeException(e);
- }
- }
-
public void initialiseInterceptorInstances()
{
HashSet<InterceptorInfo> interceptors = ((EJBContainer)container).getApplicableInterceptors();
@@ -123,18 +114,6 @@
}
}
- public EJBContext getEJBContext()
- {
- if (ejbContext == null)
- {
- BaseSessionContext bsc = new BaseSessionContext();
- bsc.setContainer(getContainer());
- bsc.setBaseContext(this);
- ejbContext = bsc;
- }
- return ejbContext;
- }
-
public Object[] getInterceptorInstances(InterceptorInfo[] interceptorInfos)
{
Object[] interceptors = new Object[interceptorInfos.length];
Deleted: trunk/ejb3/src/main/org/jboss/ejb3/BaseSessionContext.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/BaseSessionContext.java 2007-07-25 13:43:49 UTC (rev 64272)
+++ trunk/ejb3/src/main/org/jboss/ejb3/BaseSessionContext.java 2007-07-25 13:57:50 UTC (rev 64273)
@@ -1,391 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2006, 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;
-
-import java.io.Externalizable;
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
-import java.security.Identity;
-import java.security.Principal;
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Properties;
-
-import javax.ejb.EJBException;
-import javax.ejb.EJBHome;
-import javax.ejb.EJBLocalHome;
-import javax.ejb.EJBLocalObject;
-import javax.ejb.EJBObject;
-import javax.ejb.MessageDrivenContext;
-import javax.ejb.SessionContext;
-import javax.ejb.TimerService;
-import javax.ejb.TransactionManagementType;
-import javax.naming.InitialContext;
-import javax.naming.NamingException;
-import javax.transaction.Status;
-import javax.transaction.SystemException;
-import javax.transaction.TransactionManager;
-import javax.transaction.UserTransaction;
-import javax.xml.rpc.handler.MessageContext;
-
-import org.jboss.annotation.security.RunAsPrincipal;
-import org.jboss.annotation.security.SecurityDomain;
-import org.jboss.aop.Advisor;
-import org.jboss.ejb3.security.SecurityDomainManager;
-import org.jboss.ejb3.session.SessionContainer;
-import org.jboss.ejb3.stateless.StatelessBeanContext;
-import org.jboss.ejb3.tx.TxUtil;
-import org.jboss.ejb3.tx.UserTransactionImpl;
-import org.jboss.logging.Logger;
-import org.jboss.security.RealmMapping;
-import org.jboss.security.RunAsIdentity;
-import org.jboss.security.SecurityAssociation;
-import org.jboss.security.SimplePrincipal;
-
-import org.jboss.metamodel.descriptor.SecurityRoleRef;
-
-/**
- * Comment
- *
- * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
- * @version $Revision$
- */
-public class BaseSessionContext implements SessionContext, MessageDrivenContext, Externalizable
-{
- private static final long serialVersionUID = -2485139227124937217L;
-
- private static final Logger log = Logger.getLogger(BaseSessionContext.class);
- protected transient EJBContainer container;
- protected transient RealmMapping rm;
- protected BaseContext baseContext;
-
- public BaseSessionContext()
- {
- }
-
- public void setBaseContext(BaseContext baseContext)
- {
- this.baseContext = baseContext;
- }
-
- public Container getContainer()
- {
- return container;
- }
-
- public void setContainer(Container container)
- {
- this.container = (EJBContainer)container;
- try
- {
- InitialContext ctx = container.getInitialContext();
- setupSecurityDomain(container, ctx);
- }
- catch (NamingException e)
- {
- throw new RuntimeException(e);
- }
- }
-
- private void setupSecurityDomain(Container container, InitialContext ctx)
- throws NamingException
- {
- SecurityDomain securityAnnotation = (SecurityDomain) ((Advisor) container).resolveAnnotation(SecurityDomain.class);
- if (securityAnnotation == null) return;
- Object domain = SecurityDomainManager.getSecurityManager(securityAnnotation.value(), ctx);
- rm = (RealmMapping) domain;
- }
-
- protected RealmMapping getRm()
- {
- return rm;
- }
-
- public void writeExternal(ObjectOutput out) throws IOException
- {
- out.writeUTF(container.getObjectName().getCanonicalName());
- }
-
- public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
- {
- container = (EJBContainer)Ejb3Registry.getContainer(in.readUTF());
- InitialContext ctx = container.getInitialContext();
- try
- {
- setupSecurityDomain(container, ctx);
- }
- catch (NamingException e)
- {
- throw new RuntimeException(e);
- }
-
- }
-
-
- //----------------
-
- public Object lookup(String name)
- {
- String newName;
- if (name.startsWith("/"))
- {
- newName = "env" + name;
- }
- else
- {
- newName = "env/" + name;
- }
- try
- {
- return getContainer().getEnc().lookup(newName);
- }
- catch (NamingException ignored)
- {
- try
- {
- return getContainer().getInitialContext().lookup(name);
- }
- catch (NamingException ignored2)
- {
-
- }
- }
- return null;
- }
-
- public Identity getCallerIdentity()
- {
- throw new IllegalStateException("deprecated");
- }
-
- public Principal getCallerPrincipal()
- {
- Principal principal = null;
-
- RunAsIdentity runAsIdentity = SecurityActions.peekRunAsIdentity(1);
-
- principal = SecurityAssociation.getCallerPrincipal();
-
- if (getRm() != null)
- {
- principal = getRm().getPrincipal(principal);
- }
-
- // This method never returns null.
- if (principal == null)
- throw new java.lang.IllegalStateException("No valid security context for the caller identity");
-
- return principal;
- }
-
- public boolean isCallerInRole(Identity role)
- {
- throw new IllegalStateException("deprecated");
- }
-
- public boolean isCallerInRole(String roleName)
- {
- // TODO revert to aspects.security.SecurityContext impl when JBoss AOP 1.1 is out.
- Principal principal = getCallerPrincipal();
-
- // Check the caller of this beans run-as identity
- // todo use priveleged stuff in ejb class
- RunAsIdentity runAsIdentity = SecurityActions.peekRunAsIdentity(1);
-
- if (principal == null && runAsIdentity == null)
- return false;
-
- if (getRm() == null)
- {
- String msg = "isCallerInRole() called with no security context. "
- + "Check that a security-domain has been set for the application.";
- throw new IllegalStateException(msg);
- }
-
- //Ensure that you go through the security role references that may be configured
- EJBContainer ejbc = (EJBContainer)container;
- if(ejbc.getXml() != null)
- {
- Collection<SecurityRoleRef> securityRoleRefs = ejbc.getXml().getSecurityRoleRefs();
- for(SecurityRoleRef roleRef: securityRoleRefs)
- {
- String refName = roleRef.getRoleName();
- if(roleName.equals(refName))
- roleName = roleRef.getRoleLink();
- }
- }
-
- HashSet set = new HashSet();
- set.add(new SimplePrincipal(roleName));
-
- // This is work in progress - currently, getRm().doesUserHaveRole(principal, set)
- // and getRm().getUserRoles(principal) ignores the principal parameter and is not
- // using the principal from the pushed RunAsIdentity
- boolean doesUserHaveRole = false;
- if (runAsIdentity != null)
- doesUserHaveRole = runAsIdentity.doesUserHaveRole(set);
-
- if (!doesUserHaveRole)
- doesUserHaveRole = getRm().doesUserHaveRole(principal, set);
-
- java.util.Set roles = getRm().getUserRoles(principal);
-
- return doesUserHaveRole;
- }
-
- public TimerService getTimerService() throws IllegalStateException
- {
- return getContainer().getTimerService();
- }
-
- public UserTransaction getUserTransaction() throws IllegalStateException
- {
- TransactionManagementType type = TxUtil.getTransactionManagementType(((Advisor) getContainer()));
- if (type != TransactionManagementType.BEAN) throw new IllegalStateException("Container " + getContainer().getEjbName() + ": it is illegal to inject UserTransaction into a CMT bean");
-
- return new UserTransactionImpl();
- }
-
- public EJBHome getEJBHome()
- {
- throw new EJBException("EJB 3.0 does not have a home type.");
- }
-
- public EJBLocalHome getEJBLocalHome()
- {
- throw new EJBException("EJB 3.0 does not have a home type.");
- }
-
- public Properties getEnvironment()
- {
- throw new EJBException("Deprecated");
- }
-
- public void setRollbackOnly() throws IllegalStateException
- {
- // EJB1.1 11.6.1: Must throw IllegalStateException if BMT
- TransactionManagementType type = TxUtil.getTransactionManagementType(((Advisor) getContainer()));
- if (type != TransactionManagementType.CONTAINER) throw new IllegalStateException("Container " + getContainer().getEjbName() + ": it is illegal to call setRollbackOnly from BMT: " + type);
-
- try
- {
- TransactionManager tm = TxUtil.getTransactionManager();
-
- // The getRollbackOnly and setRollBackOnly method of the SessionContext interface should be used
- // only in the session bean methods that execute in the context of a transaction.
- if (tm.getTransaction() == null)
- throw new IllegalStateException("setRollbackOnly() not allowed without a transaction.");
-
- tm.setRollbackOnly();
- }
- catch (SystemException e)
- {
- log.warn("failed to set rollback only; ignoring", e);
- }
- }
-
- public boolean getRollbackOnly() throws IllegalStateException
- {
- // EJB1.1 11.6.1: Must throw IllegalStateException if BMT
- TransactionManagementType type = TxUtil.getTransactionManagementType(((Advisor) getContainer()));
- if (type != TransactionManagementType.CONTAINER)
- throw new IllegalStateException("Container " + getContainer().getEjbName() + ": it is illegal to call getRollbackOnly from BMT: " + type);
-
- try
- {
- TransactionManager tm = TxUtil.getTransactionManager();
-
- // The getRollbackOnly and setRollBackOnly method of the SessionContext interface should be used
- // only in the session bean methods that execute in the context of a transaction.
- if (tm.getTransaction() == null)
- throw new IllegalStateException("getRollbackOnly() not allowed without a transaction.");
-
- // EJBTHREE-805, consider an asynchronous rollback due to timeout
- int status = tm.getStatus();
- return status == Status.STATUS_MARKED_ROLLBACK
- || status == Status.STATUS_ROLLING_BACK
- || status == Status.STATUS_ROLLEDBACK;
- }
- catch (SystemException e)
- {
- log.warn("failed to get tx manager status; ignoring", e);
- return true;
- }
- }
-
- public EJBLocalObject getEJBLocalObject() throws IllegalStateException
- {
- try
- {
- Object id = baseContext.getId();
- EJBLocalObject proxy = (EJBLocalObject)((SessionContainer)container).createLocalProxy(id);
- return proxy;
- }
- catch (Exception e)
- {
- throw new IllegalStateException(e);
- }
- }
-
- public EJBObject getEJBObject() throws IllegalStateException
- {
- try
- {
- Object id = baseContext.getId();
- EJBObject proxy = (EJBObject)((SessionContainer)container).createRemoteProxy(id);
- return proxy;
- }
- catch (Exception e)
- {
- throw new IllegalStateException(e);
- }
- }
-
- public Object getBusinessObject(Class businessInterface) throws IllegalStateException
- {
- if(businessInterface == null)
- throw new IllegalStateException("businessInterface is null");
-
- return ((EJBContainer)container).getBusinessObject(baseContext, businessInterface);
- }
-
- public Class getInvokedBusinessInterface() throws IllegalStateException
- {
- return ((SessionContainer)container).getInvokedBusinessInterface();
- }
-
- public MessageContext getMessageContext() throws IllegalStateException
- {
- // disallowed for stateful session beans (EJB3 FR 4.4.1 p 81)
- if(baseContext instanceof StatelessBeanContext)
- {
- MessageContext ctx = ((StatelessBeanContext) baseContext).getMessageContextJAXRPC();
- if(ctx == null)
- throw new IllegalStateException("No message context found");
- return ctx;
- }
- throw new UnsupportedOperationException("Only stateless beans can have a message context");
- }
-
-}
Modified: trunk/ejb3/src/main/org/jboss/ejb3/BeanContext.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/BeanContext.java 2007-07-25 13:43:49 UTC (rev 64272)
+++ trunk/ejb3/src/main/org/jboss/ejb3/BeanContext.java 2007-07-25 13:57:50 UTC (rev 64273)
@@ -25,23 +25,20 @@
import org.jboss.aop.metadata.SimpleMetaData;
import org.jboss.ejb3.interceptor.InterceptorInfo;
-
/**
- * Comment
+ * An instance of an enterprise bean linked to its container.
+ *
+ * Must have a constructor with container argument.
*
* @author <a href="mailto:bill at jboss.org">Bill Burke</a>
* @version $Revision$
*/
-public interface BeanContext
+public interface BeanContext<T extends Container>
{
Object getInstance();
- void setInstance(Object instance);
+ T getContainer();
- Container getContainer();
-
- void setContainer(Container container);
-
void initialiseInterceptorInstances();
void remove();
@@ -51,6 +48,6 @@
EJBContext getEJBContext();
Object[] getInterceptorInstances(InterceptorInfo[] interceptorInfos);
-
- Object getInvokedMethodKey();
+//
+// Object getInvokedMethodKey();
}
Modified: trunk/ejb3/src/main/org/jboss/ejb3/Container.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/Container.java 2007-07-25 13:43:49 UTC (rev 64272)
+++ trunk/ejb3/src/main/org/jboss/ejb3/Container.java 2007-07-25 13:57:50 UTC (rev 64273)
@@ -43,6 +43,13 @@
{
String ENC_CTX_NAME = "java:comp";
+ // TODO: Wolf: I don't like this, why the '?', and why the public method
+ /**
+ * Create a bean context for use in a pool.
+ * @return a ready to use bean context
+ */
+ BeanContext<?> createBeanContext();
+
Class getBeanClass();
String getEjbName();
@@ -58,8 +65,6 @@
Pool getPool();
- Object construct();
-
void invokePostConstruct(BeanContext beanContext, Object[] params);
void invokePreDestroy(BeanContext beanContext);
@@ -72,6 +77,12 @@
void invokeInit(Object bean, Class[] initTypes, Object[] initValues);
+ BeanContext<?> peekContext();
+
+ BeanContext<?> popContext();
+
+ void pushContext(BeanContext<?> ctx);
+
public void create() throws Exception;
public void start() throws Exception;
Modified: trunk/ejb3/src/main/org/jboss/ejb3/EJBContainer.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/EJBContainer.java 2007-07-25 13:43:49 UTC (rev 64272)
+++ trunk/ejb3/src/main/org/jboss/ejb3/EJBContainer.java 2007-07-25 13:57:50 UTC (rev 64273)
@@ -40,6 +40,7 @@
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
+import javax.ejb.EJBContext;
import javax.ejb.Local;
import javax.ejb.Remote;
import javax.ejb.Timeout;
@@ -50,6 +51,8 @@
import javax.naming.LinkRef;
import javax.naming.NameNotFoundException;
import javax.naming.NamingException;
+import javax.naming.Reference;
+import javax.naming.StringRefAddr;
import org.jboss.annotation.ejb.Clustered;
import org.jboss.annotation.ejb.PoolClass;
@@ -129,8 +132,6 @@
protected Context enc;
- protected Class beanContextClass;
-
//protected SessionCallbackHandler callbackHandler;
protected LifecycleInterceptorHandler callbackHandler;
@@ -165,6 +166,8 @@
private List<Class<?>> businessInterfaces;
+ private ThreadLocalStack<BeanContext<?>> currentBean = new ThreadLocalStack<BeanContext<?>>();
+
/**
* @param name Advisor name
* @param manager Domain to get interceptor bindings from
@@ -221,10 +224,25 @@
this.interceptorRepository = interceptorRepository;
this.interceptorRepository.addBeanClass(clazz.getName());
bindORB();
+ bindEJBContext();
this.dependencyPolicy = deployment.createDependencyPolicy(this);
}
+ private void bindEJBContext()
+ {
+ try
+ {
+ Reference ref = new Reference(EJBContext.class.getName(), EJBContextFactory.class.getName(), null);
+ ref.add(new StringRefAddr("oid", getObjectName().getCanonicalName()));
+ Util.rebind(getEnc(), "EJBContext", ref);
+ }
+ catch (NamingException e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+
private void bindORB()
{
try
@@ -237,6 +255,8 @@
}
}
+ public abstract BeanContext<?> createBeanContext();
+
public String createObjectName(String ejbName)
{
return JavaEEComponentHelper.createObjectName(deployment, ejbName);
@@ -257,6 +277,11 @@
this.encFactory = encFactory;
}
+ public void pushContext(BeanContext<?> beanContext)
+ {
+ currentBean.push(beanContext);
+ }
+
/**
* Makes sure that EJB's ENC is available
* Delegates to whatever implementation is used to push the ENC of the EJB
@@ -268,7 +293,18 @@
encFactory.pushEnc(this);
}
-
+ public BeanContext<?> peekContext()
+ {
+ BeanContext<?> ctx = currentBean.get();
+ assert ctx != null : "ctx is null";
+ return ctx;
+ }
+
+ public BeanContext<?> popContext()
+ {
+ return currentBean.pop();
+ }
+
/**
* Pops EJB's ENC from the stack. Delegates to whatever implementation
* is used to pop the EJB's ENC from the stock
@@ -604,7 +640,7 @@
return partitionName;
}
- public Object construct()
+ protected Object construct()
{
Interceptor[] cInterceptors = constructorInterceptors[defaultConstructorIndex];
if (cInterceptors == null)
@@ -727,7 +763,7 @@
int maxSize = poolClass.maxSize();
long timeout = poolClass.timeout();
pool = poolClazz.newInstance();
- pool.initialize(this, beanContextClass, clazz, maxSize, timeout);
+ pool.initialize(this, maxSize, timeout);
resolveInjectors();
pool.setInjectors(injectors.toArray(new Injector[injectors.size()]));
@@ -868,7 +904,7 @@
partitionName = value;
}
- public Object getBusinessObject(BeanContext beanContext, Class businessObject) throws IllegalStateException
+ public <T> T getBusinessObject(BeanContext<?> beanContext, Class<T> businessInterface) throws IllegalStateException
{
throw new IllegalStateException("Not implemented");
}
Added: trunk/ejb3/src/main/org/jboss/ejb3/EJBContextFactory.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/EJBContextFactory.java (rev 0)
+++ trunk/ejb3/src/main/org/jboss/ejb3/EJBContextFactory.java 2007-07-25 13:57:50 UTC (rev 64273)
@@ -0,0 +1,49 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2007, Red Hat Middleware LLC, and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt 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;
+
+import java.util.Hashtable;
+
+import javax.naming.Context;
+import javax.naming.Name;
+import javax.naming.Reference;
+import javax.naming.spi.ObjectFactory;
+
+/**
+ * Comment
+ *
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class EJBContextFactory implements ObjectFactory
+{
+ /* (non-Javadoc)
+ * @see javax.naming.spi.ObjectFactory#getObjectInstance(java.lang.Object, javax.naming.Name, javax.naming.Context, java.util.Hashtable)
+ */
+ public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable<?, ?> environment)
+ throws Exception
+ {
+ Reference ref = (Reference) obj;
+ String oid = (String) ref.get("oid").getContent();
+ return Ejb3Registry.getContainer(oid).peekContext().getEJBContext();
+ }
+}
Property changes on: trunk/ejb3/src/main/org/jboss/ejb3/EJBContextFactory.java
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:eol-style
+ native
Copied: trunk/ejb3/src/main/org/jboss/ejb3/EJBContextImpl.java (from rev 64244, trunk/ejb3/src/main/org/jboss/ejb3/BaseSessionContext.java)
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/EJBContextImpl.java (rev 0)
+++ trunk/ejb3/src/main/org/jboss/ejb3/EJBContextImpl.java 2007-07-25 13:57:50 UTC (rev 64273)
@@ -0,0 +1,274 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, 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;
+
+import java.security.Identity;
+import java.security.Principal;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Properties;
+
+import javax.ejb.EJBContext;
+import javax.ejb.EJBException;
+import javax.ejb.EJBHome;
+import javax.ejb.EJBLocalHome;
+import javax.ejb.TimerService;
+import javax.ejb.TransactionManagementType;
+import javax.naming.NamingException;
+import javax.transaction.Status;
+import javax.transaction.SystemException;
+import javax.transaction.TransactionManager;
+import javax.transaction.UserTransaction;
+
+import org.jboss.aop.Advisor;
+import org.jboss.ejb3.tx.TxUtil;
+import org.jboss.ejb3.tx.UserTransactionImpl;
+import org.jboss.logging.Logger;
+import org.jboss.metamodel.descriptor.SecurityRoleRef;
+import org.jboss.security.RealmMapping;
+import org.jboss.security.RunAsIdentity;
+import org.jboss.security.SecurityAssociation;
+import org.jboss.security.SimplePrincipal;
+
+/**
+ * Comment
+ *
+ * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
+ * @version $Revision$
+ */
+public abstract class EJBContextImpl<T extends Container, B extends BeanContext<T>> implements EJBContext
+{
+ private static final Logger log = Logger.getLogger(EJBContextImpl.class);
+ protected transient T container;
+ protected transient RealmMapping rm;
+ protected B beanContext;
+
+ protected EJBContextImpl(B beanContext)
+ {
+ assert beanContext != null : "beanContext is null";
+
+ this.beanContext = beanContext;
+ this.container = beanContext.getContainer();
+ this.rm = container.getSecurityManager(RealmMapping.class);
+ }
+
+ protected T getContainer()
+ {
+ return container;
+ }
+
+ protected RealmMapping getRm()
+ {
+ return rm;
+ }
+
+ public Object lookup(String name)
+ {
+ String newName;
+ if (name.startsWith("/"))
+ {
+ newName = "env" + name;
+ }
+ else
+ {
+ newName = "env/" + name;
+ }
+ try
+ {
+ return getContainer().getEnc().lookup(newName);
+ }
+ catch (NamingException ignored)
+ {
+ try
+ {
+ return getContainer().getInitialContext().lookup(name);
+ }
+ catch (NamingException ignored2)
+ {
+
+ }
+ }
+ return null;
+ }
+
+ @SuppressWarnings("deprecation")
+ public Identity getCallerIdentity()
+ {
+ throw new IllegalStateException("deprecated");
+ }
+
+ public Principal getCallerPrincipal()
+ {
+ Principal principal = null;
+
+ RunAsIdentity runAsIdentity = SecurityActions.peekRunAsIdentity(1);
+
+ principal = SecurityAssociation.getCallerPrincipal();
+
+ if (getRm() != null)
+ {
+ principal = getRm().getPrincipal(principal);
+ }
+
+ // This method never returns null.
+ if (principal == null)
+ throw new java.lang.IllegalStateException("No valid security context for the caller identity");
+
+ return principal;
+ }
+
+ @SuppressWarnings("deprecation")
+ public boolean isCallerInRole(Identity role)
+ {
+ throw new IllegalStateException("deprecated");
+ }
+
+ public boolean isCallerInRole(String roleName)
+ {
+ // TODO revert to aspects.security.SecurityContext impl when JBoss AOP 1.1 is out.
+ Principal principal = getCallerPrincipal();
+
+ // Check the caller of this beans run-as identity
+ // todo use priveleged stuff in ejb class
+ RunAsIdentity runAsIdentity = SecurityActions.peekRunAsIdentity(1);
+
+ if (principal == null && runAsIdentity == null)
+ return false;
+
+ if (getRm() == null)
+ {
+ String msg = "isCallerInRole() called with no security context. "
+ + "Check that a security-domain has been set for the application.";
+ throw new IllegalStateException(msg);
+ }
+
+ //Ensure that you go through the security role references that may be configured
+ EJBContainer ejbc = (EJBContainer)container;
+ if(ejbc.getXml() != null)
+ {
+ Collection<SecurityRoleRef> securityRoleRefs = ejbc.getXml().getSecurityRoleRefs();
+ for(SecurityRoleRef roleRef: securityRoleRefs)
+ {
+ String refName = roleRef.getRoleName();
+ if(roleName.equals(refName))
+ roleName = roleRef.getRoleLink();
+ }
+ }
+
+ HashSet set = new HashSet();
+ set.add(new SimplePrincipal(roleName));
+
+ // This is work in progress - currently, getRm().doesUserHaveRole(principal, set)
+ // and getRm().getUserRoles(principal) ignores the principal parameter and is not
+ // using the principal from the pushed RunAsIdentity
+ boolean doesUserHaveRole = false;
+ if (runAsIdentity != null)
+ doesUserHaveRole = runAsIdentity.doesUserHaveRole(set);
+
+ if (!doesUserHaveRole)
+ doesUserHaveRole = getRm().doesUserHaveRole(principal, set);
+
+ java.util.Set roles = getRm().getUserRoles(principal);
+
+ return doesUserHaveRole;
+ }
+
+ public TimerService getTimerService() throws IllegalStateException
+ {
+ return getContainer().getTimerService();
+ }
+
+ public UserTransaction getUserTransaction() throws IllegalStateException
+ {
+ TransactionManagementType type = TxUtil.getTransactionManagementType(((Advisor) getContainer()));
+ if (type != TransactionManagementType.BEAN) throw new IllegalStateException("Container " + getContainer().getEjbName() + ": it is illegal to inject UserTransaction into a CMT bean");
+
+ return new UserTransactionImpl();
+ }
+
+ public EJBHome getEJBHome()
+ {
+ throw new EJBException("EJB 3.0 does not have a home type.");
+ }
+
+ public EJBLocalHome getEJBLocalHome()
+ {
+ throw new EJBException("EJB 3.0 does not have a home type.");
+ }
+
+ public Properties getEnvironment()
+ {
+ throw new EJBException("Deprecated");
+ }
+
+ public void setRollbackOnly() throws IllegalStateException
+ {
+ // EJB1.1 11.6.1: Must throw IllegalStateException if BMT
+ TransactionManagementType type = TxUtil.getTransactionManagementType(((Advisor) getContainer()));
+ if (type != TransactionManagementType.CONTAINER) throw new IllegalStateException("Container " + getContainer().getEjbName() + ": it is illegal to call setRollbackOnly from BMT: " + type);
+
+ try
+ {
+ TransactionManager tm = TxUtil.getTransactionManager();
+
+ // The getRollbackOnly and setRollBackOnly method of the SessionContext interface should be used
+ // only in the session bean methods that execute in the context of a transaction.
+ if (tm.getTransaction() == null)
+ throw new IllegalStateException("setRollbackOnly() not allowed without a transaction.");
+
+ tm.setRollbackOnly();
+ }
+ catch (SystemException e)
+ {
+ log.warn("failed to set rollback only; ignoring", e);
+ }
+ }
+
+ public boolean getRollbackOnly() throws IllegalStateException
+ {
+ // EJB1.1 11.6.1: Must throw IllegalStateException if BMT
+ TransactionManagementType type = TxUtil.getTransactionManagementType(((Advisor) getContainer()));
+ if (type != TransactionManagementType.CONTAINER)
+ throw new IllegalStateException("Container " + getContainer().getEjbName() + ": it is illegal to call getRollbackOnly from BMT: " + type);
+
+ try
+ {
+ TransactionManager tm = TxUtil.getTransactionManager();
+
+ // The getRollbackOnly and setRollBackOnly method of the SessionContext interface should be used
+ // only in the session bean methods that execute in the context of a transaction.
+ if (tm.getTransaction() == null)
+ throw new IllegalStateException("getRollbackOnly() not allowed without a transaction.");
+
+ // EJBTHREE-805, consider an asynchronous rollback due to timeout
+ int status = tm.getStatus();
+ return status == Status.STATUS_MARKED_ROLLBACK
+ || status == Status.STATUS_ROLLING_BACK
+ || status == Status.STATUS_ROLLEDBACK;
+ }
+ catch (SystemException e)
+ {
+ log.warn("failed to get tx manager status; ignoring", e);
+ return true;
+ }
+ }
+}
Modified: trunk/ejb3/src/main/org/jboss/ejb3/Ejb3Registry.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/Ejb3Registry.java 2007-07-25 13:43:49 UTC (rev 64272)
+++ trunk/ejb3/src/main/org/jboss/ejb3/Ejb3Registry.java 2007-07-25 13:57:50 UTC (rev 64273)
@@ -109,7 +109,7 @@
}
/**
- * Returns the container specified by the given canocical object name.
+ * Returns the container specified by the given canonical object name.
* Never returns null.
*
* @param oid the canonical object name of the container
@@ -124,6 +124,22 @@
}
/**
+ * Returns the container specified by the given canonical object name
+ * which is expected to be of the given type.
+ * Never returns null.
+ *
+ * @param oid the canonical object name of the container
+ * @param type the container type
+ * @return the container
+ * @throws IllegalStateException if the container is not registered
+ */
+ @SuppressWarnings("unchecked")
+ public static <T extends Container> T getContainer(String oid, Class<T> type)
+ {
+ return (T) getContainer(oid);
+ }
+
+ /**
* Returns an unmodifiable collection of the registered containers.
*
* @return the containers
Modified: trunk/ejb3/src/main/org/jboss/ejb3/Pool.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/Pool.java 2007-07-25 13:43:49 UTC (rev 64272)
+++ trunk/ejb3/src/main/org/jboss/ejb3/Pool.java 2007-07-25 13:57:50 UTC (rev 64273)
@@ -35,9 +35,9 @@
/**
* Creates if no object is available in pool. ejbCreate will be called if created
*/
- BeanContext get();
+ BeanContext<?> get();
- BeanContext get(Class[] initTypes, Object[] initValues);
+ BeanContext<?> get(Class[] initTypes, Object[] initValues);
/**
* Put bean back in pool
@@ -55,11 +55,11 @@
*
* @param obj
*/
- void discard(BeanContext obj);
+ void discard(BeanContext<?> obj);
public void setInjectors(Injector[] injectors);
- void initialize(Container container, Class contextClass, Class beanClass, int maxSize, long timeout);
+ void initialize(Container container, int maxSize, long timeout);
void setMaxSize(int maxSize);
Modified: trunk/ejb3/src/main/org/jboss/ejb3/StrictMaxPool.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/StrictMaxPool.java 2007-07-25 13:43:49 UTC (rev 64272)
+++ trunk/ejb3/src/main/org/jboss/ejb3/StrictMaxPool.java 2007-07-25 13:57:50 UTC (rev 64273)
@@ -52,7 +52,7 @@
/**
* The pool data structure
*/
- protected LinkedList pool = new LinkedList();
+ protected LinkedList<BeanContext<?>> pool = new LinkedList<BeanContext<?>>();
/**
* The maximum number of instances allowed in the pool
*/
@@ -70,9 +70,9 @@
/**
* super.initialize() must have been called in advance
*/
- public void initialize(Container container, Class contextClass, Class beanClass, int maxSize, long timeout)
+ public void initialize(Container container, int maxSize, long timeout)
{
- super.initialize(container, contextClass, beanClass, maxSize, timeout);
+ super.initialize(container, maxSize, timeout);
this.maxSize = maxSize;
this.strictMaxSize = new FIFOSemaphore(maxSize);
this.strictTimeout = timeout;
@@ -90,7 +90,7 @@
*
* @return Context /w instance
*/
- public BeanContext get()
+ public BeanContext<?> get()
{
boolean trace = log.isTraceEnabled();
if (trace)
@@ -114,7 +114,7 @@
{
if (!pool.isEmpty())
{
- return (BeanContext) pool.removeFirst();
+ return pool.removeFirst();
}
}
@@ -122,7 +122,7 @@
return create();
}
- public BeanContext get(Class[] initTypes, Object[] initValues)
+ public BeanContext<?> get(Class[] initTypes, Object[] initValues)
{
boolean trace = log.isTraceEnabled();
if (trace)
@@ -146,7 +146,7 @@
{
if (!pool.isEmpty())
{
- return (BeanContext) pool.removeFirst();
+ return pool.removeFirst();
}
}
Modified: trunk/ejb3/src/main/org/jboss/ejb3/ThreadlocalPool.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/ThreadlocalPool.java 2007-07-25 13:43:49 UTC (rev 64272)
+++ trunk/ejb3/src/main/org/jboss/ejb3/ThreadlocalPool.java 2007-07-25 13:57:50 UTC (rev 64273)
@@ -49,7 +49,7 @@
pool.remove();
}
- public BeanContext get()
+ public BeanContext<?> get()
{
BeanContext ctx = pool.get();
if (ctx != null)
@@ -62,7 +62,7 @@
return ctx;
}
- public BeanContext get(Class[] initTypes, Object[] initValues)
+ public BeanContext<?> get(Class[] initTypes, Object[] initValues)
{
BeanContext ctx = pool.get();
if (ctx != null)
@@ -83,4 +83,8 @@
pool.set(ctx);
}
+ @Override
+ public void setMaxSize(int maxSize)
+ {
+ }
}
Modified: trunk/ejb3/src/main/org/jboss/ejb3/cache/simple/StatefulSessionFilePersistenceManager.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/cache/simple/StatefulSessionFilePersistenceManager.java 2007-07-25 13:43:49 UTC (rev 64272)
+++ trunk/ejb3/src/main/org/jboss/ejb3/cache/simple/StatefulSessionFilePersistenceManager.java 2007-07-25 13:57:50 UTC (rev 64273)
@@ -345,7 +345,7 @@
}
catch (Exception e)
{
- log.warn("Could not read for timeout removal for file " + file.getName() + ". " + e.getMessage());
+ log.warn("Could not read for timeout removal for file " + file.getName(), e);
}
}
Modified: trunk/ejb3/src/main/org/jboss/ejb3/mdb/MDBContext.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/mdb/MDBContext.java 2007-07-25 13:43:49 UTC (rev 64272)
+++ trunk/ejb3/src/main/org/jboss/ejb3/mdb/MDBContext.java 2007-07-25 13:57:50 UTC (rev 64273)
@@ -21,6 +21,8 @@
*/
package org.jboss.ejb3.mdb;
+import javax.ejb.EJBContext;
+
import org.jboss.ejb3.BaseContext;
/**
@@ -29,10 +31,23 @@
* @author <a href="mailto:bill at jboss.org">Bill Burke</a>
* @version $Revision$
*/
-public class MDBContext extends BaseContext
+public class MDBContext extends BaseContext<MessagingContainer>
{
+ protected EJBContext ejbContext;
+
+ protected MDBContext(MessagingContainer container, Object bean)
+ {
+ super(container, bean);
+ }
+
public void remove()
{
}
+ public EJBContext getEJBContext()
+ {
+ if(ejbContext == null)
+ ejbContext = new MessageDrivenContextImpl(this);
+ return ejbContext;
+ }
}
Added: trunk/ejb3/src/main/org/jboss/ejb3/mdb/MessageDrivenContextImpl.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/mdb/MessageDrivenContextImpl.java (rev 0)
+++ trunk/ejb3/src/main/org/jboss/ejb3/mdb/MessageDrivenContextImpl.java 2007-07-25 13:57:50 UTC (rev 64273)
@@ -0,0 +1,42 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2007, Red Hat Middleware LLC, and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt 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.mdb;
+
+import javax.ejb.MessageDrivenContext;
+
+import org.jboss.ejb3.EJBContextImpl;
+
+/**
+ * Comment
+ *
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class MessageDrivenContextImpl extends EJBContextImpl<MessagingContainer, MDBContext> implements MessageDrivenContext
+{
+ private static final long serialVersionUID = 1L;
+
+ protected MessageDrivenContextImpl(MDBContext baseContext)
+ {
+ super(baseContext);
+ }
+}
Property changes on: trunk/ejb3/src/main/org/jboss/ejb3/mdb/MessageDrivenContextImpl.java
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:eol-style
+ native
Modified: trunk/ejb3/src/main/org/jboss/ejb3/mdb/MessagingContainer.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/mdb/MessagingContainer.java 2007-07-25 13:43:49 UTC (rev 64272)
+++ trunk/ejb3/src/main/org/jboss/ejb3/mdb/MessagingContainer.java 2007-07-25 13:57:50 UTC (rev 64273)
@@ -73,12 +73,16 @@
{
super(Ejb3Module.BASE_EJB3_JMX_NAME + ",name=" + ejbName, manager, cl, beanClassName, ejbName, ctxProperties, interceptorRepository, deployment);
- beanContextClass = MDBContext.class;
-
messageEndpointFactory = new JBossMessageEndpointFactory();
messageEndpointFactory.setContainer(this);
}
+ @Override
+ public BeanContext<?> createBeanContext()
+ {
+ return new MDBContext(this, construct());
+ }
+
public abstract Class getMessagingType();
public abstract Map getActivationConfigProperties();
Modified: trunk/ejb3/src/main/org/jboss/ejb3/service/ServiceBeanContext.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/service/ServiceBeanContext.java 2007-07-25 13:43:49 UTC (rev 64272)
+++ trunk/ejb3/src/main/org/jboss/ejb3/service/ServiceBeanContext.java 2007-07-25 13:57:50 UTC (rev 64273)
@@ -21,14 +21,20 @@
*/
package org.jboss.ejb3.service;
-import org.jboss.ejb3.BaseContext;
+import org.jboss.ejb3.session.SessionBeanContext;
+import org.jboss.ejb3.session.SessionContainer;
/**
* @author <a href="mailto:kabir.khan at jboss.org">Kabir Khan</a>
* @version $Revision$
*/
-public class ServiceBeanContext extends BaseContext
+public class ServiceBeanContext extends SessionBeanContext
{
+ public ServiceBeanContext(SessionContainer container, Object bean)
+ {
+ super(container, bean);
+ }
+
public void remove()
{
Modified: trunk/ejb3/src/main/org/jboss/ejb3/service/ServiceContainer.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/service/ServiceContainer.java 2007-07-25 13:43:49 UTC (rev 64272)
+++ trunk/ejb3/src/main/org/jboss/ejb3/service/ServiceContainer.java 2007-07-25 13:57:50 UTC (rev 64273)
@@ -90,7 +90,6 @@
Ejb3Deployment deployment)
{
super(cl, beanClassName, ejbName, manager, ctxProperties, interceptorRepository, deployment);
- beanContextClass = ServiceBeanContext.class;
this.mbeanServer = server;
}
@@ -117,6 +116,12 @@
}
@Override
+ public BeanContext<?> createBeanContext()
+ {
+ return new ServiceBeanContext(this, singleton);
+ }
+
+ @Override
protected ProxyFactory createProxyFactory(LocalBinding binding)
{
return new ServiceLocalProxyFactory(this, binding);
@@ -423,26 +428,18 @@
{
if (beanContext == null)
{
- try
- {
- beanContext = (BeanContext) beanContextClass.newInstance();
- beanContext.setContainer(this);
- beanContext.initialiseInterceptorInstances();
- beanContext.setInstance(singleton);
- }
- catch (InstantiationException e)
- {
- throw new RuntimeException(e); //To change body of catch statement use Options | File Templates.
- }
- catch (IllegalAccessException e)
- {
- throw new RuntimeException(e); //To change body of catch statement use Options | File Templates.
- }
+ beanContext = createBeanContext();
+ beanContext.initialiseInterceptorInstances();
}
}
}
}
+ public BeanContext<?> peekContext()
+ {
+ return beanContext;
+ }
+
@Override
protected EJBContainerInvocation populateInvocation(EJBContainerInvocation invocation)
{
Added: trunk/ejb3/src/main/org/jboss/ejb3/session/SessionBeanContext.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/session/SessionBeanContext.java (rev 0)
+++ trunk/ejb3/src/main/org/jboss/ejb3/session/SessionBeanContext.java 2007-07-25 13:57:50 UTC (rev 64273)
@@ -0,0 +1,62 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2007, Red Hat Middleware LLC, and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt 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.session;
+
+import javax.ejb.EJBContext;
+
+import org.jboss.ejb3.BaseContext;
+
+/**
+ * An instance of an enterprise bean link to its container.
+ *
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public abstract class SessionBeanContext extends BaseContext<SessionContainer>
+{
+ protected EJBContext ejbContext;
+
+ /**
+ * Must not break getInstance post condition!
+ * @param container
+ */
+ protected SessionBeanContext(SessionContainer container)
+ {
+ super(container);
+ }
+
+ protected SessionBeanContext(SessionContainer container, Object bean)
+ {
+ super(container, bean);
+ }
+
+ public EJBContext getEJBContext()
+ {
+ if (ejbContext == null)
+ {
+ SessionContextImpl bsc = new SessionContextImpl(this);
+ ejbContext = bsc;
+ }
+ return ejbContext;
+ }
+
+}
Property changes on: trunk/ejb3/src/main/org/jboss/ejb3/session/SessionBeanContext.java
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:eol-style
+ native
Added: trunk/ejb3/src/main/org/jboss/ejb3/session/SessionContextImpl.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/session/SessionContextImpl.java (rev 0)
+++ trunk/ejb3/src/main/org/jboss/ejb3/session/SessionContextImpl.java 2007-07-25 13:57:50 UTC (rev 64273)
@@ -0,0 +1,142 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, 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.session;
+
+import java.io.Externalizable;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.security.Identity;
+import java.security.Principal;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Properties;
+
+import javax.ejb.EJBException;
+import javax.ejb.EJBHome;
+import javax.ejb.EJBLocalHome;
+import javax.ejb.EJBLocalObject;
+import javax.ejb.EJBObject;
+import javax.ejb.MessageDrivenContext;
+import javax.ejb.SessionContext;
+import javax.ejb.TimerService;
+import javax.ejb.TransactionManagementType;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import javax.transaction.Status;
+import javax.transaction.SystemException;
+import javax.transaction.TransactionManager;
+import javax.transaction.UserTransaction;
+import javax.xml.rpc.handler.MessageContext;
+
+import org.jboss.annotation.security.RunAsPrincipal;
+import org.jboss.annotation.security.SecurityDomain;
+import org.jboss.aop.Advisor;
+import org.jboss.ejb3.BaseContext;
+import org.jboss.ejb3.Container;
+import org.jboss.ejb3.EJBContainer;
+import org.jboss.ejb3.EJBContextImpl;
+import org.jboss.ejb3.Ejb3Registry;
+import org.jboss.ejb3.SecurityActions;
+import org.jboss.ejb3.security.SecurityDomainManager;
+import org.jboss.ejb3.stateless.StatelessBeanContext;
+import org.jboss.ejb3.tx.TxUtil;
+import org.jboss.ejb3.tx.UserTransactionImpl;
+import org.jboss.logging.Logger;
+import org.jboss.security.RealmMapping;
+import org.jboss.security.RunAsIdentity;
+import org.jboss.security.SecurityAssociation;
+import org.jboss.security.SimplePrincipal;
+
+import org.jboss.metamodel.descriptor.SecurityRoleRef;
+
+/**
+ * Comment
+ *
+ * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
+ * @version $Revision$
+ */
+public class SessionContextImpl extends EJBContextImpl<SessionContainer, SessionBeanContext> implements SessionContext
+{
+ @SuppressWarnings("unused")
+ private static final Logger log = Logger.getLogger(SessionContextImpl.class);
+
+ public SessionContextImpl(SessionBeanContext beanContext)
+ {
+ super(beanContext);
+ }
+
+ public <T> T getBusinessObject(Class<T> businessInterface) throws IllegalStateException
+ {
+ if(businessInterface == null)
+ throw new IllegalStateException("businessInterface is null");
+
+ return container.getBusinessObject(beanContext, businessInterface);
+ }
+
+ public EJBLocalObject getEJBLocalObject() throws IllegalStateException
+ {
+ try
+ {
+ Object id = beanContext.getId();
+ EJBLocalObject proxy = (EJBLocalObject) container.createLocalProxy(id);
+ return proxy;
+ }
+ catch (Exception e)
+ {
+ throw new IllegalStateException(e);
+ }
+ }
+
+ public EJBObject getEJBObject() throws IllegalStateException
+ {
+ try
+ {
+ Object id = beanContext.getId();
+ EJBObject proxy = (EJBObject) container.createRemoteProxy(id);
+ return proxy;
+ }
+ catch (Exception e)
+ {
+ throw new IllegalStateException(e);
+ }
+ }
+
+ public Class getInvokedBusinessInterface() throws IllegalStateException
+ {
+ return container.getInvokedBusinessInterface();
+ }
+
+ public MessageContext getMessageContext() throws IllegalStateException
+ {
+ // disallowed for stateful session beans (EJB3 FR 4.4.1 p 81)
+ if(beanContext instanceof StatelessBeanContext)
+ {
+ MessageContext ctx = ((StatelessBeanContext) beanContext).getMessageContextJAXRPC();
+ if(ctx == null)
+ throw new IllegalStateException("No message context found");
+ return ctx;
+ }
+ throw new UnsupportedOperationException("Only stateless beans can have a message context");
+ }
+}
Property changes on: trunk/ejb3/src/main/org/jboss/ejb3/session/SessionContextImpl.java
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:eol-style
+ native
Modified: trunk/ejb3/src/main/org/jboss/ejb3/stateful/NestedStatefulBeanContext.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/stateful/NestedStatefulBeanContext.java 2007-07-25 13:43:49 UTC (rev 64272)
+++ trunk/ejb3/src/main/org/jboss/ejb3/stateful/NestedStatefulBeanContext.java 2007-07-25 13:57:50 UTC (rev 64273)
@@ -21,6 +21,7 @@
*/
package org.jboss.ejb3.stateful;
+import java.io.Externalizable;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
@@ -29,6 +30,7 @@
import javax.persistence.EntityManager;
import org.jboss.aop.metadata.SimpleMetaData;
+import org.jboss.ejb3.session.SessionContainer;
/**
* Overrides superclass to not use MarshalledValue in externalization,
@@ -40,11 +42,16 @@
* @author <a href="mailto:bill at jboss.org">Bill Burke</a>
* @version $Revision$
*/
-public class NestedStatefulBeanContext extends StatefulBeanContext
+public class NestedStatefulBeanContext extends StatefulBeanContext implements Externalizable
{
/** The serialVersionUID */
private static final long serialVersionUID = 7835719320529968045L;
+ public NestedStatefulBeanContext(SessionContainer container, Object bean)
+ {
+ super(container, bean);
+ }
+
public void writeExternal(ObjectOutput out) throws IOException
{
out.writeUTF(getContainer().getObjectName().getCanonicalName());
Modified: trunk/ejb3/src/main/org/jboss/ejb3/stateful/ProxiedStatefulBeanContext.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/stateful/ProxiedStatefulBeanContext.java 2007-07-25 13:43:49 UTC (rev 64272)
+++ trunk/ejb3/src/main/org/jboss/ejb3/stateful/ProxiedStatefulBeanContext.java 2007-07-25 13:57:50 UTC (rev 64273)
@@ -33,6 +33,7 @@
import org.jboss.aop.metadata.SimpleMetaData;
import org.jboss.ejb3.Container;
import org.jboss.ejb3.interceptor.InterceptorInfo;
+import org.jboss.ejb3.session.SessionContainer;
/**
* Proxy to a NestedStatefulBeanContext that can be independently passivated,
@@ -43,8 +44,7 @@
*
* @version $Revision$
*/
-public class ProxiedStatefulBeanContext extends StatefulBeanContext implements
- Externalizable
+public class ProxiedStatefulBeanContext extends StatefulBeanContext implements Externalizable
{
/** The serialVersionUID */
private static final long serialVersionUID = -5156610459343035743L;
@@ -59,22 +59,19 @@
public ProxiedStatefulBeanContext(StatefulBeanContext delegate)
{
+ super(delegate.getContainer(), delegate.getInstance());
+
this.delegate = delegate;
oid = delegate.getId();
- containerId = delegate.getContainer().getObjectName().getCanonicalName();
+ containerId = container.getObjectName().getCanonicalName();
parentRef = new StatefulBeanContextReference(delegate.getContainedIn());
}
- public ProxiedStatefulBeanContext()
- {
- }
-
protected StatefulBeanContext getDelegate()
{
if (delegate == null)
{
- for (StatefulBeanContext ctx : parentRef.getBeanContext()
- .getContains())
+ for (StatefulBeanContext ctx : parentRef.getBeanContext().getContains())
{
Object matchingOid = ctx.getId();
if (oid.equals(matchingOid)
@@ -109,6 +106,8 @@
oid = in.readObject();
containerId = in.readUTF();
parentRef = (StatefulBeanContextReference) in.readObject();
+
+ assert parentRef != null : "parentRef is null";
}
@Override
@@ -248,12 +247,12 @@
return getDelegate().getId();
}
- @Override
- public void setId(Object id)
- {
- this.oid = id;
- getDelegate().setId(id);
- }
+// @Override
+// public void setId(Object id)
+// {
+// this.oid = id;
+// getDelegate().setId(id);
+// }
@Override
public boolean isTxSynchronized()
@@ -273,15 +272,15 @@
getDelegate().remove();
}
+// @Override
+// public void setContainer(Container container)
+// {
+// getDelegate().setContainer(container);
+// }
+//
@Override
- public void setContainer(Container container)
+ public SessionContainer getContainer()
{
- getDelegate().setContainer(container);
- }
-
- @Override
- public Container getContainer()
- {
return getDelegate().getContainer();
}
@@ -310,12 +309,6 @@
}
@Override
- public void setInstance(Object instance)
- {
- getDelegate().setInstance(instance);
- }
-
- @Override
public void initialiseInterceptorInstances()
{
getDelegate().initialiseInterceptorInstances();
Modified: trunk/ejb3/src/main/org/jboss/ejb3/stateful/StatefulBeanContext.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/stateful/StatefulBeanContext.java 2007-07-25 13:43:49 UTC (rev 64272)
+++ trunk/ejb3/src/main/org/jboss/ejb3/stateful/StatefulBeanContext.java 2007-07-25 13:57:50 UTC (rev 64273)
@@ -21,10 +21,9 @@
*/
package org.jboss.ejb3.stateful;
-import java.io.Externalizable;
import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
+import java.io.ObjectStreamException;
+import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
@@ -32,20 +31,22 @@
import java.util.Map;
import java.util.concurrent.locks.ReentrantLock;
+import javax.ejb.EJBContext;
import javax.persistence.EntityManager;
import javax.transaction.Synchronization;
import javax.transaction.Transaction;
import org.jboss.aop.metadata.SimpleMetaData;
-import org.jboss.ejb3.BaseContext;
-import org.jboss.ejb3.Container;
import org.jboss.ejb3.Ejb3Registry;
import org.jboss.ejb3.ThreadLocalStack;
import org.jboss.ejb3.cache.StatefulCache;
import org.jboss.ejb3.interceptor.InterceptorInfo;
+import org.jboss.ejb3.session.SessionBeanContext;
+import org.jboss.ejb3.session.SessionContainer;
import org.jboss.ejb3.tx.TxUtil;
import org.jboss.serial.io.MarshalledObject;
import org.jboss.tm.TxUtils;
+import org.jboss.util.id.GUID;
/**
* BeanContext for a stateful session bean.
@@ -55,11 +56,36 @@
*
* @version $Revision$
*/
-public class StatefulBeanContext extends BaseContext implements Externalizable
+public class StatefulBeanContext extends SessionBeanContext implements Serializable
{
/** The serialVersionUID */
private static final long serialVersionUID = -102470788178912606L;
+ private static class Serialized implements Serializable
+ {
+ private static final long serialVersionUID = 1L;
+
+ private String containerName;
+ private Object id;
+ private SimpleMetaData metadata;
+ private long lastUsed;
+ private MarshalledObject beanMO;
+ private boolean removed;
+ private boolean replicationIsPassivation;
+
+ private Object readResolve() throws ObjectStreamException
+ {
+ StatefulContainer container = Ejb3Registry.getContainer(containerName, StatefulContainer.class);
+ StatefulBeanContext context = new StatefulBeanContext(container, beanMO);
+ context.id = this.id;
+ context.metadata = this.metadata;
+ context.lastUsed = this.lastUsed;
+ context.removed = this.removed;
+ context.replicationIsPassivation = this.replicationIsPassivation;
+ return context;
+ }
+ }
+
protected Object id;
protected boolean txSynchronized = false;
@@ -92,10 +118,35 @@
protected transient boolean passivated = false;
- public StatefulBeanContext()
+ /**
+ * An incoming context from serialization.
+ *
+ * @param container
+ * @param beanMO
+ */
+ protected StatefulBeanContext(SessionContainer container, MarshalledObject beanMO)
{
-
+ super(container);
+
+ assert beanMO != null : "beanMO is null";
+
+ this.containerName = container.getObjectName().getCanonicalName();
+ this.beanMO = beanMO;
}
+
+ /**
+ * A brand new stateful session bean.
+ *
+ * @param container
+ * @param bean
+ */
+ protected StatefulBeanContext(SessionContainer container, Object bean)
+ {
+ super(container, bean);
+
+ this.containerName = container.getObjectName().getCanonicalName();
+ this.id = new GUID();
+ }
public List<StatefulBeanContext> getContains()
{
@@ -126,6 +177,14 @@
return copy;
}
+ @Override
+ public EJBContext getEJBContext()
+ {
+ if(ejbContext == null)
+ ejbContext = new StatefulSessionContextImpl(this);
+ return ejbContext;
+ }
+
public EntityManager getExtendedPersistenceContext(String id)
{
EntityManager found = null;
@@ -304,11 +363,9 @@
// independent marshalling. Instead, we return a proxy to it that will
// be stored in its container's cache
containedIn = propagatedContainedIn.get();
- NestedStatefulBeanContext nested = new NestedStatefulBeanContext();
+ NestedStatefulBeanContext nested = new NestedStatefulBeanContext(getContainer(), bean);
nested.id = id;
- nested.container = getContainer();
nested.containerName = containerName;
- nested.bean = bean;
nested.replicationIsPassivation = replicationIsPassivation;
containedIn.addContains(nested);
thisPtr = new ProxiedStatefulBeanContext(nested);
@@ -551,11 +608,6 @@
return id;
}
- public void setId(Object id)
- {
- this.id = id;
- }
-
public boolean isTxSynchronized()
{
return txSynchronized;
@@ -715,17 +767,12 @@
}
}
- public void setContainer(Container container)
+ @Override
+ public SessionContainer getContainer()
{
- super.setContainer(container);
- containerName = container.getObjectName().getCanonicalName();
- }
-
- public Container getContainer()
- {
if (container == null)
{
- container = Ejb3Registry.getContainer(containerName);
+ container = Ejb3Registry.getContainer(containerName, SessionContainer.class);
}
return container;
}
@@ -737,6 +784,7 @@
{
extractBeanAndInterceptors();
}
+ assert bean != null : "bean is null";
return bean;
}
@@ -812,14 +860,10 @@
}
}
- public void writeExternal(ObjectOutput out) throws IOException
+ private Object writeReplace() throws ObjectStreamException
{
- out.writeUTF(containerName);
- out.writeObject(id);
- out.writeObject(metadata);
- out.writeLong(lastUsed);
-
- if (beanMO == null)
+ Serialized state = new Serialized();
+ if (this.beanMO == null)
{
Object[] beanAndInterceptors = new Object[4];
beanAndInterceptors[0] = bean;
@@ -837,8 +881,15 @@
// two different versions of the constituent state that
// can fall out of sync. So now we just write a local variable.
- MarshalledObject mo = new MarshalledObject(beanAndInterceptors);
- out.writeObject(mo);
+ try
+ {
+ MarshalledObject mo = new MarshalledObject(beanAndInterceptors);
+ state.beanMO = mo;
+ }
+ catch(IOException e)
+ {
+ throw new RuntimeException("Marshalling of bean " + bean + " failed", e);
+ }
}
else
{
@@ -846,30 +897,75 @@
// extractBeanAndInterceptors hasn't been called in between.
// This can happen if a passivated session is involved in a
// JBoss Cache state transfer to a newly deployed node.
- out.writeObject(beanMO);
+ state.beanMO = this.beanMO;
}
-
-
- out.writeBoolean(removed);
- out.writeBoolean(replicationIsPassivation);
+ state.containerName = this.containerName;
+ state.id = this.id;
+ state.lastUsed = this.lastUsed;
+ state.metadata = this.metadata;
+ state.removed = this.removed;
+ state.replicationIsPassivation = this.replicationIsPassivation;
+ return state;
}
+
+// public void writeExternal(ObjectOutput out) throws IOException
+// {
+// out.writeUTF(containerName);
+// out.writeObject(id);
+// out.writeObject(metadata);
+// out.writeLong(lastUsed);
+//
+// if (beanMO == null)
+// {
+// Object[] beanAndInterceptors = new Object[4];
+// beanAndInterceptors[0] = bean;
+// beanAndInterceptors[1] = persistenceContexts;
+// if (interceptorInstances != null && interceptorInstances.size() > 0)
+// {
+// ArrayList list = new ArrayList();
+// list.addAll(interceptorInstances.values());
+// beanAndInterceptors[2] = list;
+// }
+// beanAndInterceptors[3] = contains;
+//
+// // BES 2007/02/12 Previously we were trying to hold a ref to
+// // beanMO after we created it, but that exposes the risk of
+// // two different versions of the constituent state that
+// // can fall out of sync. So now we just write a local variable.
+//
+// MarshalledObject mo = new MarshalledObject(beanAndInterceptors);
+// out.writeObject(mo);
+// }
+// else
+// {
+// // We've been deserialized and are now being re-serialized, but
+// // extractBeanAndInterceptors hasn't been called in between.
+// // This can happen if a passivated session is involved in a
+// // JBoss Cache state transfer to a newly deployed node.
+// out.writeObject(beanMO);
+// }
+//
+//
+// out.writeBoolean(removed);
+// out.writeBoolean(replicationIsPassivation);
+// }
+//
+// public void readExternal(ObjectInput in) throws IOException,
+// ClassNotFoundException
+// {
+// containerName = in.readUTF();
+// id = in.readObject();
+// metadata = (SimpleMetaData) in.readObject();
+// lastUsed = in.readLong();
+//
+// beanMO = (MarshalledObject) in.readObject();
+// removed = in.readBoolean();
+// replicationIsPassivation = in.readBoolean();
+//
+// // If we've just been deserialized, we are passivated
+// passivated = true;
+// }
- public void readExternal(ObjectInput in) throws IOException,
- ClassNotFoundException
- {
- containerName = in.readUTF();
- id = in.readObject();
- metadata = (SimpleMetaData) in.readObject();
- lastUsed = in.readLong();
-
- beanMO = (MarshalledObject) in.readObject();
- removed = in.readBoolean();
- replicationIsPassivation = in.readBoolean();
-
- // If we've just been deserialized, we are passivated
- passivated = true;
- }
-
public Object getInvokedMethodKey()
{
return this.getId();
Modified: trunk/ejb3/src/main/org/jboss/ejb3/stateful/StatefulBeanContextReference.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/stateful/StatefulBeanContextReference.java 2007-07-25 13:43:49 UTC (rev 64272)
+++ trunk/ejb3/src/main/org/jboss/ejb3/stateful/StatefulBeanContextReference.java 2007-07-25 13:57:50 UTC (rev 64273)
@@ -25,6 +25,8 @@
import java.io.ObjectInput;
import java.io.IOException;
import java.io.ObjectOutput;
+import java.io.Serializable;
+
import org.jboss.ejb3.Ejb3Registry;
/**
@@ -33,7 +35,7 @@
* @author <a href="mailto:bill at jboss.org">Bill Burke</a>
* @version $Revision$
*/
-public class StatefulBeanContextReference implements Externalizable
+public class StatefulBeanContextReference implements Serializable
{
/** The serialVersionUID */
private static final long serialVersionUID = 2644760020735482423L;
@@ -42,31 +44,37 @@
private Object oid;
private String containerId;
-
-
- public StatefulBeanContextReference()
+ private static class Serialized implements Serializable
{
+ private Object oid;
+ private String containerId;
+
+ private Serialized(StatefulBeanContextReference ref)
+ {
+ }
}
-
+
public StatefulBeanContextReference(StatefulBeanContext beanContext)
{
+ assert beanContext != null : "beanContext is null";
+
this.beanContext = beanContext;
oid = beanContext.getId();
containerId = beanContext.getContainer().getObjectName().getCanonicalName();
}
- public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
- {
- containerId = in.readUTF();
- oid = in.readObject();
- }
+// public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
+// {
+// containerId = in.readUTF();
+// oid = in.readObject();
+// }
+//
+// public void writeExternal(ObjectOutput out) throws IOException
+// {
+// out.writeUTF(containerId);
+// out.writeObject(oid);
+// }
- public void writeExternal(ObjectOutput out) throws IOException
- {
- out.writeUTF(containerId);
- out.writeObject(oid);
- }
-
public StatefulBeanContext getBeanContext()
{
if (beanContext == null)
@@ -75,7 +83,14 @@
// We are willing to accept a context that has been marked as removed
// as it can still hold nested children
beanContext = container.getCache().get(oid, false);
+
+ assert beanContext != null : "beanContext no longer in cache";
}
return beanContext;
}
+
+ private Object writeReplace()
+ {
+ return new Serialized(this);
+ }
}
Modified: trunk/ejb3/src/main/org/jboss/ejb3/stateful/StatefulContainer.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/stateful/StatefulContainer.java 2007-07-25 13:43:49 UTC (rev 64272)
+++ trunk/ejb3/src/main/org/jboss/ejb3/stateful/StatefulContainer.java 2007-07-25 13:57:50 UTC (rev 64273)
@@ -82,10 +82,15 @@
Ejb3Deployment deployment)
{
super(cl, beanClassName, ejbName, manager, ctxProperties, interceptorRepository, deployment);
- beanContextClass = StatefulBeanContext.class;
}
@Override
+ public BeanContext<?> createBeanContext()
+ {
+ return new StatefulBeanContext(this, construct());
+ }
+
+ @Override
protected ProxyFactory createProxyFactory(LocalBinding binding)
{
return new StatefulLocalProxyFactory(this, binding);
Modified: trunk/ejb3/src/main/org/jboss/ejb3/stateful/StatefulInstanceInterceptor.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/stateful/StatefulInstanceInterceptor.java 2007-07-25 13:43:49 UTC (rev 64272)
+++ trunk/ejb3/src/main/org/jboss/ejb3/stateful/StatefulInstanceInterceptor.java 2007-07-25 13:57:50 UTC (rev 64273)
@@ -77,6 +77,7 @@
ejb.setTargetObject(target.getInstance());
ejb.setBeanContext(target);
StatefulBeanContext.currentBean.push(target);
+ container.pushContext(target);
try
{
if (target.isDiscarded()) throw new EJBException("SFSB was discarded by another thread");
@@ -95,6 +96,7 @@
}
finally
{
+ container.popContext();
StatefulBeanContext.currentBean.pop();
synchronized (target)
{
Added: trunk/ejb3/src/main/org/jboss/ejb3/stateful/StatefulSessionContextImpl.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/stateful/StatefulSessionContextImpl.java (rev 0)
+++ trunk/ejb3/src/main/org/jboss/ejb3/stateful/StatefulSessionContextImpl.java 2007-07-25 13:57:50 UTC (rev 64273)
@@ -0,0 +1,71 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2007, Red Hat Middleware LLC, and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt 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.stateful;
+
+import java.io.ObjectStreamException;
+import java.io.Serializable;
+
+import org.jboss.ejb3.Ejb3Registry;
+import org.jboss.ejb3.session.SessionBeanContext;
+import org.jboss.ejb3.session.SessionContextImpl;
+
+/**
+ * A session context that is serializable.
+ *
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class StatefulSessionContextImpl extends SessionContextImpl implements Serializable
+{
+ private static final long serialVersionUID = 1L;
+
+ private static class Serialized implements Serializable
+ {
+ private static final long serialVersionUID = 1L;
+
+// private SessionBeanContext beanContext;
+
+ private String oid;
+ private Object id;
+
+ private Object readResolve() throws ObjectStreamException
+ {
+ StatefulContainer container = Ejb3Registry.getContainer(oid, StatefulContainer.class);
+ StatefulBeanContext beanContext = container.getCache().get(id, false);
+ return new StatefulSessionContextImpl(beanContext);
+ }
+ }
+
+ public StatefulSessionContextImpl(SessionBeanContext beanContext)
+ {
+ super(beanContext);
+ }
+
+ private Object writeReplace() throws ObjectStreamException
+ {
+ Serialized s = new Serialized();
+ s.oid = container.getObjectName().getCanonicalName();
+ s.id = beanContext.getId();
+// s.beanContext = beanContext;
+ return s;
+ }
+}
Property changes on: trunk/ejb3/src/main/org/jboss/ejb3/stateful/StatefulSessionContextImpl.java
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:eol-style
+ native
Modified: trunk/ejb3/src/main/org/jboss/ejb3/stateless/StatelessBeanContext.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/stateless/StatelessBeanContext.java 2007-07-25 13:43:49 UTC (rev 64272)
+++ trunk/ejb3/src/main/org/jboss/ejb3/stateless/StatelessBeanContext.java 2007-07-25 13:57:50 UTC (rev 64273)
@@ -24,6 +24,8 @@
import javax.xml.ws.WebServiceContext;
import org.jboss.ejb3.BaseContext;
+import org.jboss.ejb3.session.SessionBeanContext;
+import org.jboss.ejb3.session.SessionContainer;
import org.jboss.injection.lang.reflect.BeanProperty;
@@ -33,11 +35,16 @@
* @author <a href="mailto:bill at jboss.org">Bill Burke</a>
* @version $Revision$
*/
-public class StatelessBeanContext extends BaseContext
+public class StatelessBeanContext extends SessionBeanContext
{
private javax.xml.rpc.handler.MessageContext jaxrpcMessageContext;
private BeanProperty webServiceContextProperty;
+ protected StatelessBeanContext(SessionContainer container, Object bean)
+ {
+ super(container, bean);
+ }
+
public javax.xml.rpc.handler.MessageContext getMessageContextJAXRPC()
{
return jaxrpcMessageContext;
Modified: trunk/ejb3/src/main/org/jboss/ejb3/stateless/StatelessContainer.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/stateless/StatelessContainer.java 2007-07-25 13:43:49 UTC (rev 64272)
+++ trunk/ejb3/src/main/org/jboss/ejb3/stateless/StatelessContainer.java 2007-07-25 13:57:50 UTC (rev 64273)
@@ -78,10 +78,15 @@
Ejb3Deployment deployment)
{
super(cl, beanClassName, ejbName, manager, ctxProperties, interceptorRepository, deployment);
- beanContextClass = StatelessBeanContext.class;
}
@Override
+ public BeanContext<?> createBeanContext()
+ {
+ return new StatelessBeanContext(this, construct());
+ }
+
+ @Override
protected ProxyFactory createProxyFactory(LocalBinding binding)
{
return new StatelessLocalProxyFactory(this, binding);
Modified: trunk/ejb3/src/main/org/jboss/ejb3/stateless/StatelessInstanceInterceptor.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/stateless/StatelessInstanceInterceptor.java 2007-07-25 13:43:49 UTC (rev 64272)
+++ trunk/ejb3/src/main/org/jboss/ejb3/stateless/StatelessInstanceInterceptor.java 2007-07-25 13:57:50 UTC (rev 64273)
@@ -51,9 +51,10 @@
EJBContainerInvocation ejb = (EJBContainerInvocation) invocation;
EJBContainer container = (EJBContainer)ejb.getAdvisor();
Pool pool = container.getPool();
- BeanContext ctx = pool.get();
+ BeanContext<?> ctx = pool.get();
ejb.setTargetObject(ctx.getInstance());
ejb.setBeanContext(ctx);
+ container.pushContext(ctx);
boolean discard = false;
@@ -68,7 +69,8 @@
throw ex;
}
finally
- {
+ {
+ container.popContext();
ejb.setTargetObject(null);
ejb.setBeanContext(null);
if (discard) pool.discard(ctx);
Added: trunk/ejb3/src/test/org/jboss/ejb3/test/interceptormetadata/MockDependencyPolicy.java
===================================================================
--- trunk/ejb3/src/test/org/jboss/ejb3/test/interceptormetadata/MockDependencyPolicy.java (rev 0)
+++ trunk/ejb3/src/test/org/jboss/ejb3/test/interceptormetadata/MockDependencyPolicy.java 2007-07-25 13:57:50 UTC (rev 64273)
@@ -0,0 +1,51 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2007, Red Hat Middleware LLC, and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt 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.test.interceptormetadata;
+
+import org.jboss.ejb3.DependencyPolicy;
+
+/**
+ * Comment
+ *
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class MockDependencyPolicy implements DependencyPolicy
+{
+
+ /* (non-Javadoc)
+ * @see org.jboss.ejb3.DependencyPolicy#addDatasource(java.lang.String)
+ */
+ public void addDatasource(String jndiName)
+ {
+ throw new RuntimeException("NYI");
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.ejb3.DependencyPolicy#addDependency(java.lang.String)
+ */
+ public void addDependency(String dependency)
+ {
+ throw new RuntimeException("NYI");
+ }
+
+}
Property changes on: trunk/ejb3/src/test/org/jboss/ejb3/test/interceptormetadata/MockDependencyPolicy.java
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:eol-style
+ native
Modified: trunk/ejb3/src/test/org/jboss/ejb3/test/stateful/nested/base/BeanMonitorBean.java
===================================================================
--- trunk/ejb3/src/test/org/jboss/ejb3/test/stateful/nested/base/BeanMonitorBean.java 2007-07-25 13:43:49 UTC (rev 64272)
+++ trunk/ejb3/src/test/org/jboss/ejb3/test/stateful/nested/base/BeanMonitorBean.java 2007-07-25 13:57:50 UTC (rev 64273)
@@ -73,7 +73,7 @@
}
catch (Exception e)
{
- log.debug("getDeepNestedId() " + e.getLocalizedMessage());
+ log.warn("getDeepNestedId() " + e.getLocalizedMessage(), e);
return "ERROR";
}
}
@@ -86,7 +86,7 @@
}
catch (Exception e)
{
- log.debug("getLocalDeepNestedId() " + e.getLocalizedMessage());
+ log.warn("getLocalDeepNestedId() " + e.getLocalizedMessage(), e);
return "ERROR";
}
}
@@ -99,7 +99,7 @@
}
catch (Exception e)
{
- log.debug("getParentPassivations() " + e.getLocalizedMessage());
+ log.warn("getParentPassivations() " + e.getLocalizedMessage(), e);
return -1;
}
}
@@ -112,7 +112,7 @@
}
catch (Exception e)
{
- log.debug("getNestedPassivations() " + e.getLocalizedMessage());
+ log.warn("getNestedPassivations() " + e.getLocalizedMessage(), e);
return -1;
}
}
@@ -125,7 +125,7 @@
}
catch (Exception e)
{
- log.debug("getLocalNestedPassivations() " + e.getLocalizedMessage());
+ log.warn("getLocalNestedPassivations() " + e.getLocalizedMessage(), e);
return -1;
}
}
@@ -138,7 +138,7 @@
}
catch (Exception e)
{
- log.debug("getDeepNestedPassivations() " + e.getLocalizedMessage());
+ log.warn("getDeepNestedPassivations() " + e.getLocalizedMessage(), e);
return -1;
}
}
@@ -151,7 +151,7 @@
}
catch (Exception e)
{
- log.debug("getLocalDeepNestedPassivations() " + e.getLocalizedMessage());
+ log.warn("getLocalDeepNestedPassivations() " + e.getLocalizedMessage(), e);
return -1;
}
}
@@ -164,7 +164,7 @@
}
catch (Exception e)
{
- log.debug("getParentActivations() " + e.getLocalizedMessage());
+ log.warn("getParentActivations() " + e.getLocalizedMessage(), e);
return -1;
}
}
@@ -190,7 +190,7 @@
}
catch (Exception e)
{
- log.debug("getLocalNestedActivations() " + e.getLocalizedMessage());
+ log.warn("getLocalNestedActivations() " + e.getLocalizedMessage(), e);
return -1;
}
}
@@ -203,7 +203,7 @@
}
catch (Exception e)
{
- log.debug("getDeepNestedActivations() " + e.getLocalizedMessage());
+ log.warn("getDeepNestedActivations() " + e.getLocalizedMessage(), e);
return -1;
}
}
@@ -230,7 +230,7 @@
}
catch (Exception e)
{
- log.debug("removeParent() " + e.getLocalizedMessage());
+ log.warn("removeParent() " + e.getLocalizedMessage(), e);
return false;
}
}
@@ -258,7 +258,7 @@
}
catch (Exception e)
{
- log.debug("removeLocalNested() " + e.getLocalizedMessage());
+ log.warn("removeLocalNested() " + e.getLocalizedMessage(), e);
return false;
}
}
@@ -286,7 +286,7 @@
}
catch (Exception e)
{
- log.debug("removeLocalDeepNested() " + e.getLocalizedMessage());
+ log.warn("removeLocalDeepNested() " + e.getLocalizedMessage(), e);
return false;
}
}
Modified: trunk/ejb3/src/test/org/jboss/ejb3/test/strictpool/BogusPool.java
===================================================================
--- trunk/ejb3/src/test/org/jboss/ejb3/test/strictpool/BogusPool.java 2007-07-25 13:43:49 UTC (rev 64272)
+++ trunk/ejb3/src/test/org/jboss/ejb3/test/strictpool/BogusPool.java 2007-07-25 13:57:50 UTC (rev 64273)
@@ -53,6 +53,12 @@
throw new RuntimeException("Bogus");
}
+ @Override
+ public void setMaxSize(int maxSize)
+ {
+ throw new RuntimeException("Bogus");
+ }
+
public void destroy()
{
throw new RuntimeException("Bogus");
More information about the jboss-cvs-commits
mailing list