From 014a405c38d5f22c384bbf9f277de585d8c54a3d Mon Sep 17 00:00:00 2001 From: "Rafael H. Schloming" Date: Tue, 30 Jan 2007 20:40:09 +0000 Subject: made multiple acknowledgement work git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/branches/qpid.0-9@501551 13f79535-47bb-0310-9956-ffa450edef68 --- .../java/org/apache/qpid/client/AMQSession.java | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) (limited to 'java/client/src') diff --git a/java/client/src/main/java/org/apache/qpid/client/AMQSession.java b/java/client/src/main/java/org/apache/qpid/client/AMQSession.java index fdd347fbc8..2e2f3e0406 100644 --- a/java/client/src/main/java/org/apache/qpid/client/AMQSession.java +++ b/java/client/src/main/java/org/apache/qpid/client/AMQSession.java @@ -26,6 +26,7 @@ import java.util.ArrayList; import java.util.Iterator; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentLinkedQueue; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; @@ -136,6 +137,8 @@ public class AMQSession extends Closeable implements Session, QueueSession, Topi */ private final FlowControllingBlockingQueue _queue; + private ConcurrentLinkedQueue _unacknowledged = new ConcurrentLinkedQueue(); + private Dispatcher _dispatcher; private MessageFactoryRegistry _messageFactoryRegistry; @@ -772,6 +775,7 @@ public class AMQSession extends Closeable implements Session, QueueSession, Topi { consumer.clearUnackedMessages(); } + _unacknowledged.clear(); // AMQP version change: Hardwire the version to 0-9 (major=0, minor=9) // TODO: Connect this to the session version obtained from ProtocolInitiation for this session. // Be aware of possible changes to parameter order as versions change. @@ -1596,6 +1600,7 @@ public class AMQSession extends Closeable implements Session, QueueSession, Topi } _queue.add(message); + _unacknowledged.offer(message.deliveryTag); } /** @@ -1608,19 +1613,27 @@ public class AMQSession extends Closeable implements Session, QueueSession, Topi * delivery tag * @throws AMQException */ - public void acknowledgeMessage(long requestId, boolean multiple) throws AMQException + public synchronized void acknowledgeMessage(long requestId, boolean multiple) throws AMQException { // AMQP version change: Hardwire the version to 0-9 (major=0, minor=9) // TODO: Connect this to the session version obtained from ProtocolInitiation for this session. // Be aware of possible changes to parameter order as versions change. final AMQMethodBody methodBody = MessageOkBody.createMethodBody((byte)0, (byte)9); // AMQP version (major, minor) - //deliveryTag, // deliveryTag - //multiple); // multiple if (_logger.isDebugEnabled()) { _logger.debug("Sending ack for request ID " + requestId + " on channel " + _channelId); } - _connection.getProtocolHandler().writeResponse(_channelId, requestId, methodBody); + if (multiple) { + for (Iterator it = _unacknowledged.iterator(); it.hasNext(); ) { + long tag = it.next(); + if (tag > requestId) { break; } + _connection.getProtocolHandler().writeResponse(_channelId, tag, methodBody); + it.remove(); + } + } else { + _connection.getProtocolHandler().writeResponse(_channelId, requestId, methodBody); + _unacknowledged.remove(requestId); + } } public int getDefaultPrefetch() -- cgit v1.2.1