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 2010/12/05 18:02:20 UTC

svn commit: r1042386 - in /activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf: internal/net/ internal/net/ssl/ net/ net/ssl/

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 <decaf/lang/Runnable.h>
 #include <decaf/lang/Exception.h>
 #include <decaf/lang/exceptions/IllegalStateException.h>
+#include <decaf/util/StlList.h>
 #include <decaf/util/concurrent/Mutex.h>
 #include <decaf/internal/util/ResourceLifecycleManager.h>
 
@@ -46,7 +48,20 @@ namespace net{
 
         ResourceLifecycleManager resources;
         Mutex lock;
+        StlList<Runnable*> shutdownTasks;
 
+        ~NetworkData() {
+            try{
+                std::auto_ptr< Iterator<Runnable*> > 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 <decaf/io/IOException.h>
+#include <decaf/lang/Runnable.h>
 
 #include <decaf/security/SecureRandom.h>
 #include <decaf/internal/net/Network.h>
@@ -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 <decaf/lang/Runnable.h>
 #include <decaf/net/ServerSocket.h>
 #include <decaf/internal/net/DefaultServerSocketFactory.h>
 #include <decaf/io/IOException.h>
@@ -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 <decaf/net/SocketFactory.h>
 
+#include <decaf/lang/Runnable.h>
 #include <decaf/internal/net/DefaultSocketFactory.h>
 #include <decaf/internal/net/Network.h>
 
@@ -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 <decaf/io/IOException.h>
-
+#include <decaf/lang/Runnable.h>
 #include <decaf/internal/net/Network.h>
-
 #include <decaf/internal/net/ssl/DefaultSSLContext.h>
 #include <decaf/internal/net/ssl/DefaultSSLServerSocketFactory.h>
 
@@ -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 <decaf/lang/Runnable.h>
 #include <decaf/internal/net/Network.h>
-
 #include <decaf/internal/net/ssl/DefaultSSLContext.h>
 #include <decaf/internal/net/ssl/DefaultSSLSocketFactory.h>
 
 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;