<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=Windows-1252">
<style type="text/css" style="display:none"><!--P{margin-top:0;margin-bottom:0;} --></style>
</head>
<body dir="ltr" style="font-size:12pt;color:#000000;background-color:#FFFFFF;font-family:Calibri,Arial,Helvetica,sans-serif;">
<p>Hi,</p>
<p><br>
</p>
<p>That somehow relates to the <span style="font-family: &quot;Courier New&quot;,monospace;">
BeforeShutdown <span style="font-family: Calibri,Arial,Helvetica,sans-serif;"></span><span style="font-family: Calibri,Arial,Helvetica,sans-serif;"></span></span>lifecycle event which must be fired after the container has finished processing requests and destroyed
 all contexts.</p>
<p><br>
</p>
<p>IMO, it would make sense / be useful to be able to execute logic on <span style="font-family: &quot;Courier New&quot;,monospace;">
ApplicationScoped</span> beans from within extensions before they are about to be &quot;destroyed&quot;.<br>
</p>
<p><br>
</p>
<p>In the example from the specification (and&nbsp;consistently with other&nbsp;lifecycle events), one can retrieve a reference to the bean manager:<br>
</p>
<p><br>
</p>
<p><span style="font-family: &quot;Courier New&quot;,monospace;">void beforeShutdown(@Observes BeforeShutdown event, BeanManager manager) { ... }</span></p>
<p><br>
</p>
<p>While that is not clearly stated in the specification (as opposed to the clarification done in version 1.2 for events like
<span style="font-family: &quot;Courier New&quot;,monospace;">AfterBeanDiscovery</span> and
<span style="font-family: &quot;Courier New&quot;,monospace;">AfterDeploymentValidation</span>), I&nbsp;induce that methods like
<span style="font-family: &quot;Courier New&quot;,monospace;">getReference</span> are supposed to systematically throw
<span style="font-family: &quot;Courier New&quot;,monospace;">ContextNotActiveException</span>.</p>
<p><br>
</p>
<p>To still meet the need, that is external control&nbsp;over <span style="font-family: &quot;Courier New&quot;,monospace;">
ApplicationScoped</span> bean&nbsp;destruction without relying on the <span style="font-family: &quot;Courier New&quot;,monospace;">
@PreDestroy</span> callback nor disposer method,&nbsp;an intermediate lifecycle&nbsp;event may be&nbsp;introduced, similarly to&nbsp;<span style="font-family: &quot;Courier New&quot;,monospace;">@Initializing</span> /
<span style="font-family: &quot;Courier New&quot;,monospace;">@Destroying(ApplicationScoped.class)</span>. Interestingly enough, the specification states that the application scope is active [...] when the disposer method or
<code>@PreDestroy</code> callback of any bean with any normal scope other than <code>
@ApplicationScoped</code> is called, which tends to validate John's &quot;lower scopes&quot; hypothesis.<br>
</p>
<p><br>
</p>
<p>For the information, calling <span style="font-family: &quot;Courier New&quot;,monospace;">
BeanManager.getReference</span> in <span style="font-family: &quot;Courier New&quot;,monospace;">
BeforeShutdown</span> actually works in Weld 2.x (I haven't tested that use case in OWB).<br>
</p>
<p><br>
</p>
<p>Antonin</p>
<div style="color: rgb(33, 33, 33);">
<hr tabindex="-1" style="display:inline-block; width:98%">
<div id="divRplyFwdMsg" dir="ltr"><font style="font-size:11pt" color="#000000" face="Calibri, sans-serif"><b>From:</b> cdi-dev-bounces@lists.jboss.org &lt;cdi-dev-bounces@lists.jboss.org&gt; on behalf of Romain Manni-Bucau &lt;rmannibucau@gmail.com&gt;<br>
<b>Sent:</b> Tuesday, April 28, 2015 10:14 PM<br>
<b>To:</b> John D. Ament<br>
<b>Cc:</b> cdi-dev@lists.jboss.org<br>
<b>Subject:</b> Re: [cdi-dev] @Destroyed(ApplicationScoped.class)</font>
<div>&nbsp;</div>
</div>
<div>
<p dir="ltr">Tcks check this event is &quot;accessible&quot; which is important otherwise it is just useless</p>
<p dir="ltr">What is not well defined is integration with other parts of ee.<br>
</p>
<div class="gmail_quote">Le 28 avr. 2015 21:00, &quot;John D. Ament&quot; &lt;<a href="mailto:john.d.ament@gmail.com">john.d.ament@gmail.com</a>&gt; a écrit :<br type="attribution">
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex; border-left:1px #ccc solid; padding-left:1ex">
<div dir="ltr">Your understanding matches my understanding, and matches what I typically tell people to do (use @PreDestroy).
<div><br>
</div>
<div>I think this is more of a use case for lower scopes, or for a dependent bean (which I would imagine would receive this event, though I can't say I've tried).</div>
<div><br>
</div>
<div>John<br>
<br>
<div class="gmail_quote">On Tue, Apr 28, 2015 at 2:56 PM Mark Struberg &lt;<a href="mailto:struberg@yahoo.de" target="_blank">struberg@yahoo.de</a>&gt; wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex; border-left:1px #ccc solid; padding-left:1ex">
Hi!<br>
<br>
The CDI-1.2 spec says in 6.7.3:<br>
<br>
„An event with qualifier @Initialized(ApplicationScoped.class) is fired when the application context is initialized and an event with qualifier @Destroyed(ApplicationScoped.class) is fired when the application is destroyed. &quot;<br>
<br>
Now from the pure wording („IS initialized“, „IS destroyed“) I’d say that both events must be fired _after_ the state is reached. Means _after_ the context got initialized and _after_ the context got destroyed.<br>
<br>
Means an observer like<br>
<br>
@ApplicationScoped<br>
public class MyBean {<br>
&nbsp; public void endIt(@Observes @Destroyed(ApplicationScoped.class) endObject) {<br>
&nbsp; &nbsp; doSomething()<br>
&nbsp; }<br>
}<br>
<br>
will _never_ get invoked.<br>
Because the bean (and the whole context) will be already killed…<br>
<br>
You can observe this event in a @Singleton scoped bean, but not in an @ApplicationScoped bean.<br>
If you like to do _that_, then simply use a @PreDestroy.<br>
<br>
Do others share this interpretation? Do we need to clarify anything?<br>
<br>
LieGrue,<br>
strub<br>
_______________________________________________<br>
cdi-dev mailing list<br>
<a href="mailto:cdi-dev@lists.jboss.org" target="_blank">cdi-dev@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/cdi-dev" target="_blank">https://lists.jboss.org/mailman/listinfo/cdi-dev</a><br>
<br>
Note that for all code provided on this list, the provider licenses the code under the Apache License, Version 2 (<a href="http://www.apache.org/licenses/LICENSE-2.0.html" target="_blank">http://www.apache.org/licenses/LICENSE-2.0.html</a>). For all other ideas
 provided on this list, the provider waives all patent and other intellectual property rights inherent in such information.</blockquote>
</div>
</div>
</div>
<br>
_______________________________________________<br>
cdi-dev mailing list<br>
<a href="mailto:cdi-dev@lists.jboss.org">cdi-dev@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/cdi-dev" target="_blank">https://lists.jboss.org/mailman/listinfo/cdi-dev</a><br>
<br>
Note that for all code provided on this list, the provider licenses the code under the Apache License, Version 2 (<a href="http://www.apache.org/licenses/LICENSE-2.0.html" target="_blank">http://www.apache.org/licenses/LICENSE-2.0.html</a>). For all other ideas
 provided on this list, the provider waives all patent and other intellectual property rights inherent in such information.<br>
</blockquote>
</div>
</div>
</div>
</body>
</html>