/** * Add DiscoverInfo to the database. * * @param nodeVer * The node and verification String (e.g. * "http://psi-im.org#q07IKJEyjvHSyhy//CH0CxmKi8w="). * @param info * DiscoverInfo for the specified node. */ static void addDiscoverInfoByNode(String nodeVer, DiscoverInfo info) { CAPS_CACHE.put(nodeVer, info); if (persistentCache != null) persistentCache.addDiscoverInfoByNodePersistent(nodeVer, info); }
@Override public void presenceUnsubscribed(BareJid address, Presence unsubscribedPresence) { if (friendshipRequestedCache.containsKey(address)) { friendshipDeniedCache.put(address, null); } for (WasUnfriendedListener wasUnfriendedListener : wasUnfriendedListeners) { wasUnfriendedListener.wasUnfriendedListener(address, unsubscribedPresence); } } });
private static void addCapsExtensionInfo(Jid from, CapsExtension capsExtension) { String capsExtensionHash = capsExtension.getHash(); String hashInUppercase = capsExtensionHash.toUpperCase(Locale.US); // SUPPORTED_HASHES uses the format of MessageDigest, which is uppercase, e.g. "SHA-1" instead of "sha-1" if (!SUPPORTED_HASHES.containsKey(hashInUppercase)) return; String hash = capsExtensionHash.toLowerCase(Locale.US); String node = capsExtension.getNode(); String ver = capsExtension.getVer(); JID_TO_NODEVER_CACHE.put(from, new NodeVerHash(node, ver, hash)); }
/** * Retrieve the user presences (a map from resource to {@link Presence}) for a given XMPP entity represented by their bare JID. * * @param entity the entity * @return the user presences */ private synchronized Map<Resourcepart, Presence> getOrCreatePresencesInternal(BareJid entity) { Map<Resourcepart, Presence> entityPresences = getPresencesInternal(entity); if (entityPresences == null) { if (contains(entity)) { entityPresences = new ConcurrentHashMap<>(); presenceMap.put(entity, entityPresences); } else { LruCache<Resourcepart, Presence> nonRosterEntityPresences = new LruCache<>(32); nonRosterPresenceMap.put(entity, nonRosterEntityPresences); entityPresences = nonRosterEntityPresences; } } return entityPresences; }
public void sendFriendshipRequest(BareJid bareJid) throws NotConnectedException, InterruptedException { Presence presence = new Presence(Presence.Type.subscribe); presence.setTo(bareJid); friendshipRequestedCache.put(bareJid, null); connection().sendStanza(presence); }
/** * Retrieve DiscoverInfo for a specific node. * * @param nodeVer * The node name (e.g. * "http://psi-im.org#q07IKJEyjvHSyhy//CH0CxmKi8w="). * @return The corresponding DiscoverInfo or null if none is known. */ public static DiscoverInfo getDiscoveryInfoByNodeVer(String nodeVer) { DiscoverInfo info = CAPS_CACHE.lookup(nodeVer); // If it was not in CAPS_CACHE, try to retrieve the information from persistentCache if (info == null && persistentCache != null) { info = persistentCache.lookup(nodeVer); // Promote the information to CAPS_CACHE if one was found if (info != null) { CAPS_CACHE.put(nodeVer, info); } } // If we were able to retrieve information from one of the caches, copy it before returning if (info != null) info = new DiscoverInfo(info); return info; }
JID_TO_NODEVER_CACHE.put(connection.getUser(), new NodeVerHash(entityNode, currentCapsVersion));
/** * Request BoB data. * * @param to * @param bobHash * @return the BoB data * @throws NotLoggedInException * @throws NoResponseException * @throws XMPPErrorException * @throws NotConnectedException * @throws InterruptedException */ public BoBData requestBoB(Jid to, BoBHash bobHash) throws NotLoggedInException, NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { BoBData bobData = BOB_CACHE.lookup(bobHash); if (bobData != null) { return bobData; } BoBIQ requestBoBIQ = new BoBIQ(bobHash); requestBoBIQ.setType(Type.get); requestBoBIQ.setTo(to); XMPPConnection connection = getAuthenticatedConnectionOrThrow(); BoBIQ responseBoBIQ = connection.createStanzaCollectorAndSend(requestBoBIQ).nextResultOrThrow(); bobData = responseBoBIQ.getBoBData(); BOB_CACHE.put(bobHash, bobData); return bobData; }
public V put(K key, V value, long expirationTime) { ExpireElement<V> eOld = cache.put(key, new ExpireElement<V>(value, expirationTime)); if (eOld == null) { return null; } return eOld.element; }
/** * Put a value in the cahce with the specified expiration time in milliseconds. * * @param key the key of the value. * @param value the value. * @param expirationTime the expiration time in milliseconds. * @return the previous value or {@code null}. */ public V put(K key, V value, long expirationTime) { ExpireElement<V> eOld = cache.put(key, new ExpireElement<V>(value, expirationTime)); if (eOld == null) { return null; } return eOld.element; }
@Override public void presenceUnsubscribed(BareJid address, Presence unsubscribedPresence) { if (friendshipRequestedCache.containsKey(address)) { friendshipDeniedCache.put(address, null); } for (WasUnfriendedListener wasUnfriendedListener : wasUnfriendedListeners) { wasUnfriendedListener.wasUnfriendedListener(address, unsubscribedPresence); } } });
LOCALPART_ESACPE_CACHE.put(localpart, res); return res;
/** * Retrieve the user presences (a map from resource to {@link Presence}) for a given XMPP entity represented by their bare JID. * * @param entity the entity * @return the user presences */ private synchronized Map<Resourcepart, Presence> getOrCreatePresencesInternal(BareJid entity) { Map<Resourcepart, Presence> entityPresences = getPresencesInternal(entity); if (entityPresences == null) { if (contains(entity)) { entityPresences = new ConcurrentHashMap<>(); presenceMap.put(entity, entityPresences); } else { LruCache<Resourcepart, Presence> nonRosterEntityPresences = new LruCache<>(32); nonRosterPresenceMap.put(entity, nonRosterEntityPresences); entityPresences = nonRosterEntityPresences; } } return entityPresences; }
LOCALPART_UNESCAPE_CACHE.put(localpart, res); return res;
public void sendFriendshipRequest(BareJid bareJid) throws NotConnectedException, InterruptedException { Presence presence = new Presence(Presence.Type.subscribe); presence.setTo(bareJid); friendshipRequestedCache.put(bareJid, null); connection().sendStanza(presence); }