1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2025-09-09 10:19:41 +02:00

Smack 4.1.3

-----BEGIN PGP SIGNATURE-----
 Version: GnuPG v2
 
 iQF8BAABCgBmBQJVpgWiXxSAAAAAAC4AKGlzc3Vlci1mcHJAbm90YXRpb25zLm9w
 ZW5wZ3AuZmlmdGhob3JzZW1hbi5uZXQxMzU3QjAxODY1QjI1MDNDMTg0NTNEMjA4
 Q0FDMkE5Njc4NTQ4RTM1AAoJEIysKpZ4VI41G1gH+gIw/seXSSY6vYlVkYEFtR+e
 LV/LArN/eN1ZGc+WjN0EysRyqOBqF8HVHuyO7fF67huDRn62s7hufVY//NTctJ5L
 m4TXwaEUvgjdul7vm/dZcNRYr0jcSpDTFWx2egkOXt3qE9AhnpbnaIJ5c3q9VVVD
 aba88c3NS7quxp0hQm1SNEAmt1CCMPom7YkxdIPKWlLj8N5AF1UuSKwckLLYSUlS
 wloBbITb6EjI1IwszhN6e6o3W+7Pz/1zbFjk0CkKUS+TmhHhKil8TonH8Se/9DYD
 1SVHxvZa8LHWsU9G/R1Nhl69K2+GHEUbGmXalFmyPIf5ifhYyNimpx9krXQUuLs=
 =3/cn
 -----END PGP SIGNATURE-----

Merge tag '4.1.3'

Smack 4.1.3
This commit is contained in:
Florian Schmaus 2015-07-15 09:37:46 +02:00
commit 1c716bc1e0
5 changed files with 61 additions and 19 deletions

View file

@ -159,9 +159,16 @@ public final class Roster extends Manager {
*/
private final Object rosterListenersAndEntriesLock = new Object();
// The roster is marked as initialized when at least a single roster packet
// has been received and processed.
private boolean loaded = false;
private enum RosterState {
uninitialized,
loading,
loaded,
}
/**
* The current state of the roster.
*/
private RosterState rosterState = RosterState.uninitialized;
private final PresencePacketListener presencePacketListener = new PresencePacketListener();
@ -338,9 +345,11 @@ public final class Roster extends Manager {
if (rosterStore != null && isRosterVersioningSupported()) {
packet.setVersion(rosterStore.getRosterVersion());
}
rosterState = RosterState.loading;
connection.sendIqWithResponseCallback(packet, new RosterResultListener(), new ExceptionCallback() {
@Override
public void processException(Exception exception) {
rosterState = RosterState.uninitialized;
Level logLevel;
if (exception instanceof NotConnectedException) {
logLevel = Level.FINE;
@ -384,16 +393,15 @@ public final class Roster extends Manager {
return true;
}
boolean waitUntilLoaded() throws InterruptedException {
final XMPPConnection connection = connection();
while (!loaded) {
long waitTime = connection.getPacketReplyTimeout();
long start = System.currentTimeMillis();
protected boolean waitUntilLoaded() throws InterruptedException {
long waitTime = connection().getPacketReplyTimeout();
long start = System.currentTimeMillis();
while (!isLoaded()) {
if (waitTime <= 0) {
break;
}
synchronized (this) {
if (!loaded) {
if (!isLoaded()) {
wait(waitTime);
}
}
@ -411,7 +419,7 @@ public final class Roster extends Manager {
* @since 4.1
*/
public boolean isLoaded() {
return loaded;
return rosterState == RosterState.loaded;
}
/**
@ -1059,7 +1067,7 @@ public final class Roster extends Manager {
}
}
}
loaded = false;
rosterState = RosterState.uninitialized;
}
/**
@ -1270,6 +1278,21 @@ public final class Roster extends Manager {
@Override
public void processPacket(Stanza packet) throws NotConnectedException, InterruptedException {
// 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
// the presence listener may be invoked with a not yet loaded roster.
if (rosterState == RosterState.loading) {
try {
waitUntilLoaded();
}
catch (InterruptedException e) {
LOGGER.log(Level.INFO, "Presence listener was interrupted", e);
}
}
if (!isLoaded()) {
LOGGER.warning("Roster not loaded while processing presence stanza");
}
Presence presence = (Presence) packet;
Jid from = presence.getFrom();
Resourcepart fromResource = Resourcepart.EMPTY;
@ -1409,7 +1432,7 @@ public final class Roster extends Manager {
}
}
loaded = true;
rosterState = RosterState.loaded;
synchronized (Roster.this) {
Roster.this.notifyAll();
}