Search in sources :

Example 1 with IoTIsFriendResponse

use of org.jivesoftware.smackx.iot.provisioning.element.IoTIsFriendResponse in project Smack by igniterealtime.

the class IoTProvisioningManager method isFriend.

/**
     * As the given provisioning server is the given JID is a friend.
     *
     * @param provisioningServer the provisioning server to ask.
     * @param friendInQuestion the JID to ask about.
     * @return <code>true</code> if the JID is a friend, <code>false</code> otherwise.
     * @throws NoResponseException
     * @throws XMPPErrorException
     * @throws NotConnectedException
     * @throws InterruptedException
     */
public boolean isFriend(Jid provisioningServer, BareJid friendInQuestion) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
    LruCache<BareJid, Void> cache = negativeFriendshipRequestCache.lookup(provisioningServer);
    if (cache != null && cache.containsKey(friendInQuestion)) {
        // We hit a cached negative isFriend response for this provisioning server.
        return false;
    }
    IoTIsFriend iotIsFriend = new IoTIsFriend(friendInQuestion);
    iotIsFriend.setTo(provisioningServer);
    IoTIsFriendResponse response = connection().createStanzaCollectorAndSend(iotIsFriend).nextResultOrThrow();
    assert (response.getJid().equals(friendInQuestion));
    boolean isFriend = response.getIsFriendResult();
    if (!isFriend) {
        // Cache the negative is friend response.
        if (cache == null) {
            cache = new LruCache<>(1024);
            negativeFriendshipRequestCache.put(provisioningServer, cache);
        }
        cache.put(friendInQuestion, null);
    }
    return isFriend;
}
Also used : DomainBareJid(org.jxmpp.jid.DomainBareJid) BareJid(org.jxmpp.jid.BareJid) IoTIsFriend(org.jivesoftware.smackx.iot.provisioning.element.IoTIsFriend) IoTIsFriendResponse(org.jivesoftware.smackx.iot.provisioning.element.IoTIsFriendResponse)

Example 2 with IoTIsFriendResponse

use of org.jivesoftware.smackx.iot.provisioning.element.IoTIsFriendResponse in project Smack by igniterealtime.

the class IoTIsFriendResponseProvider method parse.

@Override
public IoTIsFriendResponse parse(XmlPullParser parser, int initialDepth) throws Exception {
    Jid jid = ParserUtils.getJidAttribute(parser);
    BareJid bareJid = jid.asBareJid();
    boolean result = ParserUtils.getBooleanAttribute(parser, "result");
    return new IoTIsFriendResponse(bareJid, result);
}
Also used : Jid(org.jxmpp.jid.Jid) BareJid(org.jxmpp.jid.BareJid) BareJid(org.jxmpp.jid.BareJid) IoTIsFriendResponse(org.jivesoftware.smackx.iot.provisioning.element.IoTIsFriendResponse)

Aggregations

IoTIsFriendResponse (org.jivesoftware.smackx.iot.provisioning.element.IoTIsFriendResponse)2 BareJid (org.jxmpp.jid.BareJid)2 IoTIsFriend (org.jivesoftware.smackx.iot.provisioning.element.IoTIsFriend)1 DomainBareJid (org.jxmpp.jid.DomainBareJid)1 Jid (org.jxmpp.jid.Jid)1