0

Eventqueue isSubscribed()

asked 2012-01-12 12:30:23 +0800

afxgroup gravatar image afxgroup
126 1

Hi,

Can anyone explain me in which way i can check if i'm already subscribed with a queue? Not in the same page of course. For example:

queueApplication = EventQueues.lookup("testChannel", EventQueues.APPLICATION, true);
queueApplication.subscribe(new EventListener() {
    public void onEvent(Event evt) {
           System.out.println("test");
    }
});

now i change the zul page. but if i reload tha previous page the queue is subscribed again and i get two messages. I want to check if i'm already registered to this queue before subscribe. I've seen that there is an isSubscribed() method but if i change the page i loose also the eventual class object i declare as EventListener class implementation.

Thank you

delete flag offensive retag edit

2 Replies

Sort by ยป oldest newest

answered 2012-01-13 08:59:18 +0800

afxgroup gravatar image afxgroup
126 1

I cannot use a DESKTOP scope since i get the messages from another server using a servlet and i must dispatch them to all people connected to that server. So the only way to push messages to everyone is to use an APPLICATION scope. In the meanwhile i've resolved it using a desktop attribute that i put to tru when i'm already connected.
The best thing was to unsubscribe the channel on page detach (or on window exit/unload not close since i have no close button) but in the documentation i've find nothing about the onPageDetached present on Page component nor an example of window onExit (if exists..) event to use with window..

link publish delete flag offensive edit

answered 2012-01-13 07:47:19 +0800

gganassin gravatar image gganassin flag of Luxembourg
540 6
http://www.hybris.com/

You are registering your listener in the APPLICATION scope... and since you have no reference to this instance of EventListener... you wont be able to unsubscribe anymore.
If you want that your listener is trashed when you refresh the page with your browser... you need to get your queue with a DESKTOP scope.

EventQueue basically is not unregistering listeners unless the scope where they are attached to is expired.

This caused some memory leaking to me in the past, when i was using EventQueues with a GenericForwardComposer and even if the window was closed... its listener (the composer) was still registered: since the queue is not exposing you the subscribed listeners i was forced to store by myself a map of who-is-subscribed-where in order to manage properly the spring cleaning ;D

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2012-01-12 12:30:23 +0800

Seen: 181 times

Last updated: Jan 13 '12

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More