git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@613829 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Robert Davies 2008-01-21 10:28:59 +00:00
parent 8f190f188b
commit caf7a7c7c2
1 changed files with 115 additions and 101 deletions

View File

@ -595,6 +595,7 @@ public class ActiveMQMessageConsumer implements MessageAvailableConsumer, StatsC
MessageAck ack = null;
if (deliveryingAcknowledgements.compareAndSet(false, true)) {
if (this.optimizeAcknowledge) {
synchronized(deliveredMessages) {
if (!deliveredMessages.isEmpty()) {
MessageDispatch md = deliveredMessages.getFirst();
ack = new MessageAck(md, MessageAck.STANDARD_ACK_TYPE, deliveredMessages.size());
@ -602,6 +603,7 @@ public class ActiveMQMessageConsumer implements MessageAvailableConsumer, StatsC
ackCounter = 0;
}
}
}
if (ack != null) {
final MessageAck ackToSend = ack;
if (executorService == null) {
@ -712,7 +714,9 @@ public class ActiveMQMessageConsumer implements MessageAvailableConsumer, StatsC
private void beforeMessageIsConsumed(MessageDispatch md) throws JMSException {
md.setDeliverySequenceId(session.getNextDeliveryId());
if (!session.isDupsOkAcknowledge()) {
synchronized(deliveredMessages) {
deliveredMessages.addFirst(md);
}
if (session.isTransacted()) {
ackLater(md, MessageAck.DELIVERED_ACK_TYPE);
}
@ -730,13 +734,15 @@ public class ActiveMQMessageConsumer implements MessageAvailableConsumer, StatsC
if (session.isTransacted()) {
// Do nothing.
} else if (session.isAutoAcknowledge()) {
synchronized (deliveredMessages) {
if (!deliveredMessages.isEmpty()) {
if (optimizeAcknowledge) {
if (deliveryingAcknowledgements.compareAndSet(false, true)) {
if (deliveryingAcknowledgements.compareAndSet(
false, true)) {
ackCounter++;
if (ackCounter >= (info.getCurrentPrefetchSize() * .65)) {
MessageAck ack = new MessageAck(md, MessageAck.STANDARD_ACK_TYPE,
deliveredMessages.size());
if (ackCounter >= (info
.getCurrentPrefetchSize() * .65)) {
MessageAck ack = new MessageAck(md,MessageAck.STANDARD_ACK_TYPE,deliveredMessages.size());
session.asyncSendPacket(ack);
ackCounter = 0;
deliveredMessages.clear();
@ -744,12 +750,12 @@ public class ActiveMQMessageConsumer implements MessageAvailableConsumer, StatsC
deliveryingAcknowledgements.set(false);
}
} else {
MessageAck ack = new MessageAck(md, MessageAck.STANDARD_ACK_TYPE, deliveredMessages
.size());
MessageAck ack = new MessageAck(md,MessageAck.STANDARD_ACK_TYPE,deliveredMessages.size());
session.asyncSendPacket(ack);
deliveredMessages.clear();
}
}
}
} else if (session.isDupsOkAcknowledge()) {
ackLater(md, MessageAck.STANDARD_ACK_TYPE);
} else if (session.isClientAcknowledge()) {
@ -812,6 +818,7 @@ public class ActiveMQMessageConsumer implements MessageAvailableConsumer, StatsC
* @throws JMSException
*/
public void acknowledge() throws JMSException {
synchronized(deliveredMessages) {
if (deliveredMessages.isEmpty()) {
return;
}
@ -833,9 +840,12 @@ public class ActiveMQMessageConsumer implements MessageAvailableConsumer, StatsC
deliveredMessages.clear();
}
}
}
public void commit() throws JMSException {
synchronized (deliveredMessages) {
deliveredMessages.clear();
}
redeliveryDelay = 0;
}
@ -845,6 +855,7 @@ public class ActiveMQMessageConsumer implements MessageAvailableConsumer, StatsC
// remove messages read but not acked at the broker yet through
// optimizeAcknowledge
if (!this.info.isBrowser()) {
synchronized(deliveredMessages) {
for (int i = 0; (i < deliveredMessages.size()) && (i < ackCounter); i++) {
// ensure we don't filter this as a duplicate
MessageDispatch md = deliveredMessages.removeLast();
@ -852,6 +863,8 @@ public class ActiveMQMessageConsumer implements MessageAvailableConsumer, StatsC
}
}
}
}
synchronized(deliveredMessages) {
if (deliveredMessages.isEmpty()) {
return;
}
@ -914,6 +927,7 @@ public class ActiveMQMessageConsumer implements MessageAvailableConsumer, StatsC
deliveredCounter -= deliveredMessages.size();
deliveredMessages.clear();
}
}
if (messageListener != null) {
session.redispatch(this, unconsumedMessages);
}