Return-Path: X-Original-To: apmail-qpid-commits-archive@www.apache.org Delivered-To: apmail-qpid-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 11CCA10198 for ; Thu, 1 Aug 2013 20:26:57 +0000 (UTC) Received: (qmail 27044 invoked by uid 500); 1 Aug 2013 20:26:57 -0000 Delivered-To: apmail-qpid-commits-archive@qpid.apache.org Received: (qmail 27010 invoked by uid 500); 1 Aug 2013 20:26:57 -0000 Mailing-List: contact commits-help@qpid.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@qpid.apache.org Delivered-To: mailing list commits@qpid.apache.org Received: (qmail 27003 invoked by uid 99); 1 Aug 2013 20:26:57 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 01 Aug 2013 20:26:57 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 01 Aug 2013 20:26:55 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 58CEE2388A02; Thu, 1 Aug 2013 20:26:35 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1509419 - in /qpid/trunk/qpid/cpp/src/qpid/broker: TxAccept.cpp TxAccept.h Date: Thu, 01 Aug 2013 20:26:35 -0000 To: commits@qpid.apache.org From: aconway@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20130801202635.58CEE2388A02@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: aconway Date: Thu Aug 1 20:26:34 2013 New Revision: 1509419 URL: http://svn.apache.org/r1509419 Log: QPID-4327: Refactor to simplify TxAccept. Removed un-necessary RangeOps layers. Modified: qpid/trunk/qpid/cpp/src/qpid/broker/TxAccept.cpp qpid/trunk/qpid/cpp/src/qpid/broker/TxAccept.h Modified: qpid/trunk/qpid/cpp/src/qpid/broker/TxAccept.cpp URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/broker/TxAccept.cpp?rev=1509419&r1=1509418&r2=1509419&view=diff ============================================================================== --- qpid/trunk/qpid/cpp/src/qpid/broker/TxAccept.cpp (original) +++ qpid/trunk/qpid/cpp/src/qpid/broker/TxAccept.cpp Thu Aug 1 20:26:34 2013 @@ -7,9 +7,9 @@ * 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 @@ -28,54 +28,23 @@ using namespace qpid::broker; using qpid::framing::SequenceSet; using qpid::framing::SequenceNumber; -TxAccept::RangeOp::RangeOp(const AckRange& r) : range(r) {} - -void TxAccept::RangeOp::prepare(TransactionContext* ctxt) -{ - for_each(range.start, range.end, bind(&DeliveryRecord::dequeue, _1, ctxt)); -} - -void TxAccept::RangeOp::commit() -{ - for_each(range.start, range.end, bind(&DeliveryRecord::committed, _1)); - for_each(range.start, range.end, bind(&DeliveryRecord::setEnded, _1)); -} - -TxAccept::RangeOps::RangeOps(DeliveryRecords& u) : unacked(u) {} -void TxAccept::RangeOps::operator()(SequenceNumber start, SequenceNumber end) +TxAccept::TxAccept(const SequenceSet& _acked, DeliveryRecords& _unacked) : + acked(_acked), unacked(_unacked) { - ranges.push_back(RangeOp(DeliveryRecord::findRange(unacked, start, end))); + for(SequenceSet::RangeIterator i = acked.rangesBegin(); i != acked.rangesEnd(); ++i) + ranges.push_back(DeliveryRecord::findRange(unacked, i->first(), i->last())); } -void TxAccept::RangeOps::prepare(TransactionContext* ctxt) -{ - std::for_each(ranges.begin(), ranges.end(), bind(&RangeOp::prepare, _1, ctxt)); -} - -void TxAccept::RangeOps::commit() -{ - std::for_each(ranges.begin(), ranges.end(), bind(&RangeOp::commit, _1)); - //now remove if isRedundant(): - if (!ranges.empty()) { - DeliveryRecords::iterator begin = ranges.front().range.start; - DeliveryRecords::iterator end = ranges.back().range.end; - DeliveryRecords::iterator removed = remove_if(begin, end, mem_fun_ref(&DeliveryRecord::isRedundant)); - unacked.erase(removed, end); - } -} - -TxAccept::TxAccept(const SequenceSet& _acked, DeliveryRecords& _unacked) : - acked(_acked), unacked(_unacked), ops(unacked) -{ - //populate the ops - acked.for_each(ops); +void TxAccept::each(boost::function f) { + for(AckRanges::iterator i = ranges.begin(); i != ranges.end(); ++i) + for_each(i->start, i->end, f); } bool TxAccept::prepare(TransactionContext* ctxt) throw() { try{ - ops.prepare(ctxt); + each(bind(&DeliveryRecord::dequeue, _1, ctxt)); return true; }catch(const std::exception& e){ QPID_LOG(error, "Failed to prepare: " << e.what()); @@ -86,10 +55,19 @@ bool TxAccept::prepare(TransactionContex } } -void TxAccept::commit() throw() +void TxAccept::commit() throw() { try { - ops.commit(); + each(bind(&DeliveryRecord::committed, _1)); + each(bind(&DeliveryRecord::setEnded, _1)); + //now remove if isRedundant(): + if (!ranges.empty()) { + DeliveryRecords::iterator begin = ranges.front().start; + DeliveryRecords::iterator end = ranges.back().end; + DeliveryRecords::iterator removed = + remove_if(begin, end, mem_fun_ref(&DeliveryRecord::isRedundant)); + unacked.erase(removed, end); + } } catch (const std::exception& e) { QPID_LOG(error, "Failed to commit: " << e.what()); } catch(...) { Modified: qpid/trunk/qpid/cpp/src/qpid/broker/TxAccept.h URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/broker/TxAccept.h?rev=1509419&r1=1509418&r2=1509419&view=diff ============================================================================== --- qpid/trunk/qpid/cpp/src/qpid/broker/TxAccept.h (original) +++ qpid/trunk/qpid/cpp/src/qpid/broker/TxAccept.h Thu Aug 1 20:26:34 2013 @@ -7,9 +7,9 @@ * 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 @@ -21,58 +21,42 @@ #ifndef _TxAccept_ #define _TxAccept_ -#include -#include -#include #include "qpid/framing/SequenceSet.h" #include "qpid/broker/DeliveryRecord.h" #include "qpid/broker/TxOp.h" +#include +#include +#include +#include namespace qpid { - namespace broker { - /** - * Defines the transactional behaviour for accepts received by - * a transactional channel. - */ - class TxAccept : public TxOp { - struct RangeOp - { - AckRange range; - - RangeOp(const AckRange& r); - void prepare(TransactionContext* ctxt); - void commit(); - }; - - struct RangeOps - { - std::vector ranges; - DeliveryRecords& unacked; - - RangeOps(DeliveryRecords& u); - - void operator()(framing::SequenceNumber start, framing::SequenceNumber end); - void prepare(TransactionContext* ctxt); - void commit(); - }; - - framing::SequenceSet acked; - DeliveryRecords& unacked; - RangeOps ops; - - public: - /** - * @param acked a representation of the accumulation of - * acks received - * @param unacked the record of delivered messages - */ - TxAccept(const framing::SequenceSet& acked, DeliveryRecords& unacked); - virtual bool prepare(TransactionContext* ctxt) throw(); - virtual void commit() throw(); - virtual void rollback() throw(); - virtual ~TxAccept(){} - }; - } +namespace broker { +/** + * Defines the transactional behaviour for accepts received by + * a transactional channel. + */ +class TxAccept : public TxOp { + typedef std::vector AckRanges; + + void each(boost::function); + + framing::SequenceSet acked; + DeliveryRecords& unacked; + AckRanges ranges; + + public: + /** + * @param acked a representation of the accumulation of + * acks received + * @param unacked the record of delivered messages + */ + TxAccept(const framing::SequenceSet& acked, DeliveryRecords& unacked); + virtual bool prepare(TransactionContext* ctxt) throw(); + virtual void commit() throw(); + virtual void rollback() throw(); + virtual ~TxAccept(){} +}; +} } --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org For additional commands, e-mail: commits-help@qpid.apache.org