summaryrefslogtreecommitdiff
path: root/cpp/src/qpid
diff options
context:
space:
mode:
authorAlan Conway <aconway@apache.org>2007-10-01 15:01:28 +0000
committerAlan Conway <aconway@apache.org>2007-10-01 15:01:28 +0000
commita255b35b435013061783a8032bb0060216305210 (patch)
tree585954c2a3555fa3d687fef5cd9c4fb5a2729009 /cpp/src/qpid
parent4dac7009ffa59199a16efc44864205aaabf2d0c1 (diff)
downloadqpid-python-a255b35b435013061783a8032bb0060216305210.tar.gz
* src/qpid/framing/ResumeHandler.cpp: Handle ack and resume logic
for broker and client. git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@580984 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/src/qpid')
-rw-r--r--cpp/src/qpid/framing/ResumeHandler.cpp56
-rw-r--r--cpp/src/qpid/framing/ResumeHandler.h69
2 files changed, 125 insertions, 0 deletions
diff --git a/cpp/src/qpid/framing/ResumeHandler.cpp b/cpp/src/qpid/framing/ResumeHandler.cpp
new file mode 100644
index 0000000000..9d2c971459
--- /dev/null
+++ b/cpp/src/qpid/framing/ResumeHandler.cpp
@@ -0,0 +1,56 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIE4bS OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+#include "ResumeHandler.h"
+#include "qpid/framing/reply_exceptions.h"
+
+#include <boost/bind.hpp>
+
+#include <algorithm>
+
+namespace qpid {
+namespace framing {
+
+void ResumeHandler::ackReceived(SequenceNumber acked) {
+ if (lastSent < acked)
+ throw InvalidArgumentException("Invalid sequence number in ack");
+ size_t keep = lastSent - acked;
+ if (keep < unacked.size())
+ unacked.erase(unacked.begin(), unacked.end()-keep);
+}
+
+void ResumeHandler::resend() {
+ std::for_each(unacked.begin(), unacked.end(),
+ boost::bind(&FrameHandler::handle,out->next, _1));
+}
+
+void ResumeHandler::handleIn(AMQFrame& f) {
+ ++lastReceived;
+ in.next->handle(f);
+}
+
+void ResumeHandler::handleOut(AMQFrame& f) {
+ ++lastSent;
+ unacked.push_back(f);
+ out.next->handle(f);
+}
+
+
+}} // namespace qpid::framing
diff --git a/cpp/src/qpid/framing/ResumeHandler.h b/cpp/src/qpid/framing/ResumeHandler.h
new file mode 100644
index 0000000000..c86a60b9cb
--- /dev/null
+++ b/cpp/src/qpid/framing/ResumeHandler.h
@@ -0,0 +1,69 @@
+#ifndef QPID_FRAMING_RESUMEHANDLER_H
+#define QPID_FRAMING_RESUMEHANDLER_H
+
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+#include "qpid/framing/AMQFrame.h"
+#include "qpid/framing/FrameHandler.h"
+#include "qpid/framing/SequenceNumber.h"
+
+#include <deque>
+
+namespace qpid {
+namespace framing {
+
+/**
+ * In/out handler pair for managing exactly-once session delivery.
+ * The same handler is used by client and broker.
+ * This handler only deals with TCP style SequenceNumber acks,
+ * not with fragmented SequenceNumberSet.
+ *
+ * THREAD UNSAFE. Expected to be used in a serialized context.
+ */
+class ResumeHandler : public FrameHandler::InOutHandler
+{
+ public:
+ /** Received acknowledgement for sent frames up to and including sentOk */
+ void ackReceived(SequenceNumber sentOk);
+
+ /** What was the last sequence number we received. */
+ SequenceNumber getLastReceived() { return lastReceived; }
+
+ /** Resend the unacked frames to the output handler */
+ void resend();
+
+ protected:
+ void handleIn(AMQFrame&);
+ void handleOut(AMQFrame&);
+
+ private:
+ typedef std::deque<AMQFrame> Frames;
+ Frames unacked;
+ SequenceNumber lastReceived;
+ SequenceNumber lastSent;
+};
+
+
+}} // namespace qpid::common
+
+
+#endif /*!QPID_FRAMING_RESUMEHANDLER_H*/