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/05/14 23:03:46 UTC

svn commit: r944468 - in /activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/transport/tcp: SslTransport.cpp SslTransport.h SslTransportFactory.cpp TcpTransport.cpp TcpTransport.h TcpTransportFactory.cpp

Author: tabish
Date: Fri May 14 21:03:46 2010
New Revision: 944468

URL: http://svn.apache.org/viewvc?rev=944468&view=rev
Log:
https://issues.apache.org/activemq/browse/AMQCPP-140

Refactored connect logic in the TcpTransport and SslTransport to make connection an explicit operation.  Fix SslTransport so it doesn't try and delete the SocketFactory returned from SSLSocketFactory::getDefault since that is owned by the factory.

Modified:
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/transport/tcp/SslTransport.cpp
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/transport/tcp/SslTransport.h
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/transport/tcp/SslTransportFactory.cpp
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/transport/tcp/TcpTransport.cpp
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/transport/tcp/TcpTransport.h
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/transport/tcp/TcpTransportFactory.cpp

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/transport/tcp/SslTransport.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/transport/tcp/SslTransport.cpp?rev=944468&r1=944467&r2=944468&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/transport/tcp/SslTransport.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/transport/tcp/SslTransport.cpp Fri May 14 21:03:46 2010
@@ -24,9 +24,6 @@
 #include <decaf/lang/exceptions/NullPointerException.h>
 #include <decaf/lang/exceptions/IllegalArgumentException.h>
 
-#include <memory>
-
-using namespace std;
 using namespace activemq;
 using namespace activemq::io;
 using namespace activemq::transport;
@@ -41,16 +38,7 @@ using namespace decaf::lang;
 using namespace decaf::lang::exceptions;
 
 ////////////////////////////////////////////////////////////////////////////////
-SslTransport::SslTransport( const decaf::net::URI& uri,
-                            const decaf::util::Properties& properties,
-                            const Pointer<Transport>& next ) :
-   TcpTransport( uri, properties, next ) {
-}
-
-////////////////////////////////////////////////////////////////////////////////
-SslTransport::SslTransport( const decaf::util::Properties& properties,
-                            const Pointer<Transport>& next ) :
-    TcpTransport( properties, next ) {
+SslTransport::SslTransport( const Pointer<Transport>& next ) : TcpTransport( next ) {
 }
 
 ////////////////////////////////////////////////////////////////////////////////
@@ -61,7 +49,8 @@ SslTransport::~SslTransport() {
 Socket* SslTransport::createSocket() {
 
     try {
-        std::auto_ptr<SocketFactory> factory( SSLSocketFactory::getDefault() );
+        // The pointer returned from getDefault is owned by the SSLSocketFactory
+        SocketFactory* factory = SSLSocketFactory::getDefault();
         return factory->createSocket();
     }
     DECAF_CATCH_RETHROW( IOException )

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/transport/tcp/SslTransport.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/transport/tcp/SslTransport.h?rev=944468&r1=944467&r2=944468&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/transport/tcp/SslTransport.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/transport/tcp/SslTransport.h Fri May 14 21:03:46 2010
@@ -42,26 +42,12 @@ namespace tcp {
     public:
 
         /**
-         * Creates a new instance of the SslTransport, the Broker URI is assumed
-         * to be set in the property "transport.uri".
+         * Creates a new instance of the SslTransport, the transport will not attempt to
+         * connect to a remote host until the connect method is called.
          *
-         * @param properties the configuration properties for this transport
          * @param next the next transport in the chain
          */
-        SslTransport( const decaf::util::Properties& properties,
-                      const Pointer<Transport>& next );
-
-        /**
-         * Creates a new instance of the SslTransport, the uri instance specifies the
-         * host and port to connect to.
-         *
-         * @param uri - The URI containing the host to connect to.
-         * @param properties the configuration properties for this transport
-         * @param next the next transport in the chain
-         */
-        SslTransport( const decaf::net::URI& uri,
-                      const decaf::util::Properties& properties,
-                      const Pointer<Transport>& next );
+        SslTransport( const Pointer<Transport>& next );
 
         virtual ~SslTransport();
 
@@ -77,6 +63,7 @@ namespace tcp {
          */
         virtual void configureSocket( decaf::net::Socket* socket, decaf::util::Properties& properties );
 
+
     };
 
 }}}

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/transport/tcp/SslTransportFactory.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/transport/tcp/SslTransportFactory.cpp?rev=944468&r1=944467&r2=944468&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/transport/tcp/SslTransportFactory.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/transport/tcp/SslTransportFactory.cpp Fri May 14 21:03:46 2010
@@ -50,7 +50,9 @@ Pointer<Transport> SslTransportFactory::
     try {
 
         Pointer<Transport> transport( new SslTransport(
-            location, properties, Pointer<Transport>( new IOTransport( wireFormat ) ) ) );
+            Pointer<Transport>( new IOTransport( wireFormat ) ) ) );
+
+        transport.dynamicCast<SslTransport>()->connect( location, properties );
 
         if( properties.getProperty( "trnasport.useInactivityMonitor", "true" ) == "true" ) {
             transport.reset( new InactivityMonitor( transport, properties, wireFormat ) );

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/transport/tcp/TcpTransport.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/transport/tcp/TcpTransport.cpp?rev=944468&r1=944467&r2=944468&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/transport/tcp/TcpTransport.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/transport/tcp/TcpTransport.cpp Fri May 14 21:03:46 2010
@@ -42,27 +42,9 @@ using namespace decaf::lang;
 using namespace decaf::lang::exceptions;
 
 ////////////////////////////////////////////////////////////////////////////////
-TcpTransport::TcpTransport( const decaf::net::URI& uri,
-                            const decaf::util::Properties& properties,
-                            const Pointer<Transport>& next )
-:   TransportFilter( next ), connectTimeout( 0 ), closed( false ) {
+TcpTransport::TcpTransport( const Pointer<Transport>& next ) :
+    TransportFilter( next ), connectTimeout( 0 ), closed( false ) {
 
-    this->initialize( uri, properties );
-}
-
-////////////////////////////////////////////////////////////////////////////////
-TcpTransport::TcpTransport( const decaf::util::Properties& properties,
-                            const Pointer<Transport>& next )
-:   TransportFilter( next ), connectTimeout( 0 ), closed( false ) {
-
-    if( !properties.hasProperty( "transport.uri" ) ) {
-        throw ActiveMQException(
-            __FILE__, __LINE__,
-            "TcpTransport::TcpTransport - "
-            "No URI set for this transport to connect to.");
-    }
-
-    this->initialize( URI( properties.getProperty( "transport.uri" ) ), properties );
 }
 
 ////////////////////////////////////////////////////////////////////////////////
@@ -97,8 +79,8 @@ void TcpTransport::close() throw( decaf:
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-void TcpTransport::initialize( const decaf::net::URI& uri,
-                               const decaf::util::Properties& properties ) {
+void TcpTransport::connect( const decaf::net::URI& uri,
+                            const decaf::util::Properties& properties ) {
 
     try {
 

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/transport/tcp/TcpTransport.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/transport/tcp/TcpTransport.h?rev=944468&r1=944467&r2=944468&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/transport/tcp/TcpTransport.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/transport/tcp/TcpTransport.h Fri May 14 21:03:46 2010
@@ -80,31 +80,32 @@ namespace tcp{
     public:
 
         /**
-         * Creates a new instance of the TcpTransport, the Broker URI is assumed
-         * to be set in the property "transport.uri".
+         * Creates a new instance of a TcpTransport, the transport is left unconnected
+         * and is in a unusable state until the connect method is called.
          *
-         * @param properties the configuration properties for this transport
-         * @param next the next transport in the chain
+         * @param next
+         *      The next transport in the chain
          */
-        TcpTransport( const decaf::util::Properties& properties,
-                      const Pointer<Transport>& next );
+        TcpTransport( const Pointer<Transport>& next );
+
+        virtual ~TcpTransport();
 
         /**
-         * Creates a new instance of the TcpTransport, the uri instance specifies the
-         * host and port to connect to.
-         *
-         * @param uri - The URI containing the host to connect to.
-         * @param properties the configuration properties for this transport
-         * @param next the next transport in the chain
+         * Creates a Socket and configures it before attempting to connect to the location specified
+         * by the URI passed in.  The Socket is configured using parameters in the properties that
+         * are passed to this method.
+         *
+         * @param uri
+         *      The URI that the Transport is to connect to once initialized.
+         * @param properties
+         *      The Properties that have been parsed from the URI or from configuration files.
          */
-        TcpTransport( const decaf::net::URI& uri,
-                      const decaf::util::Properties& properties,
-                      const Pointer<Transport>& next );
-
-        virtual ~TcpTransport();
+        void connect( const decaf::net::URI& uri,
+                      const decaf::util::Properties& properties );
 
         /**
          * Delegates to the superclass and then closes the socket.
+         *
          * @throws IOException if errors occur.
          */
         virtual void close() throw( decaf::io::IOException );
@@ -169,12 +170,6 @@ namespace tcp{
         virtual void configureSocket( decaf::net::Socket* socket,
                                       const decaf::util::Properties& properties );
 
-    private:
-
-        void initialize( const decaf::net::URI& uri,
-                         const decaf::util::Properties& properties );
-
-
     };
 
 }}}

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/transport/tcp/TcpTransportFactory.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/transport/tcp/TcpTransportFactory.cpp?rev=944468&r1=944467&r2=944468&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/transport/tcp/TcpTransportFactory.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/transport/tcp/TcpTransportFactory.cpp Fri May 14 21:03:46 2010
@@ -96,7 +96,10 @@ Pointer<Transport> TcpTransportFactory::
     try {
 
         Pointer<Transport> transport( new TcpTransport(
-            location, properties, Pointer<Transport>( new IOTransport( wireFormat ) ) ) );
+            Pointer<Transport>( new IOTransport( wireFormat ) ) ) );
+
+        // Initialize the Transport, creates Sockets and configures defaults.
+        transport.dynamicCast<TcpTransport>()->connect( location, properties );
 
         if( properties.getProperty( "trnasport.useInactivityMonitor", "true" ) == "true" ) {
             transport.reset( new InactivityMonitor( transport, properties, wireFormat ) );