mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2025-12-06 13:11: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
|
|
@ -38,10 +38,10 @@ public class PacketCollectorTest
|
|||
}
|
||||
|
||||
// Assert that '0' has rolled off
|
||||
assertEquals("1", collector.nextResult().getPacketID());
|
||||
assertEquals("2", collector.nextResult().getPacketID());
|
||||
assertEquals("3", collector.nextResult().getPacketID());
|
||||
assertEquals("4", collector.nextResult().getPacketID());
|
||||
assertEquals("1", collector.nextResultBlockForever().getPacketID());
|
||||
assertEquals("2", collector.nextResultBlockForever().getPacketID());
|
||||
assertEquals("3", collector.nextResultBlockForever().getPacketID());
|
||||
assertEquals("4", collector.nextResultBlockForever().getPacketID());
|
||||
assertEquals("5", collector.pollResult().getPacketID());
|
||||
assertNull(collector.pollResult());
|
||||
|
||||
|
|
@ -51,10 +51,10 @@ public class PacketCollectorTest
|
|||
collector.processPacket(testPacket);
|
||||
}
|
||||
|
||||
assertEquals("10", collector.nextResult().getPacketID());
|
||||
assertEquals("11", collector.nextResult().getPacketID());
|
||||
assertEquals("12", collector.nextResult().getPacketID());
|
||||
assertEquals("13", collector.nextResult().getPacketID());
|
||||
assertEquals("10", collector.nextResultBlockForever().getPacketID());
|
||||
assertEquals("11", collector.nextResultBlockForever().getPacketID());
|
||||
assertEquals("12", collector.nextResultBlockForever().getPacketID());
|
||||
assertEquals("13", collector.nextResultBlockForever().getPacketID());
|
||||
assertEquals("14", collector.pollResult().getPacketID());
|
||||
assertNull(collector.pollResult());
|
||||
|
||||
|
|
@ -87,7 +87,8 @@ public class PacketCollectorTest
|
|||
catch (InterruptedException e)
|
||||
{
|
||||
}
|
||||
Packet packet = collector.nextResult();
|
||||
@SuppressWarnings("unused")
|
||||
Packet packet = collector.nextResultBlockForever();
|
||||
// System.out.println(Thread.currentThread().getName() + " packet: " + packet);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ public class SmackConfigurationTest {
|
|||
@Test
|
||||
public void testSmackConfiguration() {
|
||||
try {
|
||||
SmackConfiguration.getPacketReplyTimeout();
|
||||
SmackConfiguration.getDefaultPacketReplyTimeout();
|
||||
} catch (Throwable t) {
|
||||
fail("SmackConfiguration threw Throwable");
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue