[jboss-cvs] JBossAS SVN: r65774 - in trunk/ejb3/src: main/org/jboss/ejb3/stateful and 3 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue Oct 2 17:51:29 EDT 2007
Author: bdecoste
Date: 2007-10-02 17:51:29 -0400 (Tue, 02 Oct 2007)
New Revision: 65774
Added:
trunk/ejb3/src/test/org/jboss/ejb3/test/stateful/TreeCacheStatefulBean.java
Modified:
trunk/ejb3/src/main/org/jboss/ejb3/cache/tree/StatefulTreeCache.java
trunk/ejb3/src/main/org/jboss/ejb3/stateful/StatefulContainer.java
trunk/ejb3/src/main/org/jboss/injection/AbstractPropertyInjector.java
trunk/ejb3/src/test/org/jboss/ejb3/test/stateful/unit/MetricsUnitTestCase.java
Log:
[EJBTHREE-1033] [EJBTHREE-883] merged from Branch_4_2
Modified: trunk/ejb3/src/main/org/jboss/ejb3/cache/tree/StatefulTreeCache.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/cache/tree/StatefulTreeCache.java 2007-10-02 20:03:23 UTC (rev 65773)
+++ trunk/ejb3/src/main/org/jboss/ejb3/cache/tree/StatefulTreeCache.java 2007-10-02 21:51:29 UTC (rev 65774)
@@ -26,6 +26,8 @@
import java.util.Iterator;
import java.util.Map;
+import java.util.Set;
+
import javax.ejb.EJBException;
import javax.ejb.NoSuchEJBException;
import javax.management.MBeanServer;
@@ -38,6 +40,7 @@
import org.jboss.cache.CacheSPI;
import org.jboss.cache.Fqn;
import org.jboss.cache.InvocationContext;
+import org.jboss.cache.Node;
import org.jboss.cache.Region;
import org.jboss.cache.config.EvictionPolicyConfig;
import org.jboss.cache.config.Option;
@@ -258,6 +261,7 @@
putInCache(ctx);
}
+ ++removeCount;
beans.remove(key);
}
}
@@ -405,16 +409,18 @@
public int getCacheSize()
{
- return -1;
- /* FIXME: make this work
int count = 0;
try
{
Set children = null;
for (int i = 0; i < hashBuckets.length; i++)
{
- children = cache.getChildrenNames(new Fqn(cacheNode, hashBuckets[i]));
- count += (children == null ? 0 : children.size());
+ Node node = cache.getRoot().getChild(new Fqn(cacheNode, hashBuckets[i]));
+ if (node != null)
+ {
+ children = node.getChildrenNames();
+ count += (children == null ? 0 : children.size());
+ }
}
count = count - passivatedCount;
}
@@ -424,7 +430,6 @@
count = -1;
}
return count;
- */
}
public int getTotalSize()
Modified: trunk/ejb3/src/main/org/jboss/ejb3/stateful/StatefulContainer.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/stateful/StatefulContainer.java 2007-10-02 20:03:23 UTC (rev 65773)
+++ trunk/ejb3/src/main/org/jboss/ejb3/stateful/StatefulContainer.java 2007-10-02 21:51:29 UTC (rev 65774)
@@ -21,8 +21,10 @@
*/
package org.jboss.ejb3.stateful;
+import java.lang.reflect.AccessibleObject;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
import java.util.Hashtable;
import java.util.Map;
@@ -55,15 +57,15 @@
import org.jboss.ejb3.ProxyFactory;
import org.jboss.ejb3.ProxyFactoryHelper;
import org.jboss.ejb3.ProxyUtils;
+import org.jboss.ejb3.cache.StatefulObjectFactory;
import org.jboss.ejb3.cache.StatefulCache;
-import org.jboss.ejb3.cache.StatefulObjectFactory;
import org.jboss.ejb3.interceptor.InterceptorInfoRepository;
import org.jboss.ejb3.proxy.EJBMetaDataImpl;
import org.jboss.ejb3.proxy.handle.HomeHandleImpl;
import org.jboss.ejb3.remoting.RemoteProxyFactory;
import org.jboss.ejb3.session.SessionContainer;
import org.jboss.injection.Injector;
-import org.jboss.injection.JndiFieldInjector;
+import org.jboss.injection.JndiPropertyInjector;
import org.jboss.logging.Logger;
/**
@@ -420,14 +422,21 @@
{
for (Injector injector : injectors)
{
- if (injector instanceof JndiFieldInjector)
+ if (injector instanceof JndiPropertyInjector)
{
- Field field = ((JndiFieldInjector) injector).getField();
+ AccessibleObject field = ((JndiPropertyInjector) injector).getAccessibleObject();
+
if (field.isAnnotationPresent(javax.ejb.EJB.class))
{
continue; // skip nested EJB injection since the local proxy will be (de)serialized correctly
}
- injector.inject(beanContext);
+
+ if (field instanceof Field)
+ {
+ // reinject transient fields
+ if ((((Field)field).getModifiers() & Modifier.TRANSIENT) > 0)
+ injector.inject(beanContext);
+ }
}
}
callbackHandler.postActivate(beanContext);
Modified: trunk/ejb3/src/main/org/jboss/injection/AbstractPropertyInjector.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/injection/AbstractPropertyInjector.java 2007-10-02 20:03:23 UTC (rev 65773)
+++ trunk/ejb3/src/main/org/jboss/injection/AbstractPropertyInjector.java 2007-10-02 21:51:29 UTC (rev 65774)
@@ -21,6 +21,8 @@
*/
package org.jboss.injection;
+import java.lang.reflect.AccessibleObject;
+
import org.jboss.ejb3.BeanContext;
import org.jboss.injection.lang.reflect.BeanProperty;
@@ -48,4 +50,9 @@
{
inject(ctx.getInstance());
}
+
+ public AccessibleObject getAccessibleObject()
+ {
+ return property.getAccessibleObject();
+ }
}
Added: trunk/ejb3/src/test/org/jboss/ejb3/test/stateful/TreeCacheStatefulBean.java
===================================================================
--- trunk/ejb3/src/test/org/jboss/ejb3/test/stateful/TreeCacheStatefulBean.java (rev 0)
+++ trunk/ejb3/src/test/org/jboss/ejb3/test/stateful/TreeCacheStatefulBean.java 2007-10-02 21:51:29 UTC (rev 65774)
@@ -0,0 +1,228 @@
+/*
+ * 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.test.stateful;
+
+import java.io.ObjectOutputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+
+import javax.annotation.Resource;
+import javax.annotation.Resources;
+import javax.ejb.Init;
+import javax.ejb.Local;
+import javax.ejb.Remote;
+import javax.ejb.Remove;
+import javax.ejb.SessionContext;
+import javax.ejb.Stateful;
+import javax.ejb.PrePassivate;
+import javax.ejb.PostActivate;
+import javax.interceptor.Interceptors;
+import javax.naming.InitialContext;
+import javax.naming.NamingEnumeration;
+
+import org.jboss.ejb3.Container;
+
+import org.jboss.annotation.ejb.RemoteBinding;
+import org.jboss.annotation.ejb.cache.Cache;
+import org.jboss.annotation.ejb.cache.tree.CacheConfig;
+import org.jboss.annotation.security.SecurityDomain;
+import org.jboss.logging.Logger;
+import org.jboss.serial.io.JBossObjectOutputStream;
+import org.jboss.serial.io.JBossObjectInputStream;
+
+/**
+ * @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
+ */
+ at Stateful(name="TreeCacheStatefulBean")
+ at Remote(org.jboss.ejb3.test.stateful.Stateful.class)
+ at Local(org.jboss.ejb3.test.stateful.StatefulLocal.class)
+ at RemoteBinding(jndiBinding = "TreeCacheStateful",
+ interceptorStack="RemoteBindingStatefulSessionClientInterceptors",
+ factory = org.jboss.ejb3.test.stateful.StatefulRemoteProxyFactory.class)
+ at CacheConfig(name="jboss.cache:service=EJB3SFSBClusteredCache", maxSize = 1000, idleTimeoutSeconds = 1)
+ at SecurityDomain("test")
+ at Resources({@Resource(name="jdbc/ds", mappedName="java:/DefaultDS")})
+ at Cache(org.jboss.ejb3.cache.tree.StatefulTreeCache.class)
+public class TreeCacheStatefulBean implements org.jboss.ejb3.test.stateful.Stateful
+{
+ private static final Logger log = Logger.getLogger(StatefulBean.class);
+
+ @Resource
+ private SessionContext sessionContext;
+
+ @Resource(mappedName="java:/DefaultDS")
+ private transient javax.sql.DataSource datasource;
+
+ @Resource(mappedName="java:/ConnectionFactory")
+ public transient javax.jms.QueueConnectionFactory connectionFactory;
+
+ private String state;
+ private int stuff;
+
+ @Interceptors(MyInterceptor.class)
+ public String getInterceptorState()
+ {
+ throw new RuntimeException("NOT REACHABLE");
+ }
+
+ @Interceptors(MyInterceptor.class)
+ public void setInterceptorState(String param)
+ {
+ throw new RuntimeException("NOT REACHABLE");
+ }
+
+ public boolean testSessionContext()
+ {
+ return sessionContext.isCallerInRole("role");
+ }
+
+ public void testResources() throws Exception
+ {
+ datasource.toString();
+ connectionFactory.toString();
+
+ javax.sql.DataSource ds = (javax.sql.DataSource)new InitialContext().lookup(Container.ENC_CTX_NAME + "/env/jdbc/ds");
+ ds.toString();
+ }
+
+ public String getState() throws Exception
+ {
+ Thread.sleep(1000);
+ return state;
+ }
+
+ public void setState(String state) throws Exception
+ {
+ Thread.sleep(1000);
+ this.state = state;
+ }
+
+ public boolean interceptorAccessed()
+ {
+ return RemoteBindingInterceptor.accessed;
+ }
+
+ public void testThrownException() throws Exception
+ {
+ throw new Exception();
+ }
+
+ public void testExceptionCause() throws Exception
+ {
+ Object o = null;
+ o.toString();
+ }
+
+ @PrePassivate
+ public void passivate()
+ {
+ log.info("************ passivating");
+ wasPassivated = true;
+ }
+
+ @PostActivate
+ public void activate()
+ {
+ log.info("************ activating");
+ }
+
+ private static boolean wasPassivated = false;
+
+ public void testSerializedState(String state)
+ {
+ this.state = state;
+
+ TreeCacheStatefulBean bean = null;
+ try
+ {
+ ObjectOutputStream out;
+
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+
+ out = new JBossObjectOutputStream(baos, false);
+ out.writeObject(this);
+ out.flush();
+
+ ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
+
+ JBossObjectInputStream is = new JBossObjectInputStream(bais);
+ bean = (TreeCacheStatefulBean)is.readObject();
+ }
+ catch (IOException e)
+ {
+ throw new RuntimeException(e);
+ }
+ catch (ClassNotFoundException e)
+ {
+ throw new RuntimeException(e);
+ }
+
+ if (!state.equals(bean.state)) throw new RuntimeException("failed to serialize: " + bean.state);
+ }
+
+ public boolean wasPassivated()
+ {
+ return wasPassivated;
+ }
+
+ public void clearPassivated()
+ {
+ wasPassivated = false;
+ }
+
+ @Init
+ public void ejbCreate(Integer state)
+ {
+ this.state=state.toString();
+ }
+
+ @Init
+ public void ejbCreate(State state)
+ {
+ this.state=state.getState();
+ }
+
+ @Init
+ public void ejbCreate(String state)
+ {
+ this.state=state;
+ }
+
+ @Remove
+ public void removeBean()
+ {
+
+ }
+
+ public void lookupStateful() throws Exception
+ {
+ // FIXME: NYI
+ throw new RuntimeException("NYI");
+ }
+
+ public void testStateful() throws Exception
+ {
+ // FIXME: NYI
+ throw new RuntimeException("NYI");
+ }
+}
Modified: trunk/ejb3/src/test/org/jboss/ejb3/test/stateful/unit/MetricsUnitTestCase.java
===================================================================
--- trunk/ejb3/src/test/org/jboss/ejb3/test/stateful/unit/MetricsUnitTestCase.java 2007-10-02 20:03:23 UTC (rev 65773)
+++ trunk/ejb3/src/test/org/jboss/ejb3/test/stateful/unit/MetricsUnitTestCase.java 2007-10-02 21:51:29 UTC (rev 65774)
@@ -100,8 +100,7 @@
assertFalse(stateful.testSessionContext());
- // Wolf: transient re-injection is broken (EJBTHREE-883)
- //stateful.testResources();
+ stateful.testResources();
count = (Integer)server.getAttribute(testerName, "CreateCount");
assertEquals(2, count);
More information about the jboss-cvs-commits
mailing list