You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ta...@apache.org on 2011/04/07 01:31:21 UTC
svn commit: r1089673 - in
/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq:
library/ActiveMQCPP.cpp transport/TransportRegistry.cpp
transport/TransportRegistry.h wireformat/WireFormatRegistry.cpp
wireformat/WireFormatRegistry.h
Author: tabish
Date: Wed Apr 6 23:31:21 2011
New Revision: 1089673
URL: http://svn.apache.org/viewvc?rev=1089673&view=rev
Log:
Provide a single method in these registries to purge all registered factories to prevent a memory leak should the user add their own factory or one of the test cases.
Modified:
activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/library/ActiveMQCPP.cpp
activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/transport/TransportRegistry.cpp
activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/transport/TransportRegistry.h
activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/wireformat/WireFormatRegistry.cpp
activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/wireformat/WireFormatRegistry.h
Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/library/ActiveMQCPP.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/library/ActiveMQCPP.cpp?rev=1089673&r1=1089672&r2=1089673&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/library/ActiveMQCPP.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/library/ActiveMQCPP.cpp Wed Apr 6 23:31:21 2011
@@ -67,15 +67,8 @@ void ActiveMQCPP::shutdownLibrary() {
// Shutdown the IdGenerator Kernel
IdGenerator::shutdown();
- // Clear out all registered WireFormat Factories.
- WireFormatRegistry::getInstance().unregisterFactory("openwire");
- WireFormatRegistry::getInstance().unregisterFactory("stomp");
-
- // Clear out all regsitered Transport factories
- TransportRegistry::getInstance().unregisterFactory("tcp");
- TransportRegistry::getInstance().unregisterFactory("ssl");
- TransportRegistry::getInstance().unregisterFactory("mock");
- TransportRegistry::getInstance().unregisterFactory("failover");
+ WireFormatRegistry::getInstance().unregisterAllFactories();
+ TransportRegistry::getInstance().unregisterAllFactories();
// Now it should be safe to shutdown Decaf.
decaf::lang::Runtime::shutdownRuntime();
@@ -91,7 +84,6 @@ void ActiveMQCPP::registerWireFormats()
"openwire", new wireformat::openwire::OpenWireFormatFactory() );
WireFormatRegistry::getInstance().registerFactory(
"stomp", new wireformat::stomp::StompWireFormatFactory() );
-
}
////////////////////////////////////////////////////////////////////////////////
@@ -108,5 +100,4 @@ void ActiveMQCPP::registerTransports() {
"mock", new MockTransportFactory() );
TransportRegistry::getInstance().registerFactory(
"failover", new FailoverTransportFactory() );
-
}
Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/transport/TransportRegistry.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/transport/TransportRegistry.cpp?rev=1089673&r1=1089672&r2=1089673&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/transport/TransportRegistry.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/transport/TransportRegistry.cpp Wed Apr 6 23:31:21 2011
@@ -32,16 +32,10 @@ TransportRegistry::TransportRegistry() :
////////////////////////////////////////////////////////////////////////////////
TransportRegistry::~TransportRegistry() {
- std::vector<TransportFactory*> factories = this->registry.values();
-
- std::vector<TransportFactory*>::iterator iter = factories.begin();
-
- for( ; iter != factories.end(); ++iter ) {
- delete *iter;
- }
-
- this->registry.clear();
- }
+ try{
+ this->unregisterAllFactories();
+ } catch(...) {}
+}
////////////////////////////////////////////////////////////////////////////////
TransportFactory* TransportRegistry::findFactory( const std::string& name ) const {
@@ -79,6 +73,19 @@ void TransportRegistry::unregisterFactor
}
////////////////////////////////////////////////////////////////////////////////
+void TransportRegistry::unregisterAllFactories() {
+
+ std::vector<TransportFactory*> factories = this->registry.values();
+ std::vector<TransportFactory*>::iterator iter = factories.begin();
+
+ for( ; iter != factories.end(); ++iter ) {
+ delete *iter;
+ }
+
+ this->registry.clear();
+}
+
+////////////////////////////////////////////////////////////////////////////////
std::vector<std::string> TransportRegistry::getTransportNames() const {
return this->registry.keySet();
}
Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/transport/TransportRegistry.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/transport/TransportRegistry.h?rev=1089673&r1=1089672&r2=1089673&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/transport/TransportRegistry.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/transport/TransportRegistry.h Wed Apr 6 23:31:21 2011
@@ -99,6 +99,11 @@ namespace transport {
void unregisterFactory( const std::string& name );
/**
+ * Removes all Factories and deletes the instances of the Factory objects.
+ */
+ void unregisterAllFactories();
+
+ /**
* Retrieves a list of the names of all the Registered Transport's in this
* Registry.
*
Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/wireformat/WireFormatRegistry.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/wireformat/WireFormatRegistry.cpp?rev=1089673&r1=1089672&r2=1089673&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/wireformat/WireFormatRegistry.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/wireformat/WireFormatRegistry.cpp Wed Apr 6 23:31:21 2011
@@ -32,16 +32,10 @@ WireFormatRegistry::WireFormatRegistry()
////////////////////////////////////////////////////////////////////////////////
WireFormatRegistry::~WireFormatRegistry() {
- std::vector<WireFormatFactory*> factories = this->registry.values();
-
- std::vector<WireFormatFactory*>::iterator iter = factories.begin();
-
- for( ; iter != factories.end(); ++iter ) {
- delete *iter;
- }
-
- this->registry.clear();
- }
+ try {
+ this->unregisterAllFactories();
+ } catch(...) {}
+}
////////////////////////////////////////////////////////////////////////////////
WireFormatFactory* WireFormatRegistry::findFactory( const std::string& name ) const {
@@ -79,6 +73,19 @@ void WireFormatRegistry::unregisterFacto
}
////////////////////////////////////////////////////////////////////////////////
+void WireFormatRegistry::unregisterAllFactories() {
+
+ std::vector<WireFormatFactory*> factories = this->registry.values();
+ std::vector<WireFormatFactory*>::iterator iter = factories.begin();
+
+ for( ; iter != factories.end(); ++iter ) {
+ delete *iter;
+ }
+
+ this->registry.clear();
+}
+
+////////////////////////////////////////////////////////////////////////////////
std::vector<std::string> WireFormatRegistry::getWireFormatNames() const {
return this->registry.keySet();
}
Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/wireformat/WireFormatRegistry.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/wireformat/WireFormatRegistry.h?rev=1089673&r1=1089672&r2=1089673&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/wireformat/WireFormatRegistry.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/wireformat/WireFormatRegistry.h Wed Apr 6 23:31:21 2011
@@ -99,6 +99,11 @@ namespace wireformat {
void unregisterFactory( const std::string& name );
/**
+ * Removes all Factories and deletes the instances of the Factory objects.
+ */
+ void unregisterAllFactories();
+
+ /**
* Retrieves a list of the names of all the Registered WireFormat's in this
* Registry.
*