https://issues.apache.org/activemq/browse/AMQ-2515 - Optimized Acknowledgements and interrupted transport

git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@884633 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Bosanac Dejan 2009-11-26 16:46:38 +00:00
parent 8978ac0772
commit 13f9ec8555
1 changed files with 12 additions and 9 deletions

View File

@ -134,6 +134,9 @@ public class ActiveMQMessageConsumer implements MessageAvailableConsumer, StatsC
private long lastDeliveredSequenceId; private long lastDeliveredSequenceId;
private IOException failureError; private IOException failureError;
private long optimizeAckTimestamp = System.currentTimeMillis();
private long optimizeAckTimeout = 300;
/** /**
* Create a MessageConsumer * Create a MessageConsumer
@ -788,7 +791,7 @@ public class ActiveMQMessageConsumer implements MessageAvailableConsumer, StatsC
} }
} }
} }
private void afterMessageIsConsumed(MessageDispatch md, boolean messageExpired) throws JMSException { private void afterMessageIsConsumed(MessageDispatch md, boolean messageExpired) throws JMSException {
if (unconsumedMessages.isClosed()) { if (unconsumedMessages.isClosed()) {
return; return;
@ -809,12 +812,13 @@ public class ActiveMQMessageConsumer implements MessageAvailableConsumer, StatsC
if (!deliveredMessages.isEmpty()) { if (!deliveredMessages.isEmpty()) {
if (optimizeAcknowledge) { if (optimizeAcknowledge) {
ackCounter++; ackCounter++;
if (ackCounter >= (info.getCurrentPrefetchSize() * .65)) { if (ackCounter >= (info.getPrefetchSize() * .65) || System.currentTimeMillis() >= (optimizeAckTimestamp + optimizeAckTimeout)) {
MessageAck ack = makeAckForAllDeliveredMessages(MessageAck.STANDARD_ACK_TYPE); MessageAck ack = makeAckForAllDeliveredMessages(MessageAck.STANDARD_ACK_TYPE);
if (ack != null) { if (ack != null) {
deliveredMessages.clear(); deliveredMessages.clear();
ackCounter = 0; ackCounter = 0;
session.sendAck(ack); session.sendAck(ack);
optimizeAckTimestamp = System.currentTimeMillis();
} }
} }
} else { } else {
@ -1074,14 +1078,13 @@ public class ActiveMQMessageConsumer implements MessageAvailableConsumer, StatsC
session.connection.rollbackDuplicate(this, old.getMessage()); session.connection.rollbackDuplicate(this, old.getMessage());
} }
} }
if (pendingAck != null && pendingAck.isDeliveredAck()) { if (!session.isTransacted()) {
// on resumption a pending delivered ack will be out of sync with // clean, so we don't have duplicates with optimizeAcknowledge
// re deliveries. synchronized (deliveredMessages) {
if (LOG.isDebugEnabled()) { deliveredMessages.clear();
LOG.debug("removing pending delivered ack on transport interupt: " + pendingAck); }
}
pendingAck = null;
} }
pendingAck = null;
} }
if (!unconsumedMessages.isClosed()) { if (!unconsumedMessages.isClosed()) {
if (this.info.isBrowser() || !session.connection.isDuplicate(this, md.getMessage())) { if (this.info.isBrowser() || !session.connection.isDuplicate(this, md.getMessage())) {