1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2024-11-22 22:32:06 +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") @SuppressWarnings("unchecked")
public <P extends Packet> P nextResultBlockForever() { public <P extends Packet> P nextResultBlockForever() {
throwIfCancelled();
P res = null; P res = null;
while (res == null) { while (res == null) {
try { try {
@ -171,6 +172,7 @@ public class PacketCollector {
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public <P extends Packet> P nextResult(long timeout) { public <P extends Packet> P nextResult(long timeout) {
throwIfCancelled();
P res = null; P res = null;
long remainingWait = timeout; long remainingWait = timeout;
final long waitStart = System.currentTimeMillis(); 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");
}
}
} }