I’'m building an application where I need to check the presence of a user synchronously. That is, given an XMPP address (user@server), I need to see if that user is online prior to doing what I need to do with that address.
The only way I can find to check presence is by getting a roster from XMPPConnection.getRoster, adding the user with roster.createEntry(…), and checking the presence using roster.getPresence(…). Unfortunately, createEntry is asynchronous, and the following code will therefore perform erratically:
Roster roster = con.getRoster();
roster.createEntry(address, “user”, null);
So… what should I do? Is there a synchronous way to do this? If not, is there a way to call createEntry and block until it’'s finished? If not… how long should a pause should I insert between lines two and three of the above code? (Yes, the messiness of that solution would make me sad, but it would work.)