activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r507932 - /activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/transport/ResponseCorrelator.cpp
Date Thu, 15 Feb 2007 14:01:34 GMT
Author: tabish
Date: Thu Feb 15 06:01:33 2007
New Revision: 507932

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

Modified:
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/transport/ResponseCorrelator.cpp

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/transport/ResponseCorrelator.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/transport/ResponseCorrelator.cpp?view=diff&rev=507932&r1=507931&r2=507932
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/transport/ResponseCorrelator.cpp
(original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/transport/ResponseCorrelator.cpp
Thu Feb 15 06:01:33 2007
@@ -22,12 +22,12 @@
 
 ////////////////////////////////////////////////////////////////////////////////
 unsigned int ResponseCorrelator::getNextCommandId() throw ( exceptions::ActiveMQException
){
-    
+
     try{
         synchronized( &commandIdMutex ){
             return ++nextCommandId;
         }
-        
+
         // Should never get here, but some compilers aren't
         // smart enough to figure out we'll never get here.
         return 0;
@@ -35,35 +35,35 @@
     AMQ_CATCH_RETHROW( exceptions::ActiveMQException )
     AMQ_CATCHALL_THROW( exceptions::ActiveMQException )
 }
-       
-//////////////////////////////////////////////////////////////////////////////// 
+
+////////////////////////////////////////////////////////////////////////////////
 ResponseCorrelator::ResponseCorrelator( Transport* next, const bool own )
 :
     TransportFilter( next, own )
-{            
+{
     nextCommandId = 0;
-            
-            // Default max response wait time to 3 seconds.
+
+    // Default max response wait time to 3 seconds.
     maxResponseWaitTime = 3000;
-    
-    // Start in the closed state. 
+
+    // Start in the closed state.
     closed = true;
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 ResponseCorrelator::~ResponseCorrelator(){
-    
+
     // Close the transport and destroy it.
     close();
 
     // Don't do anything with the future responses -
-    // they should be cleaned up by each requester.                        
+    // they should be cleaned up by each requester.
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 unsigned long ResponseCorrelator::getMaxResponseWaitTime() const{
     return maxResponseWaitTime;
-}           
+}
 
 ////////////////////////////////////////////////////////////////////////////////
 void ResponseCorrelator::setMaxResponseWaitTime( const unsigned long milliseconds ){
@@ -71,19 +71,19 @@
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-void ResponseCorrelator::oneway( Command* command ) 
+void ResponseCorrelator::oneway( Command* command )
     throw( CommandIOException, exceptions::UnsupportedOperationException )
 {
-    
+
     try{
         command->setCommandId( getNextCommandId() );
         command->setResponseRequired( false );
-        
+
         if( closed || next == NULL ){
             throw CommandIOException( __FILE__, __LINE__,
                 "transport already closed" );
         }
-        
+
         next->oneway( command );
     }
     AMQ_CATCH_RETHROW( exceptions::UnsupportedOperationException )
@@ -93,45 +93,45 @@
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-Response* ResponseCorrelator::request( Command* command ) 
+Response* ResponseCorrelator::request( Command* command )
     throw( CommandIOException, exceptions::UnsupportedOperationException )
 {
-    
+
     try{
         command->setCommandId( getNextCommandId() );
         command->setResponseRequired( true );
-        
+
         // Add a future response object to the map indexed by this
         // command id.
-        FutureResponse* futureResponse = 
+        FutureResponse* futureResponse =
            new FutureResponse();
-          
+
         synchronized( &mapMutex ){
             requestMap[command->getCommandId()] = futureResponse;
-        }                                
-        
+        }
+
         // Wait to be notified of the response via the futureResponse
         // object.
         Response* response = NULL;
         synchronized( futureResponse ){
-            
+
             // Send the request.
             next->oneway( command );
-            
+
             // Wait for the response to come in.
-            futureResponse->wait( maxResponseWaitTime );                             
         
-            
+            futureResponse->wait( maxResponseWaitTime );
+
             // Get the response.
-            response = futureResponse->getResponse();                    
-        }                              
-                        
+            response = futureResponse->getResponse();
+        }
+
         // Perform cleanup on the map.
         synchronized( &mapMutex ){
-            
+
             // We've done our waiting - get this thing out
             // of the map.
             requestMap.erase( command->getCommandId() );
-            
+
             // Destroy the futureResponse.  It is safe to
             // do this now because the other thread only
             // accesses the futureResponse within a lock on
@@ -139,14 +139,14 @@
             delete futureResponse;
             futureResponse = NULL;
         }
-            
-        if( response == NULL ){                                        
-            
+
+        if( response == NULL ){
+
             throw CommandIOException( __FILE__, __LINE__,
                 "response from futureResponse was invalid" );
         }
-        
-        return response;                
+
+        return response;
     }
     AMQ_CATCH_RETHROW( exceptions::UnsupportedOperationException )
     AMQ_CATCH_RETHROW( CommandIOException )
@@ -156,49 +156,49 @@
 
 ////////////////////////////////////////////////////////////////////////////////
 void ResponseCorrelator::onCommand( Command* command ){
-    
+
     // Let's see if the incoming command is a response.
-    Response* response = 
+    Response* response =
        dynamic_cast<Response*>( command );
-       
+
     if( response == NULL ){
-        
+
         // It's a non-response - just notify the listener.
         fire( command );
         return;
     }
-        
+
     // It is a response - let's correlate ...
     synchronized( &mapMutex ){
-        
+
         // Look the future request up based on the correlation id.
         std::map<unsigned int, FutureResponse*>::iterator iter =
             requestMap.find( response->getCorrelationId() );
         if( iter == requestMap.end() ){
-            
+
             // This is not terrible - just log it.
-            printf("ResponseCorrelator::onCommand() - received unknown response for request:
%d\n", 
+            printf("ResponseCorrelator::onCommand() - received unknown response for request:
%d\n",
                 response->getCorrelationId() );
             return;
         }
-        
+
         // Get the future response (if it's in the map, it's not NULL).
         FutureResponse* futureResponse = NULL;
         futureResponse = iter->second;
-        
+
         // If it's an exception response, notify the exception listener.
-        ExceptionResponse* exResp = 
+        ExceptionResponse* exResp =
             dynamic_cast<ExceptionResponse*>( response );
         if( exResp != NULL ){
             const BrokerError* error = exResp->getException();
             fire( *error );
         }
-        
+
         synchronized( futureResponse ){
-            
+
             // Set the response property in the future response.
             futureResponse->setResponse( response );
-            
+
             // Notify all waiting for this response.
             futureResponse->notifyAll();
         }
@@ -211,7 +211,7 @@
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-void ResponseCorrelator::setTransportExceptionListener( 
+void ResponseCorrelator::setTransportExceptionListener(
     TransportExceptionListener* listener )
 {
     this->exceptionListener = listener;
@@ -219,43 +219,43 @@
 
 ////////////////////////////////////////////////////////////////////////////////
 void ResponseCorrelator::start() throw( cms::CMSException ){
-    
+
     /**
      * We're already started.
      */
     if( !closed ){
         return;
     }
-    
+
     if( commandlistener == NULL ){
         throw exceptions::ActiveMQException( __FILE__, __LINE__,
             "commandListener is invalid" );
     }
-    
+
     if( exceptionListener == NULL ){
         throw exceptions::ActiveMQException( __FILE__, __LINE__,
             "exceptionListener is invalid" );
     }
-    
+
     if( next == NULL ){
         throw exceptions::ActiveMQException( __FILE__, __LINE__,
             "next transport is NULL" );
     }
-    
+
     // Start the delegate transport object.
     next->start();
-    
+
     // Mark it as open.
     closed = false;
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 void ResponseCorrelator::close() throw( cms::CMSException ){
-    
+
     if( !closed && next != NULL ){
         next->close();
     }
-    
+
     closed = true;
 }
 



Mime
View raw message