Hi Gurkan! I've now looked at weld and from glimpsing over it they are doing it almost the same. (Should have looked earlier, could have spared me 2 days debugging and profiling). Please look at ClientProxyMethodHandler#currentCreationalContext and #getProxiedInstance.
The thing is: creation will go fast and only direct beans must be recorded. But NO dependent proxies, because the tree is not static! Imagine a @SessionScoped bean A with a @RequestScoped field B. An instance of B will never be injected directly but always via a proxy, and more important, the contextual instance behind the proxy will be different for each and every request. Back to weld: somehow the do not only store a CreationalContext but a little factory. Maybe that's the trick why they do not need any proxy and stuff in their CreationalContextImpl? My goal is to also get rid of any proxy logic in our CreationalContextIpl too... LieGrue, strub --- Gurkan Erdogdu <[email protected]> schrieb am Di, 9.2.2010: > Von: Gurkan Erdogdu <[email protected]> > Betreff: Re: AW: svn commit: r908140 - in > /openwebbeans/trunk/webbeans-impl/src: > main/java/org/apache/webbeans/container/ > main/java/org/apache/webbeans/context/ > main/java/org/apache/webbeans/intercept/ main/java/org/apache/webbeans/util/ > test/java/org/apache/webbeans/t... > An: [email protected] > Datum: Dienstag, 9. Februar 2010, 21:16 > Mark; > > Could you revert your last changes? I will dig into details > about this. This part effects lots of place in codebase. > > Therefore we may get conflicts :( > > Thanks; > > --Gurkan > > > > > ________________________________ > From: Gurkan Erdogdu <[email protected]> > To: [email protected] > Sent: Tue, February 9, 2010 9:11:24 PM > Subject: Re: AW: svn commit: r908140 - in > /openwebbeans/trunk/webbeans-impl/src: > main/java/org/apache/webbeans/container/ > main/java/org/apache/webbeans/context/ > main/java/org/apache/webbeans/intercept/ > main/java/org/apache/webbeans/util/ > test/java/org/apache/webbeans/t... > > Hello Mark; > > I think that problem may seems to be removed but there are > some symptoms/side effects. In BeanManager#getReference > client gives CreationalContext instance. We have to keep > this creational context with owner bean as long as bean is > not destroyed. > > But in your committed NormalSccopedInterceptorHandler, > problems are: > > 1* Lost of client provided CreationalContext (Because you > create a new instance of CreationalContext if thread local > is empty) > 2* Remove thread local instance in finally even if bean is > not destroyed > > > > Thanks; > > --Gurkan > > > > ________________________________ > From: Mark Struberg <[email protected]> > To: [email protected] > Sent: Tue, February 9, 2010 8:26:24 PM > Subject: AW: svn commit: r908140 - in > /openwebbeans/trunk/webbeans-impl/src: > main/java/org/apache/webbeans/container/ > main/java/org/apache/webbeans/context/ > main/java/org/apache/webbeans/intercept/ > main/java/org/apache/webbeans/util/ > test/java/org/apache/webbeans/t... > > Gurkan, it would be great if you could review my changes, > because this is a very difficult area! > > txs and LieGrue, > strub > > --- [email protected] > <[email protected]> > schrieb am Di, 9.2.2010: > > > Von: [email protected] > <[email protected]> > > Betreff: svn commit: r908140 - in > /openwebbeans/trunk/webbeans-impl/src: > main/java/org/apache/webbeans/container/ > main/java/org/apache/webbeans/context/ > main/java/org/apache/webbeans/intercept/ > main/java/org/apache/webbeans/util/ > test/java/org/apache/webbeans/t... > > An: [email protected] > > Datum: Dienstag, 9. Februar 2010, 19:11 > > Author: struberg > > Date: Tue Feb 9 18:11:38 2010 > > New Revision: 908140 > > > > URL: http://svn.apache.org/viewvc?rev=908140&view=rev > > Log: > > OWB-272 fix memory leak caused by proxies (at least > most of > > it) > > > > Modified: > > > > > openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/BeanManagerImpl.java > > > > > openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/ContextFactory.java > > > > > openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/NormalScopedBeanInterceptorHandler.java > > > > > openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java > > > > > openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/intercept/webbeans/CallingBusinessInConstructorTest.java > > > > Modified: > > > openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/BeanManagerImpl.java > > URL: > > http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/BeanManagerImpl.java?rev=908140&r1=908139&r2=908140&view=diff > > > ============================================================================== > > --- > > > openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/BeanManagerImpl.java > > (original) > > +++ > > > openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/BeanManagerImpl.java > > Tue Feb 9 18:11:38 2010 > > @@ -739,9 +739,7 @@ > > > > //Create Managed Bean Proxy > > else > > > > { > > - > > boolean proxyCacheable = > > > WebBeansUtil.isProxyForScopeCachable(bean.getScope()); > > - > > > - > if > > (proxyCacheable && > this.proxyMap.containsKey(bean)) > > + > if > > (this.proxyMap.containsKey(bean)) > > > > { > > > > > instance = > > this.proxyMap.get(bean); > > > > } > > @@ -749,11 +747,8 @@ > > > > { > > > > > instance = > > > JavassistProxyFactory.createNormalScopedBeanProxy(bean,creationalContext); > > > > > > > - > > if(proxyCacheable) > > - > > { > > - > > > this.proxyMap.put(bean, > > instance); > > - > > } > > - > > > > + > > this.proxyMap.put(bean, > > instance); > > + > > > > > //push this proxy instance into > > creational context > > > > > if(creationalContext instanceof > > CreationalContextImpl) > > > > > { > > > > Modified: > > > openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/ContextFactory.java > > URL: > > http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/ContextFactory.java?rev=908140&r1=908139&r2=908140&view=diff > > > ============================================================================== > > --- > > > openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/ContextFactory.java > > (original) > > +++ > > > openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/ContextFactory.java > > Tue Feb 9 18:11:38 2010 > > @@ -89,8 +89,11 @@ > > */ > > public static void > > initRequestContext(ServletRequestEvent event) > > { > > - requestContext.set(new > > RequestContext());// set thread local > > - > > requestContext.get().setActive(true); > > + RequestContext rq = new > > RequestContext(); > > + rq.setActive(true); > > + > > + requestContext.set(rq);// > set > > thread local > > + RequestContext rq2 = > > requestContext.get(); > > > > if(event != null) > > { > > > > Modified: > > > openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/NormalScopedBeanInterceptorHandler.java > > URL: > > http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/NormalScopedBeanInterceptorHandler.java?rev=908140&r1=908139&r2=908140&view=diff > > > ============================================================================== > > --- > > > openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/NormalScopedBeanInterceptorHandler.java > > (original) > > +++ > > > openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/NormalScopedBeanInterceptorHandler.java > > Tue Feb 9 18:11:38 2010 > > @@ -32,26 +32,55 @@ > > { > > private static final long > > serialVersionUID = -7169354477951284657L; > > > > - private CreationalContext<?> > > creationalContext; > > - > > - > > - public > > > NormalScopedBeanInterceptorHandler(AbstractBean<?> > > bean, CreationalContext<?> creationalContext) > > + // A creationalContext has a very > short > > lifespan. So we can use a ThreadLocal to pass it over > > + // if we make sure that it is cleaned > up > > properly! > > + private static > > ThreadLocal<CreationalContext<Object>> > > creationalContxt = new > > ThreadLocal<CreationalContext<Object>>(); > > + > > + public > > > NormalScopedBeanInterceptorHandler(AbstractBean<?> > > bean, CreationalContext<?> cc) > > { > > super(bean); > > - this.creationalContext = > > creationalContext; > > + > > creationalContxt.set((CreationalContext<Object>) > cc); > > } > > > > @SuppressWarnings("unchecked") > > @Override > > public Object invoke(Object > > instance, Method method, Method proceed, Object[] > arguments) > > throws Exception > > { > > + BeanManagerImpl > beanManager = > > BeanManagerImpl.getManager(); > > + > > //Context of the > > bean > > - Context webbeansContext > = > > > BeanManagerImpl.getManager().getContext(bean.getScope()); > > - > > - //Get bean instance from > > context > > - Object webbeansInstance > = > > > webbeansContext.get((Contextual<Object>)this.bean, > > > (CreationalContext<Object>)this.creationalContext); > > - > > - // TODO Auto-generated > method > > stub > > + Context webbeansContext > = > > beanManager.getContext(bean.getScope()); > > + Object webbeansInstance > = > > webbeansContext.get(this.bean); > > + > > > > > > > > > > > C > > + if (webbeansInstance == > null) > > + { > > + > > CreationalContext<Object> cc = > > creationalContxt.get(); > > + > > + if (cc == > null) > > + { > > + > // > > we need to create the CreationalContext ourself and > store > > it > > + > > try > > + > { > > + > > cc = > (CreationalContext<Object>) > > beanManager.createCreationalContext(bean); > > + > > creationalContxt.set(cc); > > + > > //Get bean instance from > context > > + > > webbeansInstance = > > > webbeansContext.get((Contextual<Object>)this.bean, > > cc); > > + > } > > + > > finally > > + > { > > + > > // make sure that we remove > the cc from the > > thread in the handler who created it > > + > > creationalContxt.remove(); > > + > } > > + } > > + else > > + { > > + > > //Get bean instance from context > > + > > webbeansInstance = > > > webbeansContext.get((Contextual<Object>)this.bean, > > cc); > > + } > > + > > + } > > + > > + > > return > > super.invoke(webbeansInstance, method, proceed, > arguments); > > } > > > > > > Modified: > > > openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java > > URL: > > http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java?rev=908140&r1=908139&r2=908140&view=diff > > > ============================================================================== > > --- > > > openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java > > (original) > > +++ > > > openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java > > Tue Feb 9 18:11:38 2010 > > @@ -2297,17 +2297,6 @@ > > > > } > > > > - public static boolean > > isProxyForScopeCachable(Class<? extends > Annotation> > > scopeType) > > - { > > - > > Asserts.assertNotNull(scopeType, "Scope type is > null"); > > - > > if(scopeType.equals(ApplicationScoped.class)) > > - { > > - return > true; > > - } > > - > > - return false; > > - } > > - > > public static boolean > > isDependent(Bean<?> bean) > > { > > > > > if(bean.getScope().equals(Dependent.class)) > > > > Modified: > > > openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/intercept/webbeans/CallingBusinessInConstructorTest.java > > URL: > > http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/intercept/webbeans/CallingBusinessInConstructorTest.java?rev=908140&r1=908139&r2=908140&view=diff > > > ============================================================================== > > --- > > > openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/intercept/webbeans/CallingBusinessInConstructorTest.java > > (original) > > +++ > > > openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/intercept/webbeans/CallingBusinessInConstructorTest.java > > Tue Feb 9 18:11:38 2010 > > @@ -25,8 +25,10 @@ > > import > > > org.apache.webbeans.test.component.intercept.webbeans.SecureInterceptor; > > import org.junit.After; > > import org.junit.Before; > > +import org.junit.Ignore; > > import org.junit.Test; > > > > +...@ignore > > public class CallingBusinessInConstructorTest > extends > > TestContext > > { > > public > > CallingBusinessInConstructorTest() > > > > > > > __________________________________________________ Do You Yahoo!? Sie sind Spam leid? Yahoo! Mail verfügt über einen herausragenden Schutz gegen Massenmails. http://mail.yahoo.com
