mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2025-12-13 08: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:
parent
e6d5385129
commit
7bd7b3d24c
50 changed files with 333 additions and 1489 deletions
|
|
@ -19,13 +19,10 @@ package org.jivesoftware.smackx.iqlast;
|
|||
|
||||
import org.jivesoftware.smack.Connection;
|
||||
import org.jivesoftware.smack.ConnectionCreationListener;
|
||||
import org.jivesoftware.smack.PacketCollector;
|
||||
import org.jivesoftware.smack.PacketListener;
|
||||
import org.jivesoftware.smack.SmackConfiguration;
|
||||
import org.jivesoftware.smack.XMPPException;
|
||||
import org.jivesoftware.smack.filter.AndFilter;
|
||||
import org.jivesoftware.smack.filter.IQTypeFilter;
|
||||
import org.jivesoftware.smack.filter.PacketIDFilter;
|
||||
import org.jivesoftware.smack.filter.PacketTypeFilter;
|
||||
import org.jivesoftware.smack.packet.IQ;
|
||||
import org.jivesoftware.smack.packet.Message;
|
||||
|
|
@ -199,19 +196,7 @@ public class LastActivityManager {
|
|||
LastActivity activity = new LastActivity();
|
||||
activity.setTo(jid);
|
||||
|
||||
PacketCollector collector = con.createPacketCollector(new PacketIDFilter(activity.getPacketID()));
|
||||
con.sendPacket(activity);
|
||||
|
||||
LastActivity response = (LastActivity) collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
|
||||
|
||||
// Cancel the collector.
|
||||
collector.cancel();
|
||||
if (response == null) {
|
||||
throw new XMPPException("No response from server on status set.");
|
||||
}
|
||||
if (response.getError() != null) {
|
||||
throw new XMPPException(response.getError());
|
||||
}
|
||||
LastActivity response = (LastActivity) con.createPacketCollectorAndSend(activity).nextResultOrThrow();
|
||||
return response;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -19,11 +19,8 @@ package org.jivesoftware.smackx.iqlast.packet;
|
|||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.jivesoftware.smack.PacketCollector;
|
||||
import org.jivesoftware.smack.SmackConfiguration;
|
||||
import org.jivesoftware.smack.Connection;
|
||||
import org.jivesoftware.smack.XMPPException;
|
||||
import org.jivesoftware.smack.filter.PacketIDFilter;
|
||||
import org.jivesoftware.smack.packet.IQ;
|
||||
import org.jivesoftware.smack.provider.IQProvider;
|
||||
import org.jivesoftware.smack.util.StringUtils;
|
||||
|
|
@ -143,19 +140,7 @@ public class LastActivity extends IQ {
|
|||
jid = StringUtils.parseBareAddress(jid);
|
||||
activity.setTo(jid);
|
||||
|
||||
PacketCollector collector = con.createPacketCollector(new PacketIDFilter(activity.getPacketID()));
|
||||
con.sendPacket(activity);
|
||||
|
||||
LastActivity response = (LastActivity) collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
|
||||
|
||||
// Cancel the collector.
|
||||
collector.cancel();
|
||||
if (response == null) {
|
||||
throw new XMPPException("No response from server on status set.");
|
||||
}
|
||||
if (response.getError() != null) {
|
||||
throw new XMPPException(response.getError());
|
||||
}
|
||||
LastActivity response = (LastActivity) con.createPacketCollectorAndSend(activity).nextResultOrThrow();
|
||||
return response;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue