Mark exceptions in packet transports as certain failures when it is not the last packet for the message

This commit is contained in:
Bart Sopers 2019-12-07 15:21:16 +01:00
parent 3bbf3a1104
commit 321f5eec3c

View file

@ -155,17 +155,33 @@ public class OmnipodCommunicationService extends RileyLinkCommunicationManager {
PacketType packetType = firstPacket ? PacketType.PDM : PacketType.CON;
OmnipodPacket packet = new OmnipodPacket(packetAddress, packetType, podState.getPacketNumber(), encodedMessage);
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);
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 {
// We actually ignore previous (ack) responses if it was not last packet to send
response = exchangePackets(podState, packet);
} catch (OmnipodException ex) {
throw 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) {