Why plugin unaware of user presence updates


I wrote a plugin that send notifications to users every few minutes. if user is online - starts sending, or user goes offline (or ordered it to stop) - terminate the sending.

but the plugin seems unaware of the user presence updates, it keeps sending once user subscribes to the service.

I guess it probably because that:

  • the plugin responds to user subscription by sending a “subscribed” presence, thus resulting in a “TO” entry on the user’'s roster.

so I modified the code to send a second presence that “subscribe” to the user, so that when user accepts the subscription, his roster entry will show “BOTH” status.

this seems to work for the Psi client, it responds with an notification, and after manual approval, the plugin does what is intended. however, on the Spark client, this seems not effective at all.

please do you have any ideas?

did some debugging and found out that:

  • when a client connects, server will send a ‘‘probe’’ Presence Packet, so actually the plugin can know the specific client in ‘‘available’’ by look at these ‘‘probe’’ packets;

  • but when a client becomes ‘‘unavailable’’, it is still impossible for the plugin to know client’'s unavailability.

please guys give me some hints.

thank you in advance.

I wonder if implementing SessionEventListener could simplify your code and solve your problem.

hi aznidin,

thanks for the tip. but could you give some more detail? cause I don’'t know anything about session and sessionmanagers.

As I understand it, the following are all instances of Session:





A multiplexer groups together several sessions. And SessionManager as the name implies, manages all the sessions.

I’‘m not sure if I could be of much help because I’'m not Java proficient. Perhaps something like:

import org.jivesoftware.wildfire.event.SessionEventDispatcher;
import org.jivesoftware.wildfire.event.SessionEventListener;
... class YourPlugin implements SessionEventListener ... {
     YourPlugin () {
     public boolean isInMyList(JID address) {
          // Check against your subscribers.
     // Implementation of SessionEventListener. Will be (automatically) called
     // by SessionEventDispatcher on events associated with the session
     public void sessionCreated(Session session) {
          if (isInMyList (session.getAddress()) {
               // Do something about it
     public void sessionDestroyed(Session session) {
          if (isInMyList (session.getAddress()) {
               // Remove from notification list
     public void anonymousSessionCreated(Session session) {}
     public void anonymousSessionDestroyed(Session session) {}

Hope that helps.


Crossing out // You might catch a server session here. LOL

Message was edited by: aznidin

hi aznidin,

thank you very much, that really helps.

however, some more questions:

  1. I can use SessionEventDispatcher.addListener(this) without needing to first getting a reference to it? for example, do I need to ‘‘XmppServer.getInstance().getSomething().getSessionEventDispatcher()’’ ?

or, just because the addlistener() is static, so all I do is to call it and it magically doing the right task?

  1. you mean I can capture ANY type of session, even it is a server session. so that works for jabber users from other domains (e.g.: googletalk users from google.com), is that correct?
  1. I think what’'s needed is that your plugin be assigned to the static object defined in SessionEventDispatcher:

private static List();

This is done via SessionEventDispatcher.addListener(). It’'s not magical

  1. Oops, sorry I got it all mixed up. The SessionManager manages all the sessions, but the SessionEventDispatcher dispatches events for local clients only. It’‘s all in SessionManager.java. As if you don’'t know

I’'m confused.

looking at the SessionManager.java and SessionEventDispatcher javadoc, did not find a solution.

back to #2 of previous questions, I mean if some guy from another domain connects to my plugin, which one can actually solve my problem - that is, to know he is online / offline, or rather, ‘‘available’’ / ‘‘unavailable’’?

my mother tongue is not English, so it’'s really difficult for me to figure out the solution thru those javadocs.


Sorry if you’‘re confused. Looking at the source, I couldn’‘t find any session event dispatcher for users from external domains. My guess is that you’'ll have to rely on for such users. Maybe some other people familiar with the source would have a different answer.

English is neither my primary language