[jboss-cvs] JBossAS SVN: r61238 - in trunk/ejb3/src: main/org/jboss/ejb3 and 7 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Fri Mar 9 06:47:23 EST 2007
Author: wolfc
Date: 2007-03-09 06:47:23 -0500 (Fri, 09 Mar 2007)
New Revision: 61238
Added:
trunk/ejb3/src/main/org/jboss/lang/
trunk/ejb3/src/main/org/jboss/lang/ref/
trunk/ejb3/src/main/org/jboss/lang/ref/WeakThreadLocal.java
Modified:
trunk/ejb3/src/main/org/jboss/ejb3/AbstractPool.java
trunk/ejb3/src/main/org/jboss/ejb3/EJBContainer.java
trunk/ejb3/src/main/org/jboss/ejb3/MCKernelAbstraction.java
trunk/ejb3/src/main/org/jboss/ejb3/Pool.java
trunk/ejb3/src/main/org/jboss/ejb3/SessionContainer.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/mdb/ConsumerContainer.java
trunk/ejb3/src/main/org/jboss/ejb3/mdb/MessagingContainer.java
trunk/ejb3/src/main/org/jboss/ejb3/service/ServiceContainer.java
trunk/ejb3/src/main/org/jboss/ejb3/stateful/StatefulClusterProxyFactory.java
trunk/ejb3/src/main/org/jboss/ejb3/stateful/StatefulContainer.java
trunk/ejb3/src/main/org/jboss/ejb3/stateful/StatefulRemoteProxyFactory.java
trunk/ejb3/src/main/org/jboss/ejb3/stateless/StatelessContainer.java
trunk/ejb3/src/test/org/jboss/ejb3/test/strictpool/BogusPool.java
Log:
EJBTHREE-840: proper start/stop semantics and destroying the pool
Modified: trunk/ejb3/src/main/org/jboss/ejb3/AbstractPool.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/AbstractPool.java 2007-03-09 11:46:28 UTC (rev 61237)
+++ trunk/ejb3/src/main/org/jboss/ejb3/AbstractPool.java 2007-03-09 11:47:23 UTC (rev 61238)
@@ -183,7 +183,7 @@
container.invokePostConstruct(ctx, initValues);
return ctx;
}
-
+
public void remove(BeanContext ctx)
{
try
Modified: trunk/ejb3/src/main/org/jboss/ejb3/EJBContainer.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/EJBContainer.java 2007-03-09 11:46:28 UTC (rev 61237)
+++ trunk/ejb3/src/main/org/jboss/ejb3/EJBContainer.java 2007-03-09 11:47:23 UTC (rev 61238)
@@ -37,6 +37,7 @@
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
+import java.util.Set;
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
@@ -54,7 +55,9 @@
import org.jboss.aop.AspectManager;
import org.jboss.aop.ClassContainer;
import org.jboss.aop.MethodInfo;
+import org.jboss.aop.advice.AspectDefinition;
import org.jboss.aop.advice.Interceptor;
+import org.jboss.aop.advice.Scope;
import org.jboss.aop.annotation.AnnotationElement;
import org.jboss.aop.joinpoint.ConstructorInvocation;
import org.jboss.aop.util.MethodHashing;
@@ -529,13 +532,42 @@
public void stop() throws Exception
{
encFactory.cleanupEnc(this);
+
+ pool.destroy();
+ pool = null;
+
+ log.info("STOPPED EJB: " + clazz.getName() + " ejbName: " + ejbName);
}
public void destroy() throws Exception
{
+ // FIXME: temporary hack: cleanup all references from aop to here
+
+ @SuppressWarnings("unchecked")
+ Set<AspectDefinition> set = (Set<AspectDefinition>) perInstanceAspectDefinitions;
+ for(AspectDefinition def : set)
+ {
+ removePerInstanceAspect(def);
+ def.advisors.remove(this);
+ }
+ for(AspectDefinition def : ((Map<AspectDefinition,?>) perInstanceJoinpointAspectDefinitions).keySet())
+ {
+ removePerInstanceJoinpointAspect(def);
+ def.advisors.remove(this);
+ }
+ // weirdness, add/removePerClassAspect are not mirror images
+ @SuppressWarnings("unchecked")
+ Map<AspectDefinition, Interceptor> map = ((Map<AspectDefinition, Interceptor>) adviceInterceptors);
+ // without toArray, concurrent modification
+ for(AspectDefinition def : map.keySet().toArray(new AspectDefinition[0]))
+ {
+ assert def.getScope() == Scope.PER_CLASS;
+ removePerClassAspect(def);
+ def.advisors.remove(this);
+ }
}
- public void initializePool() throws Exception
+ protected void initializePool() throws Exception
{
PoolClass poolClass = (PoolClass) resolveAnnotation(PoolClass.class);
Class<? extends Pool> poolClazz = poolClass.value();
Modified: trunk/ejb3/src/main/org/jboss/ejb3/MCKernelAbstraction.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/MCKernelAbstraction.java 2007-03-09 11:46:28 UTC (rev 61237)
+++ trunk/ejb3/src/main/org/jboss/ejb3/MCKernelAbstraction.java 2007-03-09 11:47:23 UTC (rev 61238)
@@ -195,6 +195,7 @@
{
try
{
+ log.info("uninstalling bean: " + name);
kernel.getController().uninstall(name);
}
catch (Exception e)
Modified: trunk/ejb3/src/main/org/jboss/ejb3/Pool.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/Pool.java 2007-03-09 11:46:28 UTC (rev 61237)
+++ trunk/ejb3/src/main/org/jboss/ejb3/Pool.java 2007-03-09 11:47:23 UTC (rev 61238)
@@ -62,4 +62,9 @@
void initialize(Container container, Class contextClass, Class beanClass, int maxSize, long timeout);
void setMaxSize(int maxSize);
+
+ /**
+ * Destroy the pool.
+ */
+ void destroy();
}
Modified: trunk/ejb3/src/main/org/jboss/ejb3/SessionContainer.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/SessionContainer.java 2007-03-09 11:46:28 UTC (rev 61237)
+++ trunk/ejb3/src/main/org/jboss/ejb3/SessionContainer.java 2007-03-09 11:47:23 UTC (rev 61238)
@@ -137,6 +137,7 @@
}
catch (Exception ignore)
{
+ log.trace("Proxy deployer stop failed", ignore);
}
try
{
@@ -144,7 +145,9 @@
}
catch (Exception ignore)
{
+ log.trace("Dispatcher unregister target failed", ignore);
}
+ super.stop();
}
protected void createMethodMap()
Modified: trunk/ejb3/src/main/org/jboss/ejb3/StrictMaxPool.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/StrictMaxPool.java 2007-03-09 11:46:28 UTC (rev 61237)
+++ trunk/ejb3/src/main/org/jboss/ejb3/StrictMaxPool.java 2007-03-09 11:47:23 UTC (rev 61238)
@@ -196,6 +196,11 @@
}
}
+ public void destroy()
+ {
+ freeAll();
+ }
+
public void discard(BeanContext ctx)
{
if (log.isTraceEnabled())
@@ -215,11 +220,13 @@
// Package protected ---------------------------------------------
// Protected -----------------------------------------------------
+ /*
protected void destroy() throws Exception
{
freeAll();
this.container = null;
}
+ */
// Private -------------------------------------------------------
Modified: trunk/ejb3/src/main/org/jboss/ejb3/ThreadlocalPool.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/ThreadlocalPool.java 2007-03-09 11:46:28 UTC (rev 61237)
+++ trunk/ejb3/src/main/org/jboss/ejb3/ThreadlocalPool.java 2007-03-09 11:47:23 UTC (rev 61238)
@@ -21,7 +21,10 @@
*/
package org.jboss.ejb3;
+import org.jboss.lang.ref.WeakThreadLocal;
+import org.jboss.logging.Logger;
+
/**
* Pools EJBs within a ThreadLocal.
*
@@ -30,15 +33,25 @@
*/
public class ThreadlocalPool extends AbstractPool
{
- protected ThreadLocal pool = new ThreadLocal();
+ private static final Logger log = Logger.getLogger(ThreadlocalPool.class);
+
+ protected WeakThreadLocal<BeanContext> pool = new WeakThreadLocal<BeanContext>();
public ThreadlocalPool()
{
}
+ public void destroy()
+ {
+ log.trace("destroying pool");
+
+ // This really serves little purpose, because we want the whole thread local map to die
+ pool.remove();
+ }
+
public BeanContext get()
{
- BeanContext ctx = (BeanContext) pool.get();
+ BeanContext ctx = pool.get();
if (ctx != null)
{
pool.set(null);
@@ -51,7 +64,7 @@
public BeanContext get(Class[] initTypes, Object[] initValues)
{
- BeanContext ctx = (BeanContext) pool.get();
+ BeanContext ctx = pool.get();
if (ctx != null)
{
pool.set(null);
Modified: trunk/ejb3/src/main/org/jboss/ejb3/mdb/ConsumerContainer.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/mdb/ConsumerContainer.java 2007-03-09 11:46:28 UTC (rev 61237)
+++ trunk/ejb3/src/main/org/jboss/ejb3/mdb/ConsumerContainer.java 2007-03-09 11:47:23 UTC (rev 61238)
@@ -301,7 +301,7 @@
public void stop() throws Exception
{
+ unregisterProducers();
super.stop();
- unregisterProducers();
}
}
Modified: trunk/ejb3/src/main/org/jboss/ejb3/mdb/MessagingContainer.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/mdb/MessagingContainer.java 2007-03-09 11:46:28 UTC (rev 61237)
+++ trunk/ejb3/src/main/org/jboss/ejb3/mdb/MessagingContainer.java 2007-03-09 11:47:23 UTC (rev 61238)
@@ -284,9 +284,12 @@
if (timerService != null)
{
TimerServiceFactory.getInstance().removeTimerService(timerService);
+ timerService = null;
}
stopProxies();
+
+ super.stop();
}
protected void stopProxies() throws Exception
@@ -294,10 +297,6 @@
messageEndpointFactory.stop();
}
- public void destroy() throws Exception
- {
- }
-
// ********* JMS Specific
protected static final String JMS_ADAPTOR = "jms-ra.rar";
protected static final String DESTINATION = "destination";
@@ -305,7 +304,7 @@
protected static final String PROVIDER_ADAPTER_JNDI = "providerAdapterJNDI";
protected static final String MAX_SESSION = "maxSession";
- public void initializePool() throws Exception
+ protected void initializePool() throws Exception
{
super.initializePool();
Modified: trunk/ejb3/src/main/org/jboss/ejb3/service/ServiceContainer.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/service/ServiceContainer.java 2007-03-09 11:46:28 UTC (rev 61237)
+++ trunk/ejb3/src/main/org/jboss/ejb3/service/ServiceContainer.java 2007-03-09 11:47:23 UTC (rev 61238)
@@ -169,14 +169,18 @@
{
invokeOptionalMethod("stop");
- if (timerService != null) TimerServiceFactory.getInstance().removeTimerService(timerService);
+ if (timerService != null)
+ {
+ TimerServiceFactory.getInstance().removeTimerService(timerService);
+ timerService = null;
+ }
// TODO: EJBTHREE-655: shouldn't happen here, but in destroy
unregisterManagementInterface();
+
+ injected = false;
super.stop();
-
- injected = false;
}
public void destroy() throws Exception
Modified: trunk/ejb3/src/main/org/jboss/ejb3/stateful/StatefulClusterProxyFactory.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/stateful/StatefulClusterProxyFactory.java 2007-03-09 11:46:28 UTC (rev 61237)
+++ trunk/ejb3/src/main/org/jboss/ejb3/stateful/StatefulClusterProxyFactory.java 2007-03-09 11:47:23 UTC (rev 61238)
@@ -158,11 +158,11 @@
public void stop() throws Exception
{
- super.stop();
+ Dispatcher.singleton.unregisterTarget(jndiName + PROXY_FACTORY_NAME);
hatarget.destroy();
((StatefulContainer) container).getClusterFamilies().remove(proxyFamilyName);
Util.unbind(container.getInitialContext(), jndiName + PROXY_FACTORY_NAME);
-
+ super.stop();
}
protected StatefulHandleImpl getHandle()
Modified: trunk/ejb3/src/main/org/jboss/ejb3/stateful/StatefulContainer.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/stateful/StatefulContainer.java 2007-03-09 11:46:28 UTC (rev 61237)
+++ trunk/ejb3/src/main/org/jboss/ejb3/stateful/StatefulContainer.java 2007-03-09 11:47:23 UTC (rev 61238)
@@ -110,8 +110,8 @@
public void stop() throws Exception
{
+ if (cache != null) cache.stop();
super.stop();
- if (cache != null) cache.stop();
}
public StatefulCache getCache()
Modified: trunk/ejb3/src/main/org/jboss/ejb3/stateful/StatefulRemoteProxyFactory.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/stateful/StatefulRemoteProxyFactory.java 2007-03-09 11:46:28 UTC (rev 61237)
+++ trunk/ejb3/src/main/org/jboss/ejb3/stateful/StatefulRemoteProxyFactory.java 2007-03-09 11:47:23 UTC (rev 61238)
@@ -111,7 +111,6 @@
public void stop() throws Exception
{
- super.stop();
Util.unbind(container.getInitialContext(), jndiName + PROXY_FACTORY_NAME);
Dispatcher.singleton.unregisterTarget(jndiName + PROXY_FACTORY_NAME);
StatefulContainer statefulContainer = (StatefulContainer) container;
@@ -120,6 +119,7 @@
{
Util.unbind(container.getInitialContext(), ProxyFactoryHelper.getHomeJndiName(container));
}
+ super.stop();
}
Modified: trunk/ejb3/src/main/org/jboss/ejb3/stateless/StatelessContainer.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/stateless/StatelessContainer.java 2007-03-09 11:46:28 UTC (rev 61237)
+++ trunk/ejb3/src/main/org/jboss/ejb3/stateless/StatelessContainer.java 2007-03-09 11:47:23 UTC (rev 61238)
@@ -92,7 +92,7 @@
try
{
super.start();
- //timerService = EjbTimerUtil.getTimerService(this, this);
+
timerService = TimerServiceFactory.getInstance().createTimerService(this.getObjectName(), this);
TimerServiceFactory.getInstance().restoreTimerService(timerService);
@@ -113,8 +113,12 @@
public void stop() throws Exception
{
- //if (timerService != null) EjbTimerUtil.removeTimerService(this);
- if (timerService != null) TimerServiceFactory.getInstance().removeTimerService(timerService);
+ if (timerService != null)
+ {
+ TimerServiceFactory.getInstance().removeTimerService(timerService);
+ timerService = null;
+ }
+
super.stop();
}
Added: trunk/ejb3/src/main/org/jboss/lang/ref/WeakThreadLocal.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/lang/ref/WeakThreadLocal.java (rev 0)
+++ trunk/ejb3/src/main/org/jboss/lang/ref/WeakThreadLocal.java 2007-03-09 11:47:23 UTC (rev 61238)
@@ -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.lang.ref;
+
+import java.lang.ref.WeakReference;
+
+/**
+ * @author carlo
+ *
+ */
+public class WeakThreadLocal<T>
+{
+ private ThreadLocal<WeakReference<T>> delegate = new ThreadLocal<WeakReference<T>>();
+
+ public T get()
+ {
+ WeakReference<T> ref = delegate.get();
+ if(ref == null)
+ return null;
+ return ref.get();
+ }
+
+ public void remove()
+ {
+ delegate.remove();
+ }
+
+ public void set(T value)
+ {
+ delegate.set(new WeakReference<T>(value));
+ }
+}
Modified: trunk/ejb3/src/test/org/jboss/ejb3/test/strictpool/BogusPool.java
===================================================================
--- trunk/ejb3/src/test/org/jboss/ejb3/test/strictpool/BogusPool.java 2007-03-09 11:46:28 UTC (rev 61237)
+++ trunk/ejb3/src/test/org/jboss/ejb3/test/strictpool/BogusPool.java 2007-03-09 11:47:23 UTC (rev 61238)
@@ -53,6 +53,11 @@
throw new RuntimeException("Bogus");
}
+ public void destroy()
+ {
+ throw new RuntimeException("Bogus");
+ }
+
public void discard(BeanContext ctx)
{
throw new RuntimeException("Bogus");
More information about the jboss-cvs-commits
mailing list