tomee-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Romain Manni-Bucau <rmannibu...@gmail.com>
Subject Re: CDI @Observes ApplicationScoped.class
Date Mon, 29 May 2017 09:01:50 GMT
Just tested with tomee embedded this listener:

@ApplicationScoped
public static class Listener {
    public void start(@javax.enterprise.event.Observes
@Initialized(ApplicationScoped.class) Object start) {
        log(start);
    }
    public void end(@javax.enterprise.event.Observes
@Destroyed(ApplicationScoped.class) Object end) {
        log(end);
    }

    private void log(final Object event) {
        System.out.println();
        System.out.println(this);
        System.out.println(System.identityHashCode(this));
        System.out.println(event);
        System.out.println(System.identityHashCode(event));
        System.out.println();
    }
}


And got:

org.apache.tomee.embedded.ClasspathAsWebappTest$Listener@21c747a
35419258
org.apache.catalina.core.ApplicationContextFacade@77d4ac52
2010426450

org.apache.tomee.embedded.ClasspathAsWebappTest$Listener@1913053c
420676924
org.apache.catalina.core.ApplicationContextFacade@77d4ac52
2010426450

so looks good


Romain Manni-Bucau
@rmannibucau <https://twitter.com/rmannibucau> |  Blog
<https://blog-rmannibucau.rhcloud.com> | Old Blog
<http://rmannibucau.wordpress.com> | Github <https://github.com/rmannibucau> |
LinkedIn <https://www.linkedin.com/in/rmannibucau> | JavaEE Factory
<https://javaeefactory-rmannibucau.rhcloud.com>

2017-05-29 10:26 GMT+02:00 tonywestonuk <tonyw@totspics.com>:

>
> MyService is an @ApplicationScoped bean
>
> And, yet the identity hashcodes change between the init, and destroy
> methods.
>
> Which means, I don't have access to the same instance variables in destory,
> that I constructed in the init.
>
> This is the problem.
>
>
> In my specific case, I am creating a UDP socket in init, storing it as an
> instance variable. And want to close it in destroy. However, the destroy
> method cant access the socket - crashes with null pointer.  I cant
> hot-redeploy as the UDP socket remains open. :-(
>
>
>
>
>
> --
> View this message in context: http://tomee-openejb.979440.
> n4.nabble.com/CDI-Observes-ApplicationScoped-class-tp4681766p4681768.html
> Sent from the TomEE Users mailing list archive at Nabble.com.
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message