1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2024-12-23 04:57:58 +01:00

Add PacketCollector.throwIfCancelled()

to prevent wrong usage of the collector.
This commit is contained in:
Florian Schmaus 2015-01-14 20:14:48 +01:00
parent 106512d8d4
commit 14b03149db

View file

@ -139,6 +139,7 @@ public class PacketCollector {
*/
@SuppressWarnings("unchecked")
public <P extends Packet> P nextResultBlockForever() {
throwIfCancelled();
P res = null;
while (res == null) {
try {
@ -171,6 +172,7 @@ public class PacketCollector {
*/
@SuppressWarnings("unchecked")
public <P extends Packet> P nextResult(long timeout) {
throwIfCancelled();
P res = null;
long remainingWait = timeout;
final long waitStart = System.currentTimeMillis();
@ -243,4 +245,10 @@ public class PacketCollector {
}
}
}
private final void throwIfCancelled() {
if (cancelled) {
throw new IllegalStateException("Packet collector already cancelled");
}
}
}