powered by Jive Software

getOccupantCount() and getOccupants() Unreliable / Not Working

Hi all,

I know lots of other people have had problems getting these to work, and it seems I am the latest. Both methods on MultiUserChat seem very unreliable, almost like they have race conditions.

Basically, I have registered a participant listener with the MultiUserChat, which calls muc.getOccupants() and muc.getOccupantCount(). The participant listener is getting fired when users join / leave chat rooms, but the getOccupants() and getOccupantCount() methods return very unpredictable / unreliable results. Here’s a list of results I get that seem to be random and cannot be tracked down to any pattern:

  • Sometimes it works if I am the first person to join the room. getOccupantCount returns 1, and and getOccupants() has one user.
  • Sometimes it returns 0 when I am the first person to join the room.
  • Sometimes if another person joins the room. It updates to show the fact that I am in the room, but doesn’t show the second person. Thinking there is only me in the room.
  • Sometimes it almost seems to operate in reverse. A user is shown as being added to the getOccupant() list when they leave the room, and as being removed from the list when they join the room. getOccupantCount() also reflects the incorrect number of users, incrementing when the user leaves the room, and decrementing when the user joins the room.

Thanks for any help in advance.

I have figured out a workaround that avoids this problem. I can use Participant Status listeners and just manage the user list by hand. I don’t have any of these problems when I do this. But I still haven’t been able to figure out why getOccupantCount() and getOccupants() behave so strangely.

I think I may have found the answer. It appears if I use a ParticipantStatusListener, instead of just a ParticipantListener, everything behaves correctly when I call getOccupantCount() or getOccupants(). So, it seems the ParticipantListener fires “too early”, and the occupants have not been updated yet. This would explain the “reverse” behavior I was seeing.

I guess I’m going to mark this as answered. Since using ParticipantStatusListener seems to work. The javadocs are not real clear on which one should be used though and perhaps could use an update.