long startTime = System.currentTimeMillis();
boolean hasMessages = true;
//Take a messge from the storage and check whether we can send it.
do {
RMMessageContext rmMessageContext = storageManager.getNextMessageToSend();
if (rmMessageContext == null) {
hasMessages = false;
} else {
long inactivityTimeout = PolicyLoader.getInstance().getInactivityTimeout();
long retransmissionInterval = PolicyLoader.getInstance()
.getBaseRetransmissionInterval();
if (rmMessageContext.getFristProcessedTime() == 0)
rmMessageContext.setFristProcessedTime(System.currentTimeMillis());
if ((System.currentTimeMillis() - rmMessageContext.getFristProcessedTime()) >
inactivityTimeout) {
log.error("Inactivity Time Out Reached for the message with <wsa:MessageID> " +
rmMessageContext.getMessageID());
//Need to clear the storage only for this sequece.
// storageManager.clearStorage();
} else if (rmMessageContext.getRetransmissionTime() <
(System.currentTimeMillis() - rmMessageContext.getLastPrecessedTime())) {
try {
rmMessageContext.setLastPrecessedTime(System.currentTimeMillis());
if (PolicyLoader.getInstance().getExponentialBackoff() != null) {
long newRtTime = ((long) Math.pow(retransmissionInterval / 1000,
rmMessageContext.getReTransmissionCount())) * 1000;
rmMessageContext.setRetransmissionTime(newRtTime);
} else {
//Let's do Binary Back Off
long rtTime = rmMessageContext.getRetransmissionTime();
rmMessageContext.setRetransmissionTime(2 * rtTime);
}
sendMessage(rmMessageContext);
rmMessageContext.setReTransmissionCount(rmMessageContext.getReTransmissionCount() + 1);
rmMessageContext.setLocked(false);
} catch (AxisFault e) {
rmMessageContext.setLocked(false);
log.error(e);
} catch (SOAPException e) {
rmMessageContext.setLocked(false);
log.error(e);
} catch (Exception e) {
rmMessageContext.setLocked(false);
log.error(e);
}
}
rmMessageContext.setLocked(false);
}
} while (hasMessages);
long timeGap = System.currentTimeMillis() - startTime;