mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-11-25 21:42: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.Logger;
|
||||
|
||||
import org.jivesoftware.smack.AsyncButOrdered;
|
||||
import org.jivesoftware.smack.MessageListener;
|
||||
import org.jivesoftware.smack.PresenceListener;
|
||||
import org.jivesoftware.smack.SmackException;
|
||||
|
@ -144,8 +143,6 @@ public class MultiUserChat {
|
|||
private final StanzaListener presenceListener;
|
||||
private final StanzaListener subjectListener;
|
||||
|
||||
private static final AsyncButOrdered<MultiUserChat> asyncButOrdered = new AsyncButOrdered<>();
|
||||
|
||||
private static final StanzaFilter DECLINE_FILTER = new AndFilter(MessageTypeFilter.NORMAL,
|
||||
new StanzaExtensionFilter(MUCUser.ELEMENT, MUCUser.NAMESPACE));
|
||||
private final StanzaListener declinesListener;
|
||||
|
@ -168,15 +165,10 @@ public class MultiUserChat {
|
|||
public void processStanza(Stanza packet) throws NotConnectedException {
|
||||
final Message message = (Message) packet;
|
||||
|
||||
asyncButOrdered.performAsyncButOrdered(MultiUserChat.this, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
for (MessageListener listener : messageListeners) {
|
||||
listener.processMessage(message);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
// Create a listener for subject updates.
|
||||
|
@ -188,16 +180,11 @@ public class MultiUserChat {
|
|||
// Update the room subject
|
||||
subject = msg.getSubject();
|
||||
|
||||
asyncButOrdered.performAsyncButOrdered(MultiUserChat.this, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
// Fire event for subject updated listeners
|
||||
for (SubjectUpdatedListener listener : subjectUpdatedListeners) {
|
||||
listener.subjectUpdated(msg.getSubject(), from);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
// Create a listener for all presence updates.
|
||||
|
@ -212,9 +199,6 @@ public class MultiUserChat {
|
|||
final EntityFullJid myRoomJID = myRoomJid;
|
||||
final boolean isUserStatusModification = presence.getFrom().equals(myRoomJID);
|
||||
|
||||
asyncButOrdered.performAsyncButOrdered(MultiUserChat.this, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
switch (presence.getType()) {
|
||||
case available:
|
||||
Presence oldPresence = occupantsMap.put(from, presence);
|
||||
|
@ -271,8 +255,6 @@ public class MultiUserChat {
|
|||
listener.processPresence(presence);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
// 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);
|
||||
|
||||
// Setup the messageListeners and presenceListeners *before* the join presence is send.
|
||||
connection.addSyncStanzaListener(messageListener, fromRoomGroupchatFilter);
|
||||
connection.addStanzaListener(messageListener, fromRoomGroupchatFilter);
|
||||
StanzaFilter presenceFromRoomFilter = new AndFilter(fromRoomFilter,
|
||||
StanzaTypeFilter.PRESENCE,
|
||||
PossibleFromTypeFilter.ENTITY_FULL_JID);
|
||||
connection.addSyncStanzaListener(presenceListener, presenceFromRoomFilter);
|
||||
connection.addStanzaListener(presenceListener, presenceFromRoomFilter);
|
||||
// @formatter:off
|
||||
connection.addSyncStanzaListener(subjectListener,
|
||||
connection.addStanzaListener(subjectListener,
|
||||
new AndFilter(fromRoomFilter,
|
||||
MessageWithSubjectFilter.INSTANCE,
|
||||
new NotFilter(MessageTypeFilter.ERROR),
|
||||
|
@ -357,7 +339,7 @@ public class MultiUserChat {
|
|||
new NotFilter(MessageWithThreadFilter.INSTANCE))
|
||||
);
|
||||
// @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),
|
||||
StanzaTypeFilter.PRESENCE));
|
||||
messageCollector = connection.createStanzaCollector(fromRoomGroupchatFilter);
|
||||
|
@ -2118,10 +2100,10 @@ public class MultiUserChat {
|
|||
* connection.
|
||||
*/
|
||||
private void removeConnectionCallbacks() {
|
||||
connection.removeSyncStanzaListener(messageListener);
|
||||
connection.removeSyncStanzaListener(presenceListener);
|
||||
connection.removeSyncStanzaListener(subjectListener);
|
||||
connection.removeSyncStanzaListener(declinesListener);
|
||||
connection.removeStanzaListener(messageListener);
|
||||
connection.removeStanzaListener(presenceListener);
|
||||
connection.removeStanzaListener(subjectListener);
|
||||
connection.removeStanzaListener(declinesListener);
|
||||
connection.removeStanzaSendingListener(presenceInterceptor);
|
||||
if (messageCollector != null) {
|
||||
messageCollector.cancel();
|
||||
|
|
Loading…
Reference in a new issue