<div dir="ltr">Hi,<br><div class="gmail_extra"><br><div class="gmail_quote">On Wed, May 11, 2016 at 10:54 AM, Martin Kouba <span dir="ltr"><<a href="mailto:mkouba@redhat.com" target="_blank">mkouba@redhat.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Hi Arjan,<br>
<br>
the test attached to WELD-2148 is wrong. We can not inspect an actual SLSB instance. The only thing we could test is that Instance.destroy() does not throw UnsupportedException for SLSB CDI reference.<br></blockquote><div><br></div><div>I see, thanks for the clarification!</div><div><br></div><div>Going forward, would it not be convenient if an Instance was AutoCloseable, so that one could do:</div><div><br></div><div>try (Instance<Foo> fooInstance =<span style="white-space:pre"> </span>CDI.current().select(Foo.class)) {</div><div> Foo foo = fooInstance.get();</div><div> foo.bar();</div><div>}</div><div><br></div><div>Kind regards,</div><div>Arjan Tijms</div><div><br></div><div><br></div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<br>
Martin<br>
<br>
Dne 11.5.2016 v 10:40 arjan tijms napsal(a):<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><span class="">
Hi Martin,<br>
<br>
Thanks for the swift action and the reference. I do have one more<br>
question looking at the test that was added. It now uses this SLSB:<br>
<br>
@Stateless<br>
public class SLSessionBean {<br>
<br>
public void ping(){<br>
}<br>
<br>
static final AtomicBoolean DESTROYED = new AtomicBoolean();<br>
<br>
@PreDestroy<br>
public void destroy() {<br>
DESTROYED.set(true);<br>
}<br>
}<br>
<br>
The assertion in the test is that the (a?) SLSB is actually destroyed,<br>
but wasn't the idea that only the internal reference is destroyed, and<br>
the bean just stays in the pool?<br>
<br>
Here it looks like the code intends to destroy a random SLSB instance<br>
from the pool. (random, since I guess an internal reference doesn't<br>
stick to the same actual instance of a SLSB, otherwise you would get<br>
stateful like semantics).<br>
<br>
Or did I miss something?<br>
<br>
Kind regards,<br>
Arjan Tijms<br>
<br>
<br>
<br>
<br>
On Wed, May 11, 2016 at 9:11 AM, Martin Kouba <<a href="mailto:mkouba@redhat.com" target="_blank">mkouba@redhat.com</a><br></span><div><div class="h5">
<mailto:<a href="mailto:mkouba@redhat.com" target="_blank">mkouba@redhat.com</a>>> wrote:<br>
<br>
Hi Arjan,<br>
<br>
I believe it's a Weld bug - you should be able to use<br>
Instance.destroy() to discard an internal SLSB proxy. See also<br>
"Lifecycle of stateless and singleton session beans" [1]. Tomas<br>
Remes created WELD-2148 to track this issue [2].<br>
<br>
Also the "leak" is an expected behaviour. See for example WELD-920<br>
[3] discussion.<br>
<br>
Martin<br>
<br>
[1]<br>
<a href="http://docs.jboss.org/cdi/spec/1.2/cdi-spec.html#stateless_lifecycle" rel="noreferrer" target="_blank">http://docs.jboss.org/cdi/spec/1.2/cdi-spec.html#stateless_lifecycle</a><br>
<br>
[2]<br>
<a href="https://issues.jboss.org/browse/WELD-2148" rel="noreferrer" target="_blank">https://issues.jboss.org/browse/WELD-2148</a><br>
<br>
[3]<br>
<a href="https://issues.jboss.org/browse/WELD-920" rel="noreferrer" target="_blank">https://issues.jboss.org/browse/WELD-920</a><br>
<br>
Dne 10.5.2016 v 17:11 arjan tijms napsal(a):<br>
<br>
Hi,<br>
<br>
Given a simple @Stateless bean:<br>
<br>
@Stateless<br>
public class Foo {<br>
public void bar() {}<br>
}<br>
<br>
Then requesting an instance of this via CDI as follows:<br>
<br>
Foo foo = CDI.current().select(Foo.class).get();<br>
<br>
Causes a lot of leaked proxy instances (at least on Weld). Now<br>
what I<br>
guess needs to be done is destroying the proxy, taking Antoine's<br>
answer<br>
here as a lead:<br>
<a href="http://stackoverflow.com/questions/28767536/scope-of-stateless-bean" rel="noreferrer" target="_blank">http://stackoverflow.com/questions/28767536/scope-of-stateless-bean</a><br>
<br>
Only the following throws an UnsupportedOperationException (on Weld<br>
2.3.2, haven't tested OWB yet)<br>
<br>
Instance<Foo> fooInstance =CDI.current().select(Foo.class);<br>
Foo foo = fooInstance.get();<br>
foo.bar();<br>
fooInstance.destroy(foo);<br>
<br>
The question is, is this how it's supposed to be done via the spec?<br>
<br>
Implementation wise, what happens in Weld is that the CDI/EJB proxy<br>
(com.test.Foo$Proxy$_$$_Weld$EnterpriseProxy$) in the following code<br>
doesn't hit the check for a dependent instance (comments in capitals<br>
added by me):<br>
<br>
<br>
public void destroy(T instance) {<br>
Preconditions.checkNotNull(instance);<br>
<br>
// check if this is a proxy of a normal-scoped bean<br>
if (instance instanceof ProxyObject) {<br>
<br>
// THIS BRANCH IS TAKEN FOR CDI/EJB PROXY<br>
<br>
ProxyObject proxy = (ProxyObject) instance;<br>
if (proxy.getHandler() instanceof<br>
ProxyMethodHandler) {<br>
ProxyMethodHandler handler = (ProxyMethodHandler)<br>
proxy.getHandler();<br>
Bean<?> bean = handler.getBean();<br>
Context context =<br>
getBeanManager().getContext(bean.getScope());<br>
if (context instanceof AlterableContext) {<br>
AlterableContext alterableContext =<br>
(AlterableContext) context;<br>
<br>
// CONTEXT IS A DEPENDENTCONTEXTIMPL THAT<br>
THROWS<br>
// UnsupportedOperationException FROM ITS<br>
DESTROY()<br>
METHOD<br>
alterableContext.destroy(bean);<br>
return;<br>
} else {<br>
throw<br>
BeanLogger.LOG.destroyUnsupported(context);<br>
}<br>
}<br>
}<br>
<br>
// check if this is a dependent instance<br>
CreationalContext<? super T> ctx = getCreationalContext();<br>
if (ctx instanceof WeldCreationalContext<?>) {<br>
WeldCreationalContext<? super T> weldCtx = cast(ctx);<br>
<br>
// PROXY REFERENCES ARE KEPT HERE IN A<br>
// "dependentInstances" LIST, AND WOULD BE CLEARED<br>
HERE<br>
// BUT THIS CODE IS NEVER REACHED<br>
weldCtx.destroyDependentInstance(instance);<br>
}<br>
}<br>
<br>
Now I wonder, am I doing something wrong (according to the CDI<br>
spec), or<br>
could this be a bug in the Weld code?<br>
<br>
Kind regards,<br>
Arjan Tijms<br>
<br>
<br>
_______________________________________________<br>
cdi-dev mailing list<br></div></div>
<a href="mailto:cdi-dev@lists.jboss.org" target="_blank">cdi-dev@lists.jboss.org</a> <mailto:<a href="mailto:cdi-dev@lists.jboss.org" target="_blank">cdi-dev@lists.jboss.org</a>><span class=""><br>
<a href="https://lists.jboss.org/mailman/listinfo/cdi-dev" rel="noreferrer" target="_blank">https://lists.jboss.org/mailman/listinfo/cdi-dev</a><br>
<br>
Note that for all code provided on this list, the provider<br>
licenses the code under the Apache License, Version 2<br>
(<a href="http://www.apache.org/licenses/LICENSE-2.0.html" rel="noreferrer" target="_blank">http://www.apache.org/licenses/LICENSE-2.0.html</a>). For all other<br>
ideas provided on this list, the provider waives all patent and<br>
other intellectual property rights inherent in such information.<br>
<br>
<br>
--<br>
Martin Kouba<br>
Software Engineer<br>
Red Hat, Czech Republic<br>
<br>
<br>
</span></blockquote><div class=""><div class="h5">
<br>
-- <br>
Martin Kouba<br>
Software Engineer<br>
Red Hat, Czech Republic<br>
</div></div></blockquote></div><br></div></div>