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
1 changed files with 8 additions and 0 deletions

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");
}
}
}