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;
}
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);
}
Aggregations