1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2025-12-11 07:31:08 +01:00

Improve packet send and result collecting API

Instead of repeating the same pattern, when sending an IQ get/set packet
and collecting the response

PacketFilter filter = new PacketIDFilter(request.getPacketID()),
PacketCollector collector = connection.createPacketCollector(filter);
connection.sendPacket(reg);
IQ result = (IQ)collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
// Stop queuing results
collector.cancel();
if (result == null) {
    throw new XMPPException("No response from server.");
}
else if (result.getType() == IQ.Type.ERROR) {
    throw new XMPPException(result.getError());
}

the API got redesigned, so that the above code block can be replaced
with

Packet result = connection.createPacketCollectorAndSend(request).nextResultOrThrow();
This commit is contained in:
Florian Schmaus 2014-02-18 15:05:19 +01:00
parent e6d5385129
commit 7bd7b3d24c
50 changed files with 333 additions and 1489 deletions

View file

@ -34,7 +34,6 @@ import org.jivesoftware.smack.filter.PacketTypeFilter;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.packet.Packet;
import org.jivesoftware.smack.packet.IQ.Type;
import org.jivesoftware.smack.util.SyncPacketSend;
import org.jivesoftware.smackx.disco.ServiceDiscoveryManager;
import org.jivesoftware.smackx.disco.packet.DiscoverInfo;
import org.jivesoftware.smackx.ping.packet.Ping;
@ -120,7 +119,7 @@ public class PingManager {
Ping ping = new Ping(jid);
Connection connection = weakRefConnection.get();
try {
SyncPacketSend.getReply(connection, ping);
connection.createPacketCollectorAndSend(ping).nextResultOrThrow();
}
catch (XMPPException exc) {
@ -137,7 +136,7 @@ public class PingManager {
* @return true if a reply was received from the entity, false otherwise.
*/
public boolean ping(String jid) {
return ping(jid, SmackConfiguration.getPacketReplyTimeout());
return ping(jid, SmackConfiguration.getDefaultPacketReplyTimeout());
}
/**