mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-11-26 05:52:06 +01:00
Make PacketCollector handle InterruptedException
Fixes SMACK-602
This commit is contained in:
parent
b5b134f569
commit
72557dd354
1 changed files with 26 additions and 12 deletions
|
@ -19,6 +19,8 @@ package org.jivesoftware.smack;
|
||||||
|
|
||||||
import java.util.concurrent.ArrayBlockingQueue;
|
import java.util.concurrent.ArrayBlockingQueue;
|
||||||
import java.util.concurrent.TimeUnit;
|
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.SmackException.NoResponseException;
|
||||||
import org.jivesoftware.smack.XMPPException.XMPPErrorException;
|
import org.jivesoftware.smack.XMPPException.XMPPErrorException;
|
||||||
|
@ -42,6 +44,8 @@ import org.jivesoftware.smack.packet.XMPPError;
|
||||||
*/
|
*/
|
||||||
public class PacketCollector {
|
public class PacketCollector {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = Logger.getLogger(PacketCollector.class.getName());
|
||||||
|
|
||||||
private PacketFilter packetFilter;
|
private PacketFilter packetFilter;
|
||||||
private ArrayBlockingQueue<Packet> resultQueue;
|
private ArrayBlockingQueue<Packet> resultQueue;
|
||||||
private XMPPConnection connection;
|
private XMPPConnection connection;
|
||||||
|
@ -114,12 +118,16 @@ public class PacketCollector {
|
||||||
* @return the next available packet.
|
* @return the next available packet.
|
||||||
*/
|
*/
|
||||||
public Packet nextResultBlockForever() {
|
public Packet nextResultBlockForever() {
|
||||||
try {
|
Packet res = null;
|
||||||
return resultQueue.take();
|
while (res == null) {
|
||||||
}
|
try {
|
||||||
catch (InterruptedException e) {
|
res = resultQueue.take();
|
||||||
throw new RuntimeException(e);
|
} catch (InterruptedException e) {
|
||||||
|
LOGGER.log(Level.FINE,
|
||||||
|
"nextResultBlockForever was interrupted", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -139,13 +147,19 @@ public class PacketCollector {
|
||||||
*
|
*
|
||||||
* @return the next available packet.
|
* @return the next available packet.
|
||||||
*/
|
*/
|
||||||
public Packet nextResult(long timeout) {
|
public Packet nextResult(final long timeout) {
|
||||||
try {
|
Packet res = null;
|
||||||
return resultQueue.poll(timeout, TimeUnit.MILLISECONDS);
|
long remainingWait = timeout;
|
||||||
}
|
final long waitStart = System.currentTimeMillis();
|
||||||
catch (InterruptedException e) {
|
while (res == null && remainingWait > 0) {
|
||||||
throw new RuntimeException(e);
|
try {
|
||||||
}
|
res = resultQueue.poll(remainingWait, TimeUnit.MILLISECONDS);
|
||||||
|
remainingWait = timeout - (System.currentTimeMillis() - waitStart);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
LOGGER.log(Level.FINE, "nextResult was interrupted", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue