mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-11-22 20:12:07 +01:00
Use standard stanza listeners in MultiUserChat
Those, relatively new, listeners guarantee that the individual listeners are not invoked in concurrently while preserving the order. Exactly what MultiUserChat previously did with AsyncButOrdered, which is now no longer needed and hence can be removed.
This commit is contained in:
parent
eb4c2c5572
commit
a7a298c5d8
1 changed files with 66 additions and 84 deletions
|
@ -27,7 +27,6 @@ import java.util.concurrent.CopyOnWriteArraySet;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import org.jivesoftware.smack.AsyncButOrdered;
|
|
||||||
import org.jivesoftware.smack.MessageListener;
|
import org.jivesoftware.smack.MessageListener;
|
||||||
import org.jivesoftware.smack.PresenceListener;
|
import org.jivesoftware.smack.PresenceListener;
|
||||||
import org.jivesoftware.smack.SmackException;
|
import org.jivesoftware.smack.SmackException;
|
||||||
|
@ -144,8 +143,6 @@ public class MultiUserChat {
|
||||||
private final StanzaListener presenceListener;
|
private final StanzaListener presenceListener;
|
||||||
private final StanzaListener subjectListener;
|
private final StanzaListener subjectListener;
|
||||||
|
|
||||||
private static final AsyncButOrdered<MultiUserChat> asyncButOrdered = new AsyncButOrdered<>();
|
|
||||||
|
|
||||||
private static final StanzaFilter DECLINE_FILTER = new AndFilter(MessageTypeFilter.NORMAL,
|
private static final StanzaFilter DECLINE_FILTER = new AndFilter(MessageTypeFilter.NORMAL,
|
||||||
new StanzaExtensionFilter(MUCUser.ELEMENT, MUCUser.NAMESPACE));
|
new StanzaExtensionFilter(MUCUser.ELEMENT, MUCUser.NAMESPACE));
|
||||||
private final StanzaListener declinesListener;
|
private final StanzaListener declinesListener;
|
||||||
|
@ -168,15 +165,10 @@ public class MultiUserChat {
|
||||||
public void processStanza(Stanza packet) throws NotConnectedException {
|
public void processStanza(Stanza packet) throws NotConnectedException {
|
||||||
final Message message = (Message) packet;
|
final Message message = (Message) packet;
|
||||||
|
|
||||||
asyncButOrdered.performAsyncButOrdered(MultiUserChat.this, new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
for (MessageListener listener : messageListeners) {
|
for (MessageListener listener : messageListeners) {
|
||||||
listener.processMessage(message);
|
listener.processMessage(message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Create a listener for subject updates.
|
// Create a listener for subject updates.
|
||||||
|
@ -188,16 +180,11 @@ public class MultiUserChat {
|
||||||
// Update the room subject
|
// Update the room subject
|
||||||
subject = msg.getSubject();
|
subject = msg.getSubject();
|
||||||
|
|
||||||
asyncButOrdered.performAsyncButOrdered(MultiUserChat.this, new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
// Fire event for subject updated listeners
|
// Fire event for subject updated listeners
|
||||||
for (SubjectUpdatedListener listener : subjectUpdatedListeners) {
|
for (SubjectUpdatedListener listener : subjectUpdatedListeners) {
|
||||||
listener.subjectUpdated(msg.getSubject(), from);
|
listener.subjectUpdated(msg.getSubject(), from);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Create a listener for all presence updates.
|
// Create a listener for all presence updates.
|
||||||
|
@ -212,9 +199,6 @@ public class MultiUserChat {
|
||||||
final EntityFullJid myRoomJID = myRoomJid;
|
final EntityFullJid myRoomJID = myRoomJid;
|
||||||
final boolean isUserStatusModification = presence.getFrom().equals(myRoomJID);
|
final boolean isUserStatusModification = presence.getFrom().equals(myRoomJID);
|
||||||
|
|
||||||
asyncButOrdered.performAsyncButOrdered(MultiUserChat.this, new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
switch (presence.getType()) {
|
switch (presence.getType()) {
|
||||||
case available:
|
case available:
|
||||||
Presence oldPresence = occupantsMap.put(from, presence);
|
Presence oldPresence = occupantsMap.put(from, presence);
|
||||||
|
@ -271,8 +255,6 @@ public class MultiUserChat {
|
||||||
listener.processPresence(presence);
|
listener.processPresence(presence);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Listens for all messages that include a MUCUser extension and fire the invitation
|
// Listens for all messages that include a MUCUser extension and fire the invitation
|
||||||
|
@ -341,13 +323,13 @@ public class MultiUserChat {
|
||||||
Presence joinPresence = conf.getJoinPresence(this);
|
Presence joinPresence = conf.getJoinPresence(this);
|
||||||
|
|
||||||
// Setup the messageListeners and presenceListeners *before* the join presence is send.
|
// Setup the messageListeners and presenceListeners *before* the join presence is send.
|
||||||
connection.addSyncStanzaListener(messageListener, fromRoomGroupchatFilter);
|
connection.addStanzaListener(messageListener, fromRoomGroupchatFilter);
|
||||||
StanzaFilter presenceFromRoomFilter = new AndFilter(fromRoomFilter,
|
StanzaFilter presenceFromRoomFilter = new AndFilter(fromRoomFilter,
|
||||||
StanzaTypeFilter.PRESENCE,
|
StanzaTypeFilter.PRESENCE,
|
||||||
PossibleFromTypeFilter.ENTITY_FULL_JID);
|
PossibleFromTypeFilter.ENTITY_FULL_JID);
|
||||||
connection.addSyncStanzaListener(presenceListener, presenceFromRoomFilter);
|
connection.addStanzaListener(presenceListener, presenceFromRoomFilter);
|
||||||
// @formatter:off
|
// @formatter:off
|
||||||
connection.addSyncStanzaListener(subjectListener,
|
connection.addStanzaListener(subjectListener,
|
||||||
new AndFilter(fromRoomFilter,
|
new AndFilter(fromRoomFilter,
|
||||||
MessageWithSubjectFilter.INSTANCE,
|
MessageWithSubjectFilter.INSTANCE,
|
||||||
new NotFilter(MessageTypeFilter.ERROR),
|
new NotFilter(MessageTypeFilter.ERROR),
|
||||||
|
@ -357,7 +339,7 @@ public class MultiUserChat {
|
||||||
new NotFilter(MessageWithThreadFilter.INSTANCE))
|
new NotFilter(MessageWithThreadFilter.INSTANCE))
|
||||||
);
|
);
|
||||||
// @formatter:on
|
// @formatter:on
|
||||||
connection.addSyncStanzaListener(declinesListener, new AndFilter(fromRoomFilter, DECLINE_FILTER));
|
connection.addStanzaListener(declinesListener, new AndFilter(fromRoomFilter, DECLINE_FILTER));
|
||||||
connection.addStanzaSendingListener(presenceInterceptor, new AndFilter(ToMatchesFilter.create(room),
|
connection.addStanzaSendingListener(presenceInterceptor, new AndFilter(ToMatchesFilter.create(room),
|
||||||
StanzaTypeFilter.PRESENCE));
|
StanzaTypeFilter.PRESENCE));
|
||||||
messageCollector = connection.createStanzaCollector(fromRoomGroupchatFilter);
|
messageCollector = connection.createStanzaCollector(fromRoomGroupchatFilter);
|
||||||
|
@ -2118,10 +2100,10 @@ public class MultiUserChat {
|
||||||
* connection.
|
* connection.
|
||||||
*/
|
*/
|
||||||
private void removeConnectionCallbacks() {
|
private void removeConnectionCallbacks() {
|
||||||
connection.removeSyncStanzaListener(messageListener);
|
connection.removeStanzaListener(messageListener);
|
||||||
connection.removeSyncStanzaListener(presenceListener);
|
connection.removeStanzaListener(presenceListener);
|
||||||
connection.removeSyncStanzaListener(subjectListener);
|
connection.removeStanzaListener(subjectListener);
|
||||||
connection.removeSyncStanzaListener(declinesListener);
|
connection.removeStanzaListener(declinesListener);
|
||||||
connection.removeStanzaSendingListener(presenceInterceptor);
|
connection.removeStanzaSendingListener(presenceInterceptor);
|
||||||
if (messageCollector != null) {
|
if (messageCollector != null) {
|
||||||
messageCollector.cancel();
|
messageCollector.cancel();
|
||||||
|
|
Loading…
Reference in a new issue