Can ItemEventListener be improved?

Current scenario :

If have 100 pubsub nodes and i want item chnages from them i have to do

LeafNode leafNode = pubSubManager.getNode(“NODENAME”);

leafNode.addItemEventListener(new myItemListener());

so that it can listen to changes from all 100 nodes.

If I don’t do above 2 statments server does send me broadcast message item event ab the item changes but I cannot get as the listener is not added.

Instead of creating

ConcurrentHashMap<ItemEventListener, PacketListener> itemEventToListenerMap = new ConcurrentHashMap<ItemEventListener, PacketListener>();

can we improve it to have a common packet listener for all the message type with itemevent ?

This will save node retrieval for 100 nodes and ram memory for HashMap with 100 nodes ?

Thanks

Jeet

leafNode.addItemEventListener(new myItemListener());
You should think about if it’s a good idea to create a new ItemListener for every (leaf) Node. Instead you could simply re-use the same listener for every node.

If you look at Node (SMACK-NIGHTLY-JOB1 4.1.0-alpha6-SNAPSHOT API) and click on the method name, you will see the source of the method: Source code You will find that Smack’s PubSub API simply uses the XMPPConnection API provided by smack-core to install the listener. If you don’t need a event listener per node, then you could install a PacketListener for every PubSub stanza with the event extension (similar to what EventContentFilter does).

1 Like

Thanks Flow

Will try to write one.