summaryrefslogtreecommitdiff
path: root/cpp/lib/broker/Reference.h
diff options
context:
space:
mode:
authorAlan Conway <aconway@apache.org>2007-02-06 15:01:45 +0000
committerAlan Conway <aconway@apache.org>2007-02-06 15:01:45 +0000
commitfbd97f554b04a109c95c01fe6ad538c5f50161af (patch)
tree0324d02ee4f8d6ca2387d1d3ff85bcd61a123a34 /cpp/lib/broker/Reference.h
parent80b1b0b5f443bfb3c9d62a80e1419c224d0229d8 (diff)
downloadqpid-python-fbd97f554b04a109c95c01fe6ad538c5f50161af.tar.gz
* broker/Reference, tests/ReferenceTest: class representing a reference.
* broker/BrokerChannel.cpp (complete): get destination exchange from Message, don't assume only one message in progress (could have multiple references open.) * broker/BrokerMessageMessage.cpp,.h: Contains transfer body and vector of append bodies. Construct from Reference. * broker/CompletionHandler.h: Extracted from BrokerMessage, used for MessageMessage also. * broker/ExchangeRegistry.cpp: Moved throw for missing exchanges to registry. * cpp/tests/start_broker: Increased wait time to 5 secs. * cpp/tests/*: renamed DummyChannel as MockChannel. git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/branches/qpid.0-9@504172 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/lib/broker/Reference.h')
-rw-r--r--cpp/lib/broker/Reference.h111
1 files changed, 111 insertions, 0 deletions
diff --git a/cpp/lib/broker/Reference.h b/cpp/lib/broker/Reference.h
new file mode 100644
index 0000000000..ecaca3de41
--- /dev/null
+++ b/cpp/lib/broker/Reference.h
@@ -0,0 +1,111 @@
+#ifndef _broker_Reference_h
+#define _broker_Reference_h
+
+/*
+ *
+ * Copyright (c) 2006 The Apache Software Foundation
+ *
+ * Licensed 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 <string>
+#include <vector>
+#include <map>
+#include <boost/shared_ptr.hpp>
+#include <boost/range.hpp>
+
+namespace qpid {
+
+namespace framing {
+class MessageTransferBody;
+class MessageAppendBody;
+}
+
+namespace broker {
+
+class CompletionHandler;
+class ReferenceRegistry;
+
+/**
+ * A reference is an accumulation point for data in a multi-frame
+ * message. A reference can be used by multiple transfer commands, so
+ * the reference tracks which commands are using it. When the reference
+ * is closed, all the associated transfers are completed.
+ *
+ * THREAD UNSAFE: per-channel resource, access to channels is
+ * serialized.
+ */
+class Reference
+{
+ public:
+ typedef std::string Id;
+ typedef boost::shared_ptr<framing::MessageTransferBody> TransferPtr;
+ typedef std::vector<TransferPtr> Transfers;
+ typedef boost::shared_ptr<framing::MessageAppendBody> AppendPtr;
+ typedef std::vector<AppendPtr> Appends;
+
+ Reference(const Id& id_=Id(), ReferenceRegistry* reg=0)
+ : id(id_), registry(reg) {}
+
+ const std::string& getId() const { return id; }
+
+ /** Add a transfer to be completed with this reference */
+ void transfer(TransferPtr transfer) { transfers.push_back(transfer); }
+
+ /** Append more data to the reference */
+ void append(AppendPtr ptr) { appends.push_back(ptr); }
+
+ /** Close the reference, complete each associated transfer */
+ void close();
+
+ const Appends& getAppends() const { return appends; }
+ const Transfers& getTransfers() const { return transfers; }
+
+ private:
+ void complete(TransferPtr transfer);
+
+ Id id;
+ ReferenceRegistry* registry;
+ Transfers transfers;
+ Appends appends;
+};
+
+
+/**
+ * A registry/factory for references.
+ *
+ * THREAD UNSAFE: per-channel resource, access to channels is
+ * serialized.
+ */
+class ReferenceRegistry {
+ public:
+ ReferenceRegistry(CompletionHandler& handler_) : handler(handler_) {};
+ Reference& open(const Reference::Id& id);
+ Reference& get(const Reference::Id& id);
+
+ private:
+ typedef std::map<Reference::Id, Reference> ReferenceMap;
+ CompletionHandler& handler;
+ ReferenceMap references;
+
+ // Reference calls references.erase() and uses handler.
+ friend class Reference;
+};
+
+
+}} // namespace qpid::broker
+
+
+
+#endif /*!_broker_Reference_h*/