-
FEATURED COMPONENTS
First time here? Check out the FAQ!
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
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
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..
Asked: 2012-01-12 12:30:23 +0800
Seen: 181 times
Last updated: Jan 13 '12