Proper use of ITopicSubscriber and OSGi Events

44 views
Skip to first unread message

Jan Thielemann

unread,
Jul 23, 2014, 6:19:33 AM7/23/14
to idem...@googlegroups.com
Hello everybody,
I recently created a tutorial on how to use the ServerPushTemplate, IServerPushCallback and ITopicSubscriber (http://wiki.idempiere.org/en/Developing_Plug-Ins_-_ServerPushTemplate,_IServerPushCallback_and_ITopicSubscriber).

Today a coworker found out a bug. If two users log in, they can send each other messages. If one of the users logs out and the other one tries to send him a message, the message is still caught in the onMessage() method from the ITopicSubscriber which results in a NPE thrown by template.executeAsynch(callback) because the desktop is null after the first user logged out.

I already tried to unsubscribe the DashboardPanel in the onPageDetached() method with the following code but it didn't work:
IMessageService service = Service.locator().locate(IMessageService.class).getService();
if (service != null) {
ITopic<Map<String, Integer>> intopic = service.getTopic(ON_USER_LOGGED_IN_TOPIC);
intopic.unsubscribe(this);
}

I wonder what i am doing wrong. What should i do to stop my DashboardPanel from receiving messages?

I saw that in DPRecentItems, there are also some other things i don't use yet: 
  • org.zkoss.zk.ui.util.DesktopCleanup
  • org.osgi.service.event.EventHandler
  • org.osgi.service.event.Event
  • java.lang.ref.WeakReference
  • (custom) TopicSubscriber
Do i need to use all the classes above so that i don't get exceptions from "dead" DashboardPanels? Do i need to use it in the same way it is used in DPRecentItems or are there other ways of doing it?

I hope you can help me.

Jan Thielemann

unread,
Jul 23, 2014, 8:39:12 AM7/23/14
to idem...@googlegroups.com
Found out that if you store the ITopic you subscribe to in an instance variable, unsubscribe works but i can't imagine that thats the intention behind this. Any suggestions or explanations?

Heng Sin Low

unread,
Jul 23, 2014, 9:48:35 AM7/23/14
to idem...@googlegroups.com
1. DesktopCleanup is needed since you don't always get the onPageDetached event ( for e.g, user just close the browser tab )
2. Desktop reference should be keep using WeakReference to prevent memory leakage

It seems DPRecentItems doesn't  unsubscribe from topic so that could be a bug that needs fixing ( Potential performance and memory issue ).


--
You received this message because you are subscribed to the Google Groups "iDempiere" group.
To unsubscribe from this group and stop receiving emails from it, send an email to idempiere+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/idempiere/0237011b-7822-4754-bc0d-a7a916469771%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Heng Sin Low

unread,
Jul 23, 2014, 9:49:10 AM7/23/14
to idem...@googlegroups.com
That's an interesting finding, will take a look when I have time.


--
You received this message because you are subscribed to the Google Groups "iDempiere" group.
To unsubscribe from this group and stop receiving emails from it, send an email to idempiere+...@googlegroups.com.

Jan Thielemann

unread,
Jul 23, 2014, 9:58:50 AM7/23/14
to idem...@googlegroups.com
Hi Hengsin,
please keep in mind that when you call
IMessageService service = Service.locator().locate(IMessageService.class).getService();

it is possible that the BaseActivator will create a new ServiceTracker which results in an new ITopic. So unsubsribing the topic with 
IMessageService service = Service.locator().locate(IMessageService.class).getService();
if (service != null) {
ITopic<Map<String, Integer>> intopic = service.getTopic(ON_USER_LOGGED_IN_TOPIC);
intopic.unsubscribe(this);
}
does not work most of the time.
Reply all
Reply to author
Forward
0 new messages