mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2024-11-22 14:22:05 +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")
|
@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");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue