mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2024-11-22 14:22:05 +01:00
[muc] Make providesMucService() use the KNOWN_MUC_SERVICES cache
This reduces the number of disco#info queries on MUC join in some situations.
This commit is contained in:
parent
f1319d1c8b
commit
8e337d7810
2 changed files with 16 additions and 12 deletions
|
@ -88,7 +88,6 @@ import org.jxmpp.jid.EntityJid;
|
||||||
import org.jxmpp.jid.Jid;
|
import org.jxmpp.jid.Jid;
|
||||||
import org.jxmpp.jid.impl.JidCreate;
|
import org.jxmpp.jid.impl.JidCreate;
|
||||||
import org.jxmpp.jid.parts.Resourcepart;
|
import org.jxmpp.jid.parts.Resourcepart;
|
||||||
import org.jxmpp.util.cache.ExpirationCache;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A MultiUserChat room (XEP-45), created with {@link MultiUserChatManager#getMultiUserChat(EntityBareJid)}.
|
* A MultiUserChat room (XEP-45), created with {@link MultiUserChatManager#getMultiUserChat(EntityBareJid)}.
|
||||||
|
@ -112,9 +111,6 @@ import org.jxmpp.util.cache.ExpirationCache;
|
||||||
public class MultiUserChat {
|
public class MultiUserChat {
|
||||||
private static final Logger LOGGER = Logger.getLogger(MultiUserChat.class.getName());
|
private static final Logger LOGGER = Logger.getLogger(MultiUserChat.class.getName());
|
||||||
|
|
||||||
private static final ExpirationCache<DomainBareJid, Void> KNOWN_MUC_SERVICES = new ExpirationCache<>(
|
|
||||||
100, 1000 * 60 * 60 * 24);
|
|
||||||
|
|
||||||
private final XMPPConnection connection;
|
private final XMPPConnection connection;
|
||||||
private final EntityBareJid room;
|
private final EntityBareJid room;
|
||||||
private final MultiUserChatManager multiUserChatManager;
|
private final MultiUserChatManager multiUserChatManager;
|
||||||
|
@ -340,12 +336,8 @@ public class MultiUserChat {
|
||||||
private Presence enter(MucEnterConfiguration conf) throws NotConnectedException, NoResponseException,
|
private Presence enter(MucEnterConfiguration conf) throws NotConnectedException, NoResponseException,
|
||||||
XMPPErrorException, InterruptedException, NotAMucServiceException {
|
XMPPErrorException, InterruptedException, NotAMucServiceException {
|
||||||
final DomainBareJid mucService = room.asDomainBareJid();
|
final DomainBareJid mucService = room.asDomainBareJid();
|
||||||
if (!KNOWN_MUC_SERVICES.containsKey(mucService)) {
|
if (!multiUserChatManager.providesMucService(mucService)) {
|
||||||
if (multiUserChatManager.providesMucService(mucService)) {
|
throw new NotAMucServiceException(this);
|
||||||
KNOWN_MUC_SERVICES.put(mucService, null);
|
|
||||||
} else {
|
|
||||||
throw new NotAMucServiceException(this);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// We enter a room by sending a presence packet where the "to"
|
// We enter a room by sending a presence packet where the "to"
|
||||||
// field is in the form "roomName@service/nickname"
|
// field is in the form "roomName@service/nickname"
|
||||||
|
|
|
@ -64,6 +64,7 @@ import org.jxmpp.jid.EntityFullJid;
|
||||||
import org.jxmpp.jid.EntityJid;
|
import org.jxmpp.jid.EntityJid;
|
||||||
import org.jxmpp.jid.Jid;
|
import org.jxmpp.jid.Jid;
|
||||||
import org.jxmpp.jid.parts.Resourcepart;
|
import org.jxmpp.jid.parts.Resourcepart;
|
||||||
|
import org.jxmpp.util.cache.ExpirationCache;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A manager for Multi-User Chat rooms.
|
* A manager for Multi-User Chat rooms.
|
||||||
|
@ -136,6 +137,9 @@ public final class MultiUserChatManager extends Manager {
|
||||||
private static final StanzaFilter INVITATION_FILTER = new AndFilter(StanzaTypeFilter.MESSAGE, new StanzaExtensionFilter(new MUCUser()),
|
private static final StanzaFilter INVITATION_FILTER = new AndFilter(StanzaTypeFilter.MESSAGE, new StanzaExtensionFilter(new MUCUser()),
|
||||||
new NotFilter(MessageTypeFilter.ERROR));
|
new NotFilter(MessageTypeFilter.ERROR));
|
||||||
|
|
||||||
|
private static final ExpirationCache<DomainBareJid, Void> KNOWN_MUC_SERVICES = new ExpirationCache<>(
|
||||||
|
100, 1000 * 60 * 60 * 24);
|
||||||
|
|
||||||
private final Set<InvitationListener> invitationsListeners = new CopyOnWriteArraySet<InvitationListener>();
|
private final Set<InvitationListener> invitationsListeners = new CopyOnWriteArraySet<InvitationListener>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -392,8 +396,16 @@ public final class MultiUserChatManager extends Manager {
|
||||||
*/
|
*/
|
||||||
public boolean providesMucService(DomainBareJid domainBareJid) throws NoResponseException,
|
public boolean providesMucService(DomainBareJid domainBareJid) throws NoResponseException,
|
||||||
XMPPErrorException, NotConnectedException, InterruptedException {
|
XMPPErrorException, NotConnectedException, InterruptedException {
|
||||||
return serviceDiscoveryManager.supportsFeature(domainBareJid,
|
boolean contains = KNOWN_MUC_SERVICES.containsKey(domainBareJid);
|
||||||
MUCInitialPresence.NAMESPACE);
|
if (!contains) {
|
||||||
|
if (serviceDiscoveryManager.supportsFeature(domainBareJid,
|
||||||
|
MUCInitialPresence.NAMESPACE)) {
|
||||||
|
KNOWN_MUC_SERVICES.put(domainBareJid, null);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return contains;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue