mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-11-26 14:02:06 +01:00
Fix Roster.waitUntilLoaded and make it interruptable
waitTime and start need to be initialized outside of the while body.
This commit is contained in:
parent
3bb06b8429
commit
0555297a6e
1 changed files with 16 additions and 15 deletions
|
@ -303,9 +303,10 @@ public class Roster extends Manager {
|
||||||
*
|
*
|
||||||
* @throws NotLoggedInException
|
* @throws NotLoggedInException
|
||||||
* @throws NotConnectedException
|
* @throws NotConnectedException
|
||||||
|
* @throws InterruptedException
|
||||||
* @since 4.1
|
* @since 4.1
|
||||||
*/
|
*/
|
||||||
public void reloadAndWait() throws NotLoggedInException, NotConnectedException {
|
public void reloadAndWait() throws NotLoggedInException, NotConnectedException, InterruptedException {
|
||||||
reload();
|
reload();
|
||||||
waitUntilLoaded();
|
waitUntilLoaded();
|
||||||
}
|
}
|
||||||
|
@ -329,25 +330,18 @@ public class Roster extends Manager {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected boolean waitUntilLoaded() {
|
protected boolean waitUntilLoaded() throws InterruptedException {
|
||||||
final XMPPConnection connection = connection();
|
long waitTime = connection().getPacketReplyTimeout();
|
||||||
|
long start = System.currentTimeMillis();
|
||||||
while (!loaded) {
|
while (!loaded) {
|
||||||
long waitTime = connection.getPacketReplyTimeout();
|
|
||||||
long start = System.currentTimeMillis();
|
|
||||||
if (waitTime <= 0) {
|
if (waitTime <= 0) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
try {
|
synchronized (this) {
|
||||||
synchronized (this) {
|
if (!loaded) {
|
||||||
if (!loaded) {
|
wait(waitTime);
|
||||||
wait(waitTime);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (InterruptedException e) {
|
|
||||||
LOGGER.log(Level.FINE, "interrupted", e);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
long now = System.currentTimeMillis();
|
long now = System.currentTimeMillis();
|
||||||
waitTime -= now - start;
|
waitTime -= now - start;
|
||||||
start = now;
|
start = now;
|
||||||
|
@ -1183,7 +1177,14 @@ public class Roster extends Manager {
|
||||||
// Try to ensure that the roster is loaded when processing presence stanzas. While the
|
// Try to ensure that the roster is loaded when processing presence stanzas. While the
|
||||||
// presence listener is synchronous, the roster result listener is not, which means that
|
// presence listener is synchronous, the roster result listener is not, which means that
|
||||||
// the presence listener may be invoked with a not yet loaded roster.
|
// the presence listener may be invoked with a not yet loaded roster.
|
||||||
boolean loaded = waitUntilLoaded();
|
boolean loaded;
|
||||||
|
try {
|
||||||
|
loaded = waitUntilLoaded();
|
||||||
|
}
|
||||||
|
catch (InterruptedException e) {
|
||||||
|
LOGGER.log(Level.INFO, "Presence listener was interrupted", e);
|
||||||
|
loaded = Roster.this.loaded;
|
||||||
|
}
|
||||||
if (loaded) {
|
if (loaded) {
|
||||||
LOGGER.warning("Roster not loaded while processing presence stanza");
|
LOGGER.warning("Roster not loaded while processing presence stanza");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue