Search code examples
apache-flexblazeds

Pushing data from java to flex only if there are subscribed consumers


I've read the following post about how to push data from BlazeDS without recieve message from Flex client?. I did not posted on that thread because is old.

I've implemented such mechanism and it seems to work well. The only thing that I did not managed to do is to stop the thread, if the client is closed. My hunch is that the client is closed, but the consumer is not unsubscribed, unless the method unsubscribe() is not called and I would say, that this is a normal behavior. The problem is that if I want to call the unsubscribe method when the client (in my case a browser) is closed, I did not find such handlers (e.g onExiting, dispose...) in flex web, only for air applications. I'm developing my application using Flex 3.6 and BlazeDS 3.2.0. Thanks.


Solution

  • There is no default handle for that in flex.

    However, what you could try is the following:

    1. Hook into the javaScript onBeforeUnload method => JavaScript + onbeforeunload
    2. In this javascript method, call a Flex function via the ExternalInterface API
    3. In your Flex app unsubscribe

    Cheers