How to use the ITopicSubscriber in a dashboard panel

214 views
Skip to first unread message

Jan Thielemann

unread,
Apr 7, 2014, 5:15:26 AM4/7/14
to idem...@googlegroups.com
Hey Guys,
i have a dashboard panel to keep track of the users (who is logged in, who is offline, send them broadcast messages).
To keep track of login/logout events, i use a event handler of MSession where i use the IMessageService to publish these events:

private void publishEvent(int createdBy, String topic) {
Map<String, Integer> properties = new HashMap<String, Integer>();
properties.put(topic, new Integer(createdBy));
IMessageService service = Service.locator().locate(IMessageService.class).getService();
if (service != null) {
ITopic<Map<String,Integer>> itopic = service.getTopic(topic);
itopic.publish(properties);
}
}

In my dashboard panel, i implemented the ITopicSubscriber

IMessageService service = Service.locator().locate(IMessageService.class).getService();
if (service != null) {
ITopic<Map<String,Integer>> intopic = service.getTopic(ON_USER_LOGGED_IN_TOPIC);
intopic.subscribe(this);
ITopic<Map<String,Integer>> outtopic = service.getTopic(ON_USER_LOGGED_OUT_TOPIC);
outtopic.subscribe(this);
}

@Override
public void onMessage(Map<String,Integer> message) {
if(message.keySet().contains(ON_USER_LOGGED_IN_TOPIC)){
treeModel.userLoggedIn(message.get(ON_USER_LOGGED_IN_TOPIC));
}else if(message.keySet().contains(ON_USER_LOGGED_OUT_TOPIC))
treeModel.userLoggedOut(message.get(ON_USER_LOGGED_OUT_TOPIC));
}

I can receive the events and read the user id from it but as soon as i try to refresh my tree model, i get the following error:

java.lang.NullPointerException
at org.compiere.util.CLogErrorBuffer.publish(CLogErrorBuffer.java:192)
at java.util.logging.Logger.log(Logger.java:610)
at com.hazelcast.logging.StandardLoggerFactory$StandardLogger.log(StandardLoggerFactory.java:50)
at com.hazelcast.logging.LoggingServiceImpl$DefaultLogger.log(LoggingServiceImpl.java:146)
at com.hazelcast.impl.ListenerManager.callListeners(ListenerManager.java:336)
at com.hazelcast.impl.BaseManager$2.run(BaseManager.java:1382)
at com.hazelcast.impl.executor.ParallelExecutorService$ParallelExecutorImpl$ExecutionSegment.run(ParallelExecutorService.java:212)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:744)
at com.hazelcast.impl.ExecutorThreadFactory$1.run(ExecutorThreadFactory.java:38)

I'm wondering what i am doing wrong. Maybe i didn't get the concept of the message service or the topicsubscriber right and i would really appreciate a hint into the right direction. It would be great if somebody could explain the whole concept to me so that i could write a tutorial in our wiki.





Heng Sin Low

unread,
Apr 7, 2014, 5:50:18 AM4/7/14
to idem...@googlegroups.com
Where is that NPE comes from ( the log is cut off ) ? Perhaps you need to use ServerPushTemplate or AEnv.executeAsyncTask to refresh your model.


--
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/57a1df52-48bb-46c4-869e-b2606dbaedbd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jan Thielemann

unread,
Apr 7, 2014, 5:58:45 AM4/7/14
to idem...@googlegroups.com
Hi Hengsin,
thanks for the answer. The log is not cut of. It is all i get. Maybe you can check it directly. The code can be found here:

How would i use the suggestions you made? My knowledge in zk is still miles away from yours...

Hiep Lq

unread,
Apr 7, 2014, 7:05:37 AM4/7/14
to idem...@googlegroups.com
Hi Jan, I interest with new things.
where's code of 

Jan Thielemann

unread,
Apr 7, 2014, 7:20:49 AM4/7/14
to idem...@googlegroups.com
This piece of code is in the event handler which i use as a replacement for model validator.

Heng Sin Low

unread,
Apr 7, 2014, 7:37:42 AM4/7/14
to idem...@googlegroups.com
Ok, so the root exception is lost due to the NPE at CLogErrorBuffer. Use a try catch block in your onMessage method to get the actual exception and it should be straightforward after we know what it is.


Message has been deleted

Jan Thielemann

unread,
Apr 7, 2014, 8:05:07 AM4/7/14
to idem...@googlegroups.com
org.zkoss.zk.ui.UiException: You cannot access a desktop other than an event listener
at org.zkoss.zk.ui.AbstractComponent.checkDetach(AbstractComponent.java:407)
at org.zkoss.zk.ui.AbstractComponent.checkParentChild(AbstractComponent.java:1073)
at org.zkoss.zk.ui.AbstractComponent.setParent(AbstractComponent.java:966)
at org.zkoss.zul.Treeitem.setParent(Treeitem.java:419)
at org.zkoss.zk.ui.AbstractComponent.detach(AbstractComponent.java:1669)
at org.zkoss.zul.Tree.onTreeDataRemoved(Tree.java:1391)
at org.zkoss.zul.Tree.onTreeDataChange(Tree.java:1340)
at org.zkoss.zul.Tree.access$1200(Tree.java:159)
at org.zkoss.zul.Tree$2.onChange(Tree.java:1465)
at org.zkoss.zul.AbstractTreeModel.fireEvent(AbstractTreeModel.java:108)
at org.zkoss.zul.DefaultTreeNode$TreeNodeChildrenList.remove(DefaultTreeNode.java:278)
at org.zkoss.zul.DefaultTreeNode$TreeNodeChildrenList.remove(DefaultTreeNode.java:226)
at org.zkoss.zul.DefaultTreeNode.remove(DefaultTreeNode.java:185)
at org.evenos.trees.BroadcasterTreeModel.removeNodesRecursivly(BroadcasterTreeModel.java:91)
at org.evenos.trees.BroadcasterTreeModel.refresh(BroadcasterTreeModel.java:77)
at org.evenos.trees.BroadcasterTreeModel.userLoggedIn(BroadcasterTreeModel.java:446)
at org.adempiere.webui.dashboard.DPBroadcaster.onMessage(DPBroadcaster.java:193)
at org.adempiere.webui.dashboard.DPBroadcaster.onMessage(DPBroadcaster.java:1)
at org.idempiere.hazelcast.service.TopicImpl$TopicSubscriberAdapter.onMessage(TopicImpl.java:83)
at com.hazelcast.impl.ListenerManager.callListener(ListenerManager.java:419)
at com.hazelcast.impl.ListenerManager.callListeners(ListenerManager.java:334)

Heng Sin Low

unread,
Apr 7, 2014, 9:14:40 AM4/7/14
to idem...@googlegroups.com
You have to use ServerPushTemplate for that. Execute the model refresh code in the IServerPushCallback.updateUI method. For the desktop reference, I believe your dashboard gadget should have a reference to it. Also, you need to verify that the desktop is still alive ( desktop.isAlive() ).


--
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,
Apr 7, 2014, 9:29:27 AM4/7/14
to idem...@googlegroups.com
Can you give me some additional explaination? I never heard of IServerPushCallback, neither do i know how to use or implement it.

Nicolas Micoud

unread,
Apr 7, 2014, 11:02:08 AM4/7/14
to idem...@googlegroups.com
Hi,


Nicolas

Jan Thielemann

unread,
Apr 8, 2014, 3:03:44 AM4/8/14
to idem...@googlegroups.com
Thank you guys, now it works. :)
Reply all
Reply to author
Forward
0 new messages