diff options
| author | Alan Conway <aconway@apache.org> | 2013-08-01 20:27:26 +0000 |
|---|---|---|
| committer | Alan Conway <aconway@apache.org> | 2013-08-01 20:27:26 +0000 |
| commit | 014f0f39d9cfb6242bea173eadbc0f8229ba5f7f (patch) | |
| tree | 74c5eba8fe21abb8d8ab00014663b1239e82fdde /qpid/cpp/include | |
| parent | dcbe820e4ebdbd4919ebd07b56790e15de3013e9 (diff) | |
| download | qpid-python-014f0f39d9cfb6242bea173eadbc0f8229ba5f7f.tar.gz | |
QPID-4327: HA TX transactions: basic replication.
On primary a PrimaryTxObserver observes a transaction's TxBuffer and generates
transaction events on a tx-replication-queue. On the backup a TxReplicator
receives the events and constructs a TxBuffer equivalent to the one in the
primary.
Unfinished:
- Primary does not wait for backups to prepare() before committing.
- All connected backups are assumed to be in the transaction, there are race
conditions around brokers joining/leavinv where this assumption is invalid.
- Need more tests.
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1509423 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/cpp/include')
| -rw-r--r-- | qpid/cpp/include/qpid/framing/BufferTypes.h | 106 |
1 files changed, 106 insertions, 0 deletions
diff --git a/qpid/cpp/include/qpid/framing/BufferTypes.h b/qpid/cpp/include/qpid/framing/BufferTypes.h new file mode 100644 index 0000000000..4199755852 --- /dev/null +++ b/qpid/cpp/include/qpid/framing/BufferTypes.h @@ -0,0 +1,106 @@ +#ifndef QPID_FRAMING_BUFFERTYPES_H +#define QPID_FRAMING_BUFFERTYPES_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. + * + */ + +/**@file + * Using templates with framing::Buffer is difficultg becase of the many + * different put/get function names. Here we define a set of types + * corresponding the basic types of Buffer but presenting a uniform + * encode/decode/encodedSize interface. + * + * It also provides some convenience templates for the common case of + * encoding a single encodable value as a string, e.g. + * + * LongString ls("hello"); + * std::string encoded = encodeStr(ls); + * LongString ls2 = decodeStr<LongString>(encoded); + * LongString ls3; + * decodeStr(encoded, ls3); + */ + +namespace qpid { +namespace framing { + +// Templates to help define types +template <class ValueType> struct BufferTypeTraits { + typedef void (Buffer::*Put)(const ValueType&); + typedef void (Buffer::*Get)(ValueType&); +}; + +template <class ValueType, + typename BufferTypeTraits<ValueType>::Put PutFn, + typename BufferTypeTraits<ValueType>::Get GetFn> +struct EncodeDecodeTemplate { + EncodeDecodeTemplate(const ValueType& s) : value(s) {} + operator ValueType() const { return value; } + + ValueType value; + void encode(framing::Buffer& buf) const { (buf.*PutFn)(value); } + void decode(framing::Buffer& buf) { (buf.*GetFn)(value); } +}; + +template <size_t Size, + typename BufferTypeTraits<std::string>::Put PutFn, + typename BufferTypeTraits<std::string>::Get GetFn + > +struct StringTypeTemplate : public EncodeDecodeTemplate<std::string, PutFn, GetFn> { + typedef EncodeDecodeTemplate<std::string, PutFn, GetFn> Base; + StringTypeTemplate(const std::string& s) : Base(s) {} + size_t encodedSize() const { return Size + Base::value.size(); } +}; + + +// Convenience tempates for encoding/decoding values to/from a std::string. + +/** Encode value as a string. */ +template <class T> std::string encodeStr(const T& value) { + std::string encoded(value.encodedSize(), '\0'); + framing::Buffer buffer(&encoded[0], encoded.size()); + value.encode(buffer); + return encoded; +} + +/** Decode value from a string. */ +template <class T> void decodeStr(const std::string& encoded, T& value) { + framing::Buffer b(const_cast<char*>(&encoded[0]), encoded.size()); + value.decode(b); +} + +/** Decode value from a string. */ +template <class T> T decodeStr(const std::string& encoded) { + T value; + decodeStr(encoded, value); + return value; +} + +// The types + +typedef StringTypeTemplate<4, &Buffer::putLongString, &Buffer::getLongString> LongString; +typedef StringTypeTemplate<2, &Buffer::putMediumString, &Buffer::getMediumString> MediumString; +typedef StringTypeTemplate<1, &Buffer::putShortString, &Buffer::getShortString> ShortString; + +// TODO aconway 2013-07-26: Add integer types. + +}} // namespace qpid::framing + +#endif /*!QPID_FRAMING_BUFFERTYPES_H*/ |
