mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2025-09-10 18:59:41 +02:00
Wait for server response before returning roster.
git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@1867 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
parent
d77787f67c
commit
af4ea681ee
4 changed files with 42 additions and 11 deletions
|
@ -53,8 +53,7 @@
|
|||
package org.jivesoftware.smack;
|
||||
|
||||
import org.jivesoftware.smack.packet.*;
|
||||
import org.jivesoftware.smack.filter.PacketIDFilter;
|
||||
import org.jivesoftware.smack.filter.PacketFilter;
|
||||
import org.jivesoftware.smack.filter.*;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.net.*;
|
||||
|
@ -109,7 +108,7 @@ public class XMPPConnection {
|
|||
private PacketWriter packetWriter;
|
||||
private PacketReader packetReader;
|
||||
|
||||
private Roster roster = null;
|
||||
Roster roster = null;
|
||||
private AccountManager accountManager = null;
|
||||
|
||||
Writer writer;
|
||||
|
@ -330,6 +329,24 @@ public class XMPPConnection {
|
|||
* @return the user's roster, or <tt>null</tt> if the user has not logged in yet.
|
||||
*/
|
||||
public Roster getRoster() {
|
||||
if (roster == null) {
|
||||
return null;
|
||||
}
|
||||
// If this is the first time the user has asked for the roster after calling
|
||||
// login, we want to wait up to 2 seconds for the server to send back the
|
||||
// user's roster. This behavior shields API users from having to worry about the
|
||||
// fact that roster operations are asynchronous, although they'll still have to
|
||||
// listen for changes to the roster. Note: because of this waiting logic, internal
|
||||
// Smack code should be wary about calling the getRoster method, and may need to
|
||||
// access the roster object directly.
|
||||
int elapsed = 0;
|
||||
while (!roster.rosterInitialized && elapsed <= 2000) {
|
||||
try {
|
||||
Thread.sleep(500);
|
||||
}
|
||||
catch (Exception e) { }
|
||||
elapsed += 500;
|
||||
}
|
||||
return roster;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue