1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2024-11-29 17:52:06 +01:00

Make PacketCollector handle InterruptedException

Fixes SMACK-602
This commit is contained in:
Florian Schmaus 2014-08-29 18:06:22 +02:00
parent b5b134f569
commit 72557dd354

View file

@ -19,6 +19,8 @@ package org.jivesoftware.smack;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.jivesoftware.smack.SmackException.NoResponseException;
import org.jivesoftware.smack.XMPPException.XMPPErrorException;
@ -42,6 +44,8 @@ import org.jivesoftware.smack.packet.XMPPError;
*/
public class PacketCollector {
private static final Logger LOGGER = Logger.getLogger(PacketCollector.class.getName());
private PacketFilter packetFilter;
private ArrayBlockingQueue<Packet> resultQueue;
private XMPPConnection connection;
@ -114,12 +118,16 @@ public class PacketCollector {
* @return the next available packet.
*/
public Packet nextResultBlockForever() {
Packet res = null;
while (res == null) {
try {
return resultQueue.take();
res = resultQueue.take();
} catch (InterruptedException e) {
LOGGER.log(Level.FINE,
"nextResultBlockForever was interrupted", e);
}
catch (InterruptedException e) {
throw new RuntimeException(e);
}
return res;
}
/**
@ -139,13 +147,19 @@ public class PacketCollector {
*
* @return the next available packet.
*/
public Packet nextResult(long timeout) {
public Packet nextResult(final long timeout) {
Packet res = null;
long remainingWait = timeout;
final long waitStart = System.currentTimeMillis();
while (res == null && remainingWait > 0) {
try {
return resultQueue.poll(timeout, TimeUnit.MILLISECONDS);
res = resultQueue.poll(remainingWait, TimeUnit.MILLISECONDS);
remainingWait = timeout - (System.currentTimeMillis() - waitStart);
} catch (InterruptedException e) {
LOGGER.log(Level.FINE, "nextResult was interrupted", e);
}
catch (InterruptedException e) {
throw new RuntimeException(e);
}
return res;
}
/**