Return-Path: Delivered-To: apmail-activemq-commits-archive@www.apache.org Received: (qmail 2185 invoked from network); 5 Dec 2010 17:02:46 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 5 Dec 2010 17:02:46 -0000 Received: (qmail 43088 invoked by uid 500); 5 Dec 2010 17:02:46 -0000 Delivered-To: apmail-activemq-commits-archive@activemq.apache.org Received: (qmail 43023 invoked by uid 500); 5 Dec 2010 17:02:45 -0000 Mailing-List: contact commits-help@activemq.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@activemq.apache.org Delivered-To: mailing list commits@activemq.apache.org Received: (qmail 43015 invoked by uid 99); 5 Dec 2010 17:02:45 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 05 Dec 2010 17:02:45 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.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; Sun, 05 Dec 2010 17:02:42 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 7236823888BD; Sun, 5 Dec 2010 17:02:20 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1042386 - in /activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf: internal/net/ internal/net/ssl/ net/ net/ssl/ Date: Sun, 05 Dec 2010 17:02:20 -0000 To: commits@activemq.apache.org From: tabish@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20101205170220.7236823888BD@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: tabish Date: Sun Dec 5 17:02:19 2010 New Revision: 1042386 URL: http://svn.apache.org/viewvc?rev=1042386&view=rev Log: fix for: https://issues.apache.org/jira/browse/AMQCPP-330 Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/Network.cpp activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/Network.h activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/ssl/DefaultSSLContext.cpp activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/ServerSocketFactory.cpp activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/SocketFactory.cpp activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/ssl/SSLServerSocketFactory.cpp activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/ssl/SSLSocketFactory.cpp Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/Network.cpp URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/Network.cpp?rev=1042386&r1=1042385&r2=1042386&view=diff ============================================================================== --- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/Network.cpp (original) +++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/Network.cpp Sun Dec 5 17:02:19 2010 @@ -17,8 +17,10 @@ #include "Network.h" +#include #include #include +#include #include #include @@ -46,7 +48,20 @@ namespace net{ ResourceLifecycleManager resources; Mutex lock; + StlList shutdownTasks; + ~NetworkData() { + try{ + std::auto_ptr< Iterator > iter( shutdownTasks.iterator() ); + while( iter->hasNext() ) { + Runnable* task = iter->next(); + try{ + task->run(); + delete task; + } catch(...) {} + } + } catch(...) {} + } }; }}} @@ -105,3 +120,10 @@ void Network::shutdownNetworking() { // Destory the Network Runtime. delete Network::networkRuntime; } + +//////////////////////////////////////////////////////////////////////////////// +void Network::addShutdownTask( decaf::lang::Runnable* task ) { + if( task != NULL ) { + this->data->shutdownTasks.add( task ); + } +} Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/Network.h URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/Network.h?rev=1042386&r1=1042385&r2=1042386&view=diff ============================================================================== --- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/Network.h (original) +++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/Network.h Sun Dec 5 17:02:19 2010 @@ -82,6 +82,24 @@ namespace net { this->addNetworkResource( resource ); } + /** + * Register a Runnable to be called when the Network Runtime is shutdown to provide + * a chance to cleanup any data or references that could cause problems should the + * Network Runtime be re-initialized. The Runnable pointer ownership is transfered + * to the NetworkRuntime to guarantee the timing of resource cleanup. + * + * The cleanup tasks are run at a critical time in the Shutdown process and should + * be as simple as possible and make every attempt to no throw any exceptions. If an + * exception is thrown it is ignored and processing of the next task is started. + * + * The tasks should not assume that any Network resources are still available and + * should execute as quickly as possible. + * + * @param task + * Pointer to a Runnable object that will now be owned by the Network Runtime. + */ + void addShutdownTask( decaf::lang::Runnable* task ); + public: // Static methods /** Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/ssl/DefaultSSLContext.cpp URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/ssl/DefaultSSLContext.cpp?rev=1042386&r1=1042385&r2=1042386&view=diff ============================================================================== --- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/ssl/DefaultSSLContext.cpp (original) +++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/net/ssl/DefaultSSLContext.cpp Sun Dec 5 17:02:19 2010 @@ -18,6 +18,7 @@ #include "DefaultSSLContext.h" #include +#include #include #include @@ -36,6 +37,25 @@ using namespace decaf::internal::net::ss using namespace decaf::internal::net::ssl::openssl; //////////////////////////////////////////////////////////////////////////////// +namespace { + + class ShutdownTask : public decaf::lang::Runnable { + private: + + SSLContext** defaultRef; + + public: + + ShutdownTask( SSLContext** defaultRef ) : defaultRef( defaultRef ) {} + virtual ~ShutdownTask() {} + + virtual void run() { + *defaultRef = NULL; + } + }; +} + +//////////////////////////////////////////////////////////////////////////////// SSLContext* DefaultSSLContext::defaultSSLContext = NULL; //////////////////////////////////////////////////////////////////////////////// @@ -65,6 +85,7 @@ SSLContext* DefaultSSLContext::getContex // Store the default in the Network Runtime, it will be destroyed when the // Application calls the Decaf shutdownLibrary method. Network::getNetworkRuntime()->addAsResource( defaultSSLContext ); + Network::getNetworkRuntime()->addShutdownTask( new ShutdownTask( &defaultSSLContext ) ); } #endif Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/ServerSocketFactory.cpp URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/ServerSocketFactory.cpp?rev=1042386&r1=1042385&r2=1042386&view=diff ============================================================================== --- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/ServerSocketFactory.cpp (original) +++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/ServerSocketFactory.cpp Sun Dec 5 17:02:19 2010 @@ -17,6 +17,7 @@ #include "ServerSocketFactory.h" +#include #include #include #include @@ -30,6 +31,25 @@ using namespace decaf::util::concurrent; using namespace decaf::internal::net; //////////////////////////////////////////////////////////////////////////////// +namespace { + + class ShutdownTask : public decaf::lang::Runnable { + private: + + ServerSocketFactory** defaultRef; + + public: + + ShutdownTask( ServerSocketFactory** defaultRef ) : defaultRef( defaultRef ) {} + virtual ~ShutdownTask() {} + + virtual void run() { + *defaultRef = NULL; + } + }; +} + +//////////////////////////////////////////////////////////////////////////////// ServerSocketFactory* ServerSocketFactory::defaultFactory = NULL; //////////////////////////////////////////////////////////////////////////////// @@ -57,6 +77,7 @@ ServerSocketFactory* ServerSocketFactory if( defaultFactory == NULL ) { defaultFactory = new DefaultServerSocketFactory(); networkRuntime->addAsResource( defaultFactory ); + networkRuntime->addShutdownTask( new ShutdownTask( &defaultFactory ) ); } } Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/SocketFactory.cpp URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/SocketFactory.cpp?rev=1042386&r1=1042385&r2=1042386&view=diff ============================================================================== --- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/SocketFactory.cpp (original) +++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/SocketFactory.cpp Sun Dec 5 17:02:19 2010 @@ -16,6 +16,7 @@ */ #include +#include #include #include @@ -27,6 +28,25 @@ using namespace decaf::util::concurrent; using namespace decaf::internal::net; //////////////////////////////////////////////////////////////////////////////// +namespace { + + class ShutdownTask : public decaf::lang::Runnable { + private: + + SocketFactory** defaultRef; + + public: + + ShutdownTask( SocketFactory** defaultRef ) : defaultRef( defaultRef ) {} + virtual ~ShutdownTask() {} + + virtual void run() { + *defaultRef = NULL; + } + }; +} + +//////////////////////////////////////////////////////////////////////////////// SocketFactory* SocketFactory::defaultFactory = NULL; //////////////////////////////////////////////////////////////////////////////// @@ -54,6 +74,7 @@ SocketFactory* SocketFactory::getDefault if( defaultFactory == NULL ) { defaultFactory = new DefaultSocketFactory(); networkRuntime->addAsResource( defaultFactory ); + networkRuntime->addShutdownTask( new ShutdownTask( &defaultFactory ) ); } } Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/ssl/SSLServerSocketFactory.cpp URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/ssl/SSLServerSocketFactory.cpp?rev=1042386&r1=1042385&r2=1042386&view=diff ============================================================================== --- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/ssl/SSLServerSocketFactory.cpp (original) +++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/ssl/SSLServerSocketFactory.cpp Sun Dec 5 17:02:19 2010 @@ -18,9 +18,8 @@ #include "SSLServerSocketFactory.h" #include - +#include #include - #include #include @@ -32,6 +31,25 @@ using namespace decaf::internal::net; using namespace decaf::internal::net::ssl; //////////////////////////////////////////////////////////////////////////////// +namespace { + + class ShutdownTask : public decaf::lang::Runnable { + private: + + ServerSocketFactory** defaultRef; + + public: + + ShutdownTask( ServerSocketFactory** defaultRef ) : defaultRef( defaultRef ) {} + virtual ~ShutdownTask() {} + + virtual void run() { + *defaultRef = NULL; + } + }; +} + +//////////////////////////////////////////////////////////////////////////////// ServerSocketFactory* SSLServerSocketFactory::defaultFactory = NULL; //////////////////////////////////////////////////////////////////////////////// @@ -69,6 +87,8 @@ ServerSocketFactory* SSLServerSocketFact // Runtime is shutdown. netRuntime->addAsResource( defaultFactory ); } + + netRuntime->addShutdownTask( new ShutdownTask( &defaultFactory ) ); } return defaultFactory; Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/ssl/SSLSocketFactory.cpp URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/ssl/SSLSocketFactory.cpp?rev=1042386&r1=1042385&r2=1042386&view=diff ============================================================================== --- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/ssl/SSLSocketFactory.cpp (original) +++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/ssl/SSLSocketFactory.cpp Sun Dec 5 17:02:19 2010 @@ -17,18 +17,38 @@ #include "SSLSocketFactory.h" +#include #include - #include #include using namespace decaf; +using namespace decaf::lang; using namespace decaf::net; using namespace decaf::net::ssl; using namespace decaf::internal::net; using namespace decaf::internal::net::ssl; //////////////////////////////////////////////////////////////////////////////// +namespace { + + class ShutdownTask : public decaf::lang::Runnable { + private: + + SocketFactory** defaultRef; + + public: + + ShutdownTask( SocketFactory** defaultRef ) : defaultRef( defaultRef ) {} + virtual ~ShutdownTask() {} + + virtual void run() { + *defaultRef = NULL; + } + }; +} + +//////////////////////////////////////////////////////////////////////////////// SocketFactory* SSLSocketFactory::defaultSocketFactory = NULL; //////////////////////////////////////////////////////////////////////////////// @@ -64,8 +84,10 @@ SocketFactory* SSLSocketFactory::getDefa // Since we created this one we need to make sure it is destroyed when the Network // Runtime is shutdown. - Network::getNetworkRuntime()->addAsResource( defaultSocketFactory ); + netRuntime->addAsResource( defaultSocketFactory ); } + + netRuntime->addShutdownTask( new ShutdownTask( &defaultSocketFactory ) ); } return defaultSocketFactory;