Mark exceptions in packet transports as certain failures when it is not the last packet for the message
This commit is contained in:
parent
3bbf3a1104
commit
321f5eec3c
1 changed files with 21 additions and 5 deletions
|
@ -155,17 +155,33 @@ public class OmnipodCommunicationService extends RileyLinkCommunicationManager {
|
||||||
PacketType packetType = firstPacket ? PacketType.PDM : PacketType.CON;
|
PacketType packetType = firstPacket ? PacketType.PDM : PacketType.CON;
|
||||||
OmnipodPacket packet = new OmnipodPacket(packetAddress, packetType, podState.getPacketNumber(), encodedMessage);
|
OmnipodPacket packet = new OmnipodPacket(packetAddress, packetType, podState.getPacketNumber(), encodedMessage);
|
||||||
byte[] encodedMessageInPacket = packet.getEncodedMessage();
|
byte[] encodedMessageInPacket = packet.getEncodedMessage();
|
||||||
|
|
||||||
// getting the data remaining to be sent
|
// getting the data remaining to be sent
|
||||||
encodedMessage = ByteUtil.substring(encodedMessage, encodedMessageInPacket.length, encodedMessage.length - encodedMessageInPacket.length);
|
encodedMessage = ByteUtil.substring(encodedMessage, encodedMessageInPacket.length, encodedMessage.length - encodedMessageInPacket.length);
|
||||||
firstPacket = false;
|
firstPacket = false;
|
||||||
|
|
||||||
|
// If this is not the last packet, the message wasn't fully sent,
|
||||||
|
// so it's impossible for the pod to have received the message
|
||||||
|
boolean isCertainFailure = encodedMessage.length > 0;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
// We actually ignore previous (ack) responses if it was not last packet to send
|
||||||
response = exchangePackets(podState, packet);
|
response = exchangePackets(podState, packet);
|
||||||
} catch (OmnipodException ex) {
|
|
||||||
throw ex;
|
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
throw new CommunicationException(CommunicationException.Type.UNEXPECTED_EXCEPTION, ex);
|
OmnipodException newException;
|
||||||
|
if (ex instanceof OmnipodException) {
|
||||||
|
newException = (OmnipodException) ex;
|
||||||
|
} else {
|
||||||
|
newException = new CommunicationException(CommunicationException.Type.UNEXPECTED_EXCEPTION, ex);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isLoggingEnabled()) {
|
||||||
|
LOG.debug("Caught exception in transportMessages. Setting certainFailure to {} because encodedMessage.length={}", isCertainFailure, encodedMessage.length);
|
||||||
|
}
|
||||||
|
newException.setCertainFailure(isCertainFailure);
|
||||||
|
|
||||||
|
throw newException;
|
||||||
}
|
}
|
||||||
//We actually ignore (ack) responses if it is not last packet to send
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (response.getPacketType() == PacketType.ACK) {
|
if (response.getPacketType() == PacketType.ACK) {
|
||||||
|
|
Loading…
Reference in a new issue