<HTML><BODY>Martin,<br><br>Thank you for your answer. I replaced 2.3.5.Final with 2.2.16.Final. Besides in 2.2.16 in<br>manifest I had to export package org.jboss.weld.config which is used by pax-cdi. <br><br>Now on bundle start:<br>Test was created.<br>java.lang.Object@6bc3928f<br>Test was initialized<br><br>Now on bundle stop:<br>java.lang.Object@6bc3928f<br>Test was destroyed.<br><br>Понедельник, 22 мая 2017, 12:27 +03:00 от Martin Kouba <mkouba@redhat.com>:<br><blockquote style="border-left:1px solid #0857A6; margin:10px; padding:0 0 0 10px;">
        <br>
        <div id="">
        
<div class="js-helper js-readmsg-msg">
        <style type="text/css"></style>
        <div>
                <base target="_self" href="https://e.mail.ru/">
                
<div id="style_14954452670000000208_BODY">Dne 22.5.2017 v 11:14 Alex Sviridov napsal(a):<br>
> Martin,<br>
> <br>
> In your message you wrote : "Up to version 2.2 Weld did not fire <br>
> @Initialized/@Destroyed events for<br>
> @ApplicationScoped for non-web modules.".<br>
> <br>
> In WELD-2389 you wrote : "Right now, this service is registered for any <br>
> non-SE environment".<br>
> <br>
> I use OSGi + PAX-CDI + WELD + JAVAFX. As I suppose this is a SE <br>
> application (not EE).<br>
> Could you explain "Right now, this service is registered for any non-SE <br>
> environment" ?<br>
<br>
Well, I'm talking about Weld SPI and I'm refering to the environment <br>
info provided by the integrator. PAX CDI provides a custom <br>
implementation of org.jboss.weld.bootstrap.api.Environment, which is <br>
fine. The problem is that Weld currently skips registration only if <br>
org.jboss.weld.bootstrap.api.Environments.SE is used.<br>
<br>
> <br>
> Best regards, Alex<br>
> <br>
> <br>
> Понедельник, 22 мая 2017, 11:51 +03:00 от Martin Kouba<br>
> <<a href="mailto:mkouba@redhat.com">mkouba@redhat.com</a>>:<br>
> <br>
> Ok, now I know what's going on.<br>
> <br>
> The event with payload "Application context initialized." comes<br>
> directly<br>
> from Weld. Whereas the second one java.lang.Object@48813e62 comes from<br>
> PAX CDI [1].<br>
> <br>
> Up to version 2.2 Weld did not fire @Initialized/@Destroyed events for<br>
> @ApplicationScoped for non-web modules. The behavior changed in 2.3 -<br>
> see also WELD-1821 [2].<br>
> <br>
> This explains the events fired twice.<br>
> <br>
> WRT Test bean instance created twice - the problem is that<br>
> @Destroyed(ApplicationScoped.class) event is fired after the actual<br>
> destruction. So if you declare an observer on an @ApplicationScoped<br>
> you're entering the "undefined behavior zone". In Weld, the Test<br>
> bean is<br>
> created again.<br>
> <br>
> I've created WELD-2389 [3] to track this issue.<br>
> <br>
> Thanks,<br>
> <br>
> Martin<br>
> <br>
> [1]<br>
> <a href="https://github.com/ops4j/org.ops4j.pax.cdi/blob/master/pax-cdi-weld/src/main/java/org/ops4j/pax/cdi/weld/impl/WeldCdiContainer.java#L154" target="_blank">https://github.com/ops4j/org.ops4j.pax.cdi/blob/master/pax-cdi-weld/src/main/java/org/ops4j/pax/cdi/weld/impl/WeldCdiContainer.java#L154</a><br>
> <br>
> [2]<br>
> <a href="https://issues.jboss.org/browse/WELD-1821" target="_blank">https://issues.jboss.org/browse/WELD-1821</a><br>
> <br>
> [3]<br>
> <a href="https://issues.jboss.org/browse/WELD-2389" target="_blank">https://issues.jboss.org/browse/WELD-2389</a><br>
> <br>
> <br>
> Dne 22.5.2017 v 09:57 Alex Sviridov napsal(a):<br>
> > Hi Martin<br>
> ><br>
> > Thank you for your answer.<br>
> ><br>
> > 1) I don't inject Test class anywhere.<br>
> > 2) I modified init and destroy methods:<br>
> > public void init(@Observes @Initialized(ApplicationScoped.class)<br>
> > Object init) {<br>
> > System.out.println(init);<br>
> > System.out.println("Test was initialized");<br>
> > }<br>
> ><br>
> > public void destroy(@Observes @Destroyed(ApplicationScoped.class)<br>
> > Object init) {<br>
> > System.out.println(init);<br>
> > System.out.println("Test was destroyed.");<br>
> > }<br>
> ><br>
> > Now on bundle start:<br>
> ><br>
> > Test was created.<br>
> > Application context initialized.<br>
> > Test was initialized<br>
> > java.lang.Object@48813e62<br>
> > Test was initialized<br>
> ><br>
> > Now on bundle stop:<br>
> ><br>
> > java.lang.Object@48813e62<br>
> > Test was destroyed.<br>
> > Test was created.<br>
> > Application context destroyed.<br>
> > Test was destroyed.<br>
> ><br>
> ><br>
> > Понедельник, 22 мая 2017, 10:48 +03:00 от Martin Kouba<br>
> > <<a href="mailto:mkouba@redhat.com">mkouba@redhat.com</a> <mailto:<a href="mailto:mkouba@redhat.com">mkouba@redhat.com</a>>>:<br>
> ><br>
> > Hi Alex,<br>
> ><br>
> > this looks really weird. Could you try to print out the event<br>
> payload,<br>
> > e.g. System.out.println(init)?<br>
> ><br>
> > Also you should be always very careful when using code inside the<br>
> > no-args constructor of a normal-scoped bean -> it will be also<br>
> executed<br>
> > when creating a client proxy. In your case, if you do @Inject<br>
> Test and<br>
> > invoke any method then you will also see "Test was created" printed<br>
> > twice.<br>
> ><br>
> > Martin<br>
> ><br>
> > Dne 22.5.2017 v 08:50 Alex Sviridov napsal(a):<br>
> > > Hi all<br>
> > ><br>
> > > I use pax-cdi -1.0.0.RC2 and weld 2.3.5.Final and this is my test<br>
> > class:<br>
> > ><br>
> > > import javax.enterprise.context.ApplicationScoped;<br>
> > > import javax.enterprise.context.Destroyed;<br>
> > > import javax.enterprise.context.Initialized;<br>
> > > import javax.enterprise.event.Observes;<br>
> > ><br>
> > > @ApplicationScoped<br>
> > > public class Test {<br>
> > ><br>
> > > public Test() {<br>
> > > System.out.println("Test was created.");<br>
> > > }<br>
> > ><br>
> > > public void init(@Observes @Initialized(ApplicationScoped.class)<br>
> > Object<br>
> > > init) {<br>
> > > System.out.println("Test was initialized");<br>
> > > }<br>
> > ><br>
> > > public void destroy(@Observes @Destroyed(ApplicationScoped.class)<br>
> > > Object init) {<br>
> > > System.out.println("Test was destroyed.");<br>
> > > }<br>
> > > }<br>
> > ><br>
> > > When I start test-bundle I see the following output:<br>
> > > Test was created.<br>
> > > Test was initialized<br>
> > > Test was initialized<br>
> > > When I stop test-bundle I see the following output:<br>
> > > Test was destroyed.<br>
> > > Test was created.<br>
> > > Test was destroyed.<br>
> > ><br>
> > > So as result this bean was two times created, two times<br>
> > initialized and two<br>
> > > times destroyed.<br>
> > ><br>
> > > I expected that this bean must be once created, one initialized<br>
> > and once<br>
> > > destroyed.<br>
> > ><br>
> > > Is this a bug that must be reported or my mistake?<br>
> > ><br>
> > > --<br>
> > > Alex Sviridov<br>
> > ><br>
> > ><br>
> > > _______________________________________________<br>
> > > weld-dev mailing list<br>
> > > <a href="mailto:weld-dev@lists.jboss.org">weld-dev@lists.jboss.org</a> <mailto:<a href="mailto:weld-dev@lists.jboss.org">weld-dev@lists.jboss.org</a>><br>
> <mailto:<a href="mailto:weld-dev@lists.jboss.org">weld-dev@lists.jboss.org</a> <mailto:<a href="mailto:weld-dev@lists.jboss.org">weld-dev@lists.jboss.org</a>>><br>
> > > <a href="https://lists.jboss.org/mailman/listinfo/weld-dev" target="_blank">https://lists.jboss.org/mailman/listinfo/weld-dev</a><br>
> > ><br>
> ><br>
> > --<br>
> > Martin Kouba<br>
> > Senior Software Engineer<br>
> > Red Hat, Czech Republic<br>
> ><br>
> ><br>
> ><br>
> > --<br>
> > Alex Sviridov<br>
> <br>
> -- <br>
> Martin Kouba<br>
> Senior Software Engineer<br>
> Red Hat, Czech Republic<br>
> <br>
> <br>
> <br>
> -- <br>
> Alex Sviridov<br>
<br>
-- <br>
Martin Kouba<br>
Senior Software Engineer<br>
Red Hat, Czech Republic<br>
</div>
                <base target="_self" href="https://e.mail.ru/">
        </div>
        
</div>
</div>
</blockquote>
<br>
<br>-- <br>Alex Sviridov<br></BODY></HTML>