diff options
Diffstat (limited to 'cpp/src')
-rw-r--r-- | cpp/src/Makefile.am | 3 | ||||
-rw-r--r-- | cpp/src/qpid/broker/MultiVersionConnectionInputHandler.cpp | 71 | ||||
-rw-r--r-- | cpp/src/qpid/broker/MultiVersionConnectionInputHandler.h | 58 | ||||
-rw-r--r-- | cpp/src/qpid/sys/RefCountedMap.h | 164 | ||||
-rw-r--r-- | cpp/src/tests/RefCountedMap.cpp | 123 |
5 files changed, 0 insertions, 419 deletions
diff --git a/cpp/src/Makefile.am b/cpp/src/Makefile.am index f79a634060..72f63ae48e 100644 --- a/cpp/src/Makefile.am +++ b/cpp/src/Makefile.am @@ -208,7 +208,6 @@ libqpidbroker_la_SOURCES = \ qpid/broker/MessageDelivery.cpp \ qpid/broker/MessageHandlerImpl.cpp \ qpid/broker/MessageStoreModule.cpp \ - qpid/broker/MultiVersionConnectionInputHandler.cpp \ qpid/broker/NameGenerator.cpp \ qpid/broker/NullMessageStore.cpp \ qpid/broker/QueueBindings.cpp \ @@ -330,7 +329,6 @@ nobase_include_HEADERS = \ qpid/broker/MessageHandlerImpl.h \ qpid/broker/MessageStore.h \ qpid/broker/MessageStoreModule.h \ - qpid/broker/MultiVersionConnectionInputHandler.h \ qpid/broker/NameGenerator.h \ qpid/broker/NullMessageStore.h \ qpid/broker/Persistable.h \ @@ -471,7 +469,6 @@ nobase_include_HEADERS = \ qpid/sys/OutputTask.h \ qpid/sys/Poller.h \ qpid/sys/Runnable.h \ - qpid/sys/RefCountedMap.h \ qpid/sys/ScopedIncrement.h \ qpid/sys/Semaphore.h \ qpid/sys/Serializer.h \ diff --git a/cpp/src/qpid/broker/MultiVersionConnectionInputHandler.cpp b/cpp/src/qpid/broker/MultiVersionConnectionInputHandler.cpp deleted file mode 100644 index f1bbf7d10e..0000000000 --- a/cpp/src/qpid/broker/MultiVersionConnectionInputHandler.cpp +++ /dev/null @@ -1,71 +0,0 @@ -/* - * - * 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 "MultiVersionConnectionInputHandler.h" -#include "Connection.h" -#include "PreviewConnection.h" -#include "qpid/framing/reply_exceptions.h" - -namespace qpid { -namespace broker { - -MultiVersionConnectionInputHandler::MultiVersionConnectionInputHandler( - qpid::sys::ConnectionOutputHandler* _out, - Broker& _broker, - const std::string& _id) : linkVersion(99,0), out(_out), broker(_broker), id(_id) {} - -void MultiVersionConnectionInputHandler::received(qpid::framing::AMQFrame& f) -{ - check(); - handler->received(f); -} - -void MultiVersionConnectionInputHandler::idleOut() -{ - check(); - handler->idleOut(); -} - -void MultiVersionConnectionInputHandler::idleIn() -{ - check(); - handler->idleIn(); -} - -bool MultiVersionConnectionInputHandler::doOutput() -{ - return handler.get() && handler->doOutput(); -} - -void MultiVersionConnectionInputHandler::closed() -{ - if (handler.get()) handler->closed(); - //else closed before initiated, nothing to do -} - -void MultiVersionConnectionInputHandler::check() -{ - if (!handler.get()) { - throw qpid::framing::InternalErrorException("Handler not initialised!"); - } -} - -} -} diff --git a/cpp/src/qpid/broker/MultiVersionConnectionInputHandler.h b/cpp/src/qpid/broker/MultiVersionConnectionInputHandler.h deleted file mode 100644 index e6915a00bd..0000000000 --- a/cpp/src/qpid/broker/MultiVersionConnectionInputHandler.h +++ /dev/null @@ -1,58 +0,0 @@ -/* - * - * 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. - * - */ -#ifndef _MultiVersionConnectionInputHandler_ -#define _MultiVersionConnectionInputHandler_ - -#include <memory> -#include <string> -#include "qpid/sys/ConnectionInputHandler.h" -#include "qpid/sys/ConnectionOutputHandler.h" -#include "qpid/broker/Broker.h" - -namespace qpid { -namespace broker { - -class MultiVersionConnectionInputHandler : public qpid::sys::ConnectionInputHandler -{ - qpid::framing::ProtocolVersion linkVersion;//version used for inter-broker links - std::auto_ptr<qpid::sys::ConnectionInputHandler> handler; - qpid::sys::ConnectionOutputHandler* out; - Broker& broker; - const std::string id; - - void check(); - -public: - MultiVersionConnectionInputHandler(qpid::sys::ConnectionOutputHandler* out, Broker& broker, const std::string& id); - virtual ~MultiVersionConnectionInputHandler() {} - - void received(qpid::framing::AMQFrame&); - void idleOut(); - void idleIn(); - bool doOutput(); - void closed(); -}; - -} -} - - -#endif diff --git a/cpp/src/qpid/sys/RefCountedMap.h b/cpp/src/qpid/sys/RefCountedMap.h deleted file mode 100644 index 2186e61b15..0000000000 --- a/cpp/src/qpid/sys/RefCountedMap.h +++ /dev/null @@ -1,164 +0,0 @@ -#ifndef QPID_SYS_REFCOUNTEDMAP_H -#define QPID_SYS_REFCOUNTEDMAP_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/sys/Mutex.h" -#include "qpid/RefCounted.h" -#include <boost/type_traits/remove_pointer.hpp> -#include <boost/bind.hpp> -#include <boost/tuple/tuple.hpp> -#include <boost/cast.hpp> -#include <boost/intrusive_ptr.hpp> -#include <vector> -#include <map> -#include <algorithm> - -namespace qpid { -namespace sys { - -template <class, class, class> class RefCountedMap; - -template <class Key, class Data, class Base=RefCounted, - class Impl=std::map<Key, Data*> > -class RefCountedMapData : public Base { - public: - typedef RefCountedMap<Key, Data, Impl> Map; - - bool attached() { - assert(map || self->second == this); - return map; - } - const Key& getKey() const { assert(attached()); return self->first; } - void released() const { if (map) map->lockedDetach(self); delete this; } - - private: - friend class RefCountedMap<Key, Data, Impl>; - boost::intrusive_ptr<Map> map; - typename Impl::iterator self; - - public: -}; - -/** - * A thread-safe, reference-counted, weak map of reference-counted values. - * - * The map does not hold a reference to its members, they must have - * external references to exist. When last external reference is - * released, the value is atomically erased from the map and deleted. - * - * The map itself is a member of a ref-counted holder class, the - * map ensures its holder is not deleted till the map is empty. - */ -template <class Key, class Data, class Impl=std::map<Key, Data*> > -class RefCountedMap : public RefCountedChild { - template <class, class, class, class> friend class RefCountedMapData; - typedef typename Impl::iterator iterator; - typedef typename Impl::value_type value_type; - - mutable sys::Mutex lock; - Impl map; - - // Acquire the lock and ensure map is not deleted before unlock. - class Lock { - boost::intrusive_ptr<const RefCountedMap> map; - sys::Mutex::ScopedLock lock; - public: - Lock(const RefCountedMap* m) : map(m), lock(m->lock) {} - }; - - // Called from Data::released. - void lockedDetach(iterator i) { Lock l(this); detach(i); } - - void detach(iterator i) { - // Must be called with lock held. - assert(i->second->map == this); - map.erase(i); - i->second->map = 0; // May call this->release() - } - - public: - RefCountedMap(RefCounted& container) : RefCountedChild(container) {} - ~RefCountedMap() {} - - /** Return 0 if not found */ - boost::intrusive_ptr<Data> find(const Key& k) { - Lock l(this); - iterator i = map.find(k); - return (i == map.end()) ? 0 : i->second; - } - - bool insert(const Key& k, boost::intrusive_ptr<Data> d) { - Lock l(this); - iterator i; - bool inserted; - boost::tuples::tie(i, inserted) = - map.insert(std::make_pair(k, d.get())); - if (inserted) { - assert(!d->map); - d->map=boost::polymorphic_downcast<RefCountedMap*>(this); - d->self=i; - } - return inserted; - } - - size_t size() { Lock l(this); return map.size(); } - - bool empty() { Lock l(this); return map.empty(); } - - void erase(const Key& k) { Lock l(this); detach(map.find(k)); } - - void clear() { Lock l(this); while (!map.empty()) detach(map.begin()); } - - /** Clear the map, apply functor to each entry before erasing */ - template <class F> void clear(F functor) { - Lock l(this); - while (!map.empty()) { - boost::intrusive_ptr<Data> ptr; - if (map.empty()) return; - ptr = map.begin()->second; - detach(map.begin()); - sys::Mutex::ScopedUnlock u(lock); - functor(ptr); - } - } - - /** Apply functor to each map entry. */ - template <class F> void apply(F functor) { - std::vector<boost::intrusive_ptr<Data> > snapshot; - { - // Take a snapshot referencing all values in map. - Lock l(this); - snapshot.resize(map.size()); - typedef value_type value_type; - std::transform(map.begin(), map.end(), snapshot.begin(), - boost::bind(&value_type::second, _1)); - } - // Drop the lock to call functor. - std::for_each(snapshot.begin(), snapshot.end(), functor); - } -}; - - -}} // namespace qpid::sys - -#endif /*!QPID_SYS_REFCOUNTEDMAP_H*/ diff --git a/cpp/src/tests/RefCountedMap.cpp b/cpp/src/tests/RefCountedMap.cpp deleted file mode 100644 index 79a0d94eb7..0000000000 --- a/cpp/src/tests/RefCountedMap.cpp +++ /dev/null @@ -1,123 +0,0 @@ -/* - * - * 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 "qpid/sys/RefCountedMap.h" -#include "unit_test.h" -#include "test_tools.h" -#include <boost/bind.hpp> -#include <map> - -QPID_AUTO_TEST_SUITE(RefCountedMapTestSuite) - -using namespace std; -using namespace qpid; -using namespace qpid::sys; - -template <int Id> struct Counted { - static int instances; - Counted() { ++instances; } - Counted(const Counted&) { ++instances; } - ~Counted() { --instances; } -}; -template <int Id>int Counted<Id>::instances=0; - -struct Data : public RefCountedMapData<int, Data>, public Counted<2> { - Data(int i=0) : value(i) {} - int value; - void inc() { value++; } -}; - -struct Container : public RefCounted, public Counted<3> { - Data::Map map; - Container() : map(*this) {} -}; - -struct RefCountedMapFixture { - intrusive_ptr<Container> cont; - intrusive_ptr<Data> p, q; - RefCountedMapFixture() : - cont(new Container()), p(new Data(1)), q(new Data(2)) - { - cont->map.insert(1,p); - cont->map.insert(2,q); - } - ~RefCountedMapFixture() { if (cont) cont->map.clear(); } -}; - -BOOST_FIXTURE_TEST_CASE(testFixtureSetup, RefCountedMapFixture) { - BOOST_CHECK_EQUAL(1, Container::instances); - BOOST_CHECK_EQUAL(2, Data::instances); - BOOST_CHECK_EQUAL(cont->map.size(), 2u); - BOOST_CHECK_EQUAL(cont->map.find(1)->value, 1); - BOOST_CHECK_EQUAL(cont->map.find(2)->value, 2); -} - -BOOST_FIXTURE_TEST_CASE(testReleaseRemoves, RefCountedMapFixture) -{ - // Release external ref, removes from map - p = 0; - BOOST_CHECK_EQUAL(Data::instances, 1); - BOOST_CHECK_EQUAL(cont->map.size(), 1u); - BOOST_CHECK(!cont->map.find(1)); - BOOST_CHECK_EQUAL(cont->map.find(2)->value, 2); - - q = 0; - BOOST_CHECK(cont->map.empty()); -} - -// Functor that releases values as a side effect. -struct Release { - RefCountedMapFixture& f ; - Release(RefCountedMapFixture& ff) : f(ff) {} - void operator()(const intrusive_ptr<Data>& ptr) { - BOOST_CHECK(ptr->value > 0); // Make sure ptr is not released. - f.p = 0; - f.q = 0; - BOOST_CHECK(ptr->value > 0); // Make sure ptr is not released. - } -}; - - -BOOST_FIXTURE_TEST_CASE(testApply, RefCountedMapFixture) { - cont->map.apply(boost::bind(&Data::inc, _1)); - BOOST_CHECK_EQUAL(2, p->value); - BOOST_CHECK_EQUAL(3, q->value); - - // Allow functors to release valuse as side effects. - cont->map.apply(Release(*this)); - BOOST_CHECK(cont->map.empty()); - BOOST_CHECK_EQUAL(Data::instances, 0); -} - -BOOST_FIXTURE_TEST_CASE(testClearFunctor, RefCountedMapFixture) { - cont->map.clear(boost::bind(&Data::inc, _1)); - BOOST_CHECK(cont->map.empty()); - BOOST_CHECK_EQUAL(2, p->value); - BOOST_CHECK_EQUAL(3, q->value); -} - -BOOST_FIXTURE_TEST_CASE(testReleaseEmptyMap, RefCountedMapFixture) { - // Container must not be deleted till map is empty. - cont = 0; - BOOST_CHECK_EQUAL(1, Container::instances); // Not empty. - p = 0; - q = 0; - BOOST_CHECK_EQUAL(0, Container::instances); // Deleted -} - -QPID_AUTO_TEST_SUITE_END() |