activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nmitt...@apache.org
Subject svn commit: r507367 - in /activemq/activemq-cpp/trunk/activemq-cpp/src/main: ./ activemq/connector/stomp/commands/ activemq/transport/
Date Wed, 14 Feb 2007 02:57:41 GMT
Author: nmittler
Date: Tue Feb 13 18:57:40 2007
New Revision: 507367

URL: http://svn.apache.org/viewvc?view=rev&rev=507367
Log:
[AMQCPP-30] adding command logging transport.  Can enable via url with commandTracingEnabled=true

Added:
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/transport/LoggingTransport.cpp
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/transport/LoggingTransport.h
Modified:
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/Makefile.am
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/connector/stomp/commands/AbstractCommand.h
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/transport/TcpTransportFactory.cpp

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/Makefile.am
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/Makefile.am?view=diff&rev=507367&r1=507366&r2=507367
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/Makefile.am (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/Makefile.am Tue Feb 13 18:57:40 2007
@@ -79,6 +79,7 @@
     activemq/transport/TransportFactoryMap.cpp \
     activemq/transport/TcpTransportFactory.cpp \
     activemq/transport/TransportFilter.cpp \
+    activemq/transport/LoggingTransport.cpp \
     activemq/util/StringTokenizer.cpp \
     activemq/util/Guid.cpp \
     activemq/util/Endian.cpp \
@@ -250,6 +251,7 @@
     activemq/transport/Response.h \
     activemq/transport/CommandIOException.h \
     activemq/transport/TransportFilter.h \
+    activemq/transport/LoggingTransport.h \
     activemq/util/Endian.h \
     activemq/util/Number.h \
     activemq/util/Config.h \

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/connector/stomp/commands/AbstractCommand.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/connector/stomp/commands/AbstractCommand.h?view=diff&rev=507367&r1=507366&r2=507367
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/connector/stomp/commands/AbstractCommand.h
(original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/connector/stomp/commands/AbstractCommand.h
Tue Feb 13 18:57:40 2007
@@ -119,14 +119,13 @@
         virtual std::string toString() const {
             
             std::ostringstream ostream;
-            ostream << "Class: " << typeid(*this).name() << std::endl;
+            ostream << "<STOMP-COMMAND class=" << typeid(*this).name() <<
">" << std::endl;
             
             std::string propertyString = getProperties().toString();
-            ostream << "Properties: " << propertyString << std::endl;
-            
-            ostream << "Body: " << std::endl;
+            ostream << propertyString;
             
             const std::vector<unsigned char>& bytes = getBytes();
+            ostream << "<STOMP-BODY numBytes=" << (int)bytes.size() <<
">";
             
             for( std::size_t ix=0; ix<bytes.size(); ++ix ){
                 char c = (char)bytes[ix];
@@ -136,6 +135,9 @@
                 else 
                     ostream << "[" << (int)(unsigned char)c << "]";
             }
+            
+            ostream << "</STOMP-BODY>";
+            ostream << std::endl << "</STOMP-COMMAND>";
             
             return ostream.str();
         }

Added: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/transport/LoggingTransport.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/transport/LoggingTransport.cpp?view=auto&rev=507367
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/transport/LoggingTransport.cpp
(added)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/transport/LoggingTransport.cpp
Tue Feb 13 18:57:40 2007
@@ -0,0 +1,92 @@
+/* 
+ * 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 "LoggingTransport.h"
+ 
+using namespace std;
+using namespace activemq;
+using namespace activemq::transport;
+
+LOGCMS_INITIALIZE( logger, LoggingTransport, "activemq.io.LoggingTransport")
+
+//////////////////////////////////////////////////////////////////////////////// 
+LoggingTransport::LoggingTransport( Transport* next, const bool own )
+:
+    TransportFilter( next, own )
+{
+}
+
+//////////////////////////////////////////////////////////////////////////////// 
+void LoggingTransport::onCommand( Command* command ) {
+    
+    ostringstream ostream;
+    ostream << "*** BEGIN RECEIVED ASYNCHRONOUS COMMAND ***" << endl;
+    ostream << command->toString() << endl;
+    ostream << "*** END RECEIVED ASYNCHRONOUS COMMAND ***";
+    
+    LOGCMS_INFO( logger, ostream.str() );  
+    
+    // Delegate to the base class.
+    TransportFilter::onCommand( command );
+}
+   
+////////////////////////////////////////////////////////////////////////////////      
+void LoggingTransport::oneway( Command* command ) 
+    throw(CommandIOException, exceptions::UnsupportedOperationException) 
+{
+    try {
+        ostringstream ostream;
+        ostream << "*** BEGIN SENDING ONEWAY COMMAND ***" << endl;
+        ostream << command->toString() << endl;
+        ostream << "*** END SENDING ONEWAY COMMAND ***";
+        
+        LOGCMS_INFO( logger, ostream.str() );  
+        
+        // Delegate to the base class.
+        TransportFilter::oneway( command );
+    } 
+    AMQ_CATCH_RETHROW( CommandIOException )
+    AMQ_CATCH_RETHROW( exceptions::UnsupportedOperationException )
+    AMQ_CATCHALL_THROW( CommandIOException )
+}
+   
+////////////////////////////////////////////////////////////////////////////////      
+Response* LoggingTransport::request( Command* command ) 
+    throw(CommandIOException, exceptions::UnsupportedOperationException)
+{
+    try {        
+        
+        // Delegate to the base class.
+        Response* response = TransportFilter::request( command );
+        
+        ostringstream ostream;
+        ostream << "*** SENDING REQUEST COMMAND ***" << endl;
+        ostream << command->toString() << endl;
+        ostream << "*** RECEIVED RESPONSE COMMAND ***" << endl;
+        ostream << ( response == NULL? "NULL" : response->toString() );
+        
+        LOGCMS_INFO( logger, ostream.str() );
+        
+        return response;
+    } 
+    AMQ_CATCH_RETHROW( CommandIOException )
+    AMQ_CATCH_RETHROW( exceptions::UnsupportedOperationException )
+    AMQ_CATCHALL_THROW( CommandIOException )
+}
+
+
+

Added: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/transport/LoggingTransport.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/transport/LoggingTransport.h?view=auto&rev=507367
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/transport/LoggingTransport.h
(added)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/transport/LoggingTransport.h
Tue Feb 13 18:57:40 2007
@@ -0,0 +1,74 @@
+/*
+ * 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 ACTIVEMQ_TRANSPORT_LOGGINGTRANSPORT_H_
+#define ACTIVEMQ_TRANSPORT_LOGGINGTRANSPORT_H_
+
+#include <activemq/transport/TransportFilter.h>
+#include <activemq/logger/LoggerDefines.h>
+
+namespace activemq {
+namespace transport {
+    
+    /**
+     * A transport filter that logs commands as they are sent/received.
+     */
+    class LoggingTransport : public TransportFilter
+    { 
+    private:
+    
+        LOGCMS_DECLARE(logger) 
+        
+    public:
+  
+        /**
+         * Constructor.
+         * @param next - the next Transport in the chain
+         * @param own - true if this filter owns the next and should delete it
+         */
+        LoggingTransport( Transport* next, const bool own = true );
+        
+        virtual ~LoggingTransport(){};
+        
+        /**
+         * Event handler for the receipt of a command.
+         * @param command - the received command object.
+         */
+        virtual void onCommand( Command* command );
+        
+        /**
+         * Sends a one-way command.  Does not wait for any response from the
+         * broker.
+         * @param command the command to be sent.
+         * @throws CommandIOException if an exception occurs during writing of
+         * the command.
+         * @throws UnsupportedOperationException if this method is not implemented
+         * by this transport.
+         */
+        virtual void oneway( Command* command ) throw(CommandIOException, exceptions::UnsupportedOperationException);
+        
+        /**
+         * Not supported by this class - throws an exception.
+         * @param command the command that is sent as a request
+         * @throws UnsupportedOperationException.
+         */
+        virtual Response* request( Command* command ) throw(CommandIOException, exceptions::UnsupportedOperationException);
+
+    };
+    
+}}
+#endif /*ACTIVEMQ_TRANSPORT_LOGGINGTRANSPORT_H_*/

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/transport/TcpTransportFactory.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/transport/TcpTransportFactory.cpp?view=diff&rev=507367&r1=507366&r2=507367
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/transport/TcpTransportFactory.cpp
(original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/transport/TcpTransportFactory.cpp
Tue Feb 13 18:57:40 2007
@@ -19,6 +19,7 @@
 
 #include <activemq/transport/TcpTransport.h>
 #include <activemq/transport/ResponseCorrelator.h>
+#include <activemq/transport/LoggingTransport.h>
 
 using namespace activemq;
 using namespace activemq::transport;
@@ -53,11 +54,16 @@
     
         Transport* transport = new TcpTransport( 
             properties, factory->createTransport( properties ) );
-
+        
         // Create a response correlator.  This will wrap around our 
         // transport and manage its lifecycle - we don't need the 
         // internal transport anymore, so we can reuse its pointer.
         transport = new ResponseCorrelator( transport );
+        
+        // If command tracing was enabled, wrap the transport with a logging transport.
+        if( properties.getProperty( "commandTracingEnabled", "false" ) == "true" ) {
+            transport = new LoggingTransport( transport );
+        }
         
         return transport;
     }



Mime
View raw message