mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-12-22 10:37:59 +01:00
Add PacketCollector.throwIfCancelled()
to prevent wrong usage of the collector.
This commit is contained in:
parent
106512d8d4
commit
14b03149db
1 changed files with 8 additions and 0 deletions
|
@ -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");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue