diff options
| author | Alan Conway <aconway@apache.org> | 2014-01-27 20:09:25 +0000 |
|---|---|---|
| committer | Alan Conway <aconway@apache.org> | 2014-01-27 20:09:25 +0000 |
| commit | 6489961f38e4ad49833b425b0316c29f1a717d31 (patch) | |
| tree | 687bf67de294ab048387b3620336b7e0e37a4bf3 /cpp/src/qpid/ha/QueueReplicator.cpp | |
| parent | 6894312e3e83301a6225416e22034c75e57b19b9 (diff) | |
| download | qpid-python-6489961f38e4ad49833b425b0316c29f1a717d31.tar.gz | |
NO-JIRA: Minor refactor to improve code safety: calling shared_from_this on creation.
Previous anti-pattern: Classes need to call shared_from_this during creation,
but can't call it in the ctor so had a separate initiailize function that the
user was required to call immediately after the constructor. Possible for user
to forget.
Improved pattern: Introduce public static create() functions to call constructor
and initialize, make constructor and initialize private.
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@1561828 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/src/qpid/ha/QueueReplicator.cpp')
| -rw-r--r-- | cpp/src/qpid/ha/QueueReplicator.cpp | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/cpp/src/qpid/ha/QueueReplicator.cpp b/cpp/src/qpid/ha/QueueReplicator.cpp index 1300819eb7..ffb40fdf22 100644 --- a/cpp/src/qpid/ha/QueueReplicator.cpp +++ b/cpp/src/qpid/ha/QueueReplicator.cpp @@ -108,6 +108,14 @@ class QueueReplicator::QueueObserver : public broker::QueueObserver { boost::shared_ptr<QueueReplicator> queueReplicator; }; +boost::shared_ptr<QueueReplicator> QueueReplicator::create( + HaBroker& hb, boost::shared_ptr<broker::Queue> q, boost::shared_ptr<broker::Link> l) +{ + boost::shared_ptr<QueueReplicator> qr(new QueueReplicator(hb, q, l)); + qr->initialize(); + return qr; +} + QueueReplicator::QueueReplicator(HaBroker& hb, boost::shared_ptr<Queue> q, boost::shared_ptr<Link> l) @@ -144,9 +152,7 @@ QueueReplicator::QueueReplicator(HaBroker& hb, QueueReplicator::~QueueReplicator() {} -// This must be called immediately after the constructor. -// It has to be separate so we can call shared_from_this(). -void QueueReplicator::activate() { +void QueueReplicator::initialize() { Mutex::ScopedLock l(lock); QPID_LOG(debug, logPrefix << "Created"); if (!queue) return; // Already destroyed |
