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 2007/06/19 21:08:24 UTC
svn commit: r548825 - in /activemq/activemq-cpp/trunk/src/main/activemq:
connector/openwire/OpenWireResponseBuilder.h
connector/stomp/StompResponseBuilder.cpp
connector/stomp/StompResponseBuilder.h transport/MockTransport.h
Author: tabish
Date: Tue Jun 19 12:08:20 2007
New Revision: 548825
URL: http://svn.apache.org/viewvc?view=rev&rev=548825
Log:
https://issues.apache.org/activemq/browse/AMQCPP-130
Modified:
activemq/activemq-cpp/trunk/src/main/activemq/connector/openwire/OpenWireResponseBuilder.h
activemq/activemq-cpp/trunk/src/main/activemq/connector/stomp/StompResponseBuilder.cpp
activemq/activemq-cpp/trunk/src/main/activemq/connector/stomp/StompResponseBuilder.h
activemq/activemq-cpp/trunk/src/main/activemq/transport/MockTransport.h
Modified: activemq/activemq-cpp/trunk/src/main/activemq/connector/openwire/OpenWireResponseBuilder.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/activemq/connector/openwire/OpenWireResponseBuilder.h?view=diff&rev=548825&r1=548824&r2=548825
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/activemq/connector/openwire/OpenWireResponseBuilder.h (original)
+++ activemq/activemq-cpp/trunk/src/main/activemq/connector/openwire/OpenWireResponseBuilder.h Tue Jun 19 12:08:20 2007
@@ -36,6 +36,7 @@
virtual transport::Command* buildDisptachedMessage(
const cms::Message* message AMQCPP_UNUSED, long long consumerId AMQCPP_UNUSED )
{ return NULL; }
+ virtual void maintainConsumers( const transport::Command* command AMQCPP_UNUSED ) {}
};
Modified: activemq/activemq-cpp/trunk/src/main/activemq/connector/stomp/StompResponseBuilder.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/activemq/connector/stomp/StompResponseBuilder.cpp?view=diff&rev=548825&r1=548824&r2=548825
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/activemq/connector/stomp/StompResponseBuilder.cpp (original)
+++ activemq/activemq-cpp/trunk/src/main/activemq/connector/stomp/StompResponseBuilder.cpp Tue Jun 19 12:08:20 2007
@@ -19,6 +19,8 @@
#include <activemq/connector/stomp/commands/ConnectCommand.h>
#include <activemq/connector/stomp/commands/ConnectedCommand.h>
+#include <activemq/connector/stomp/commands/SubscribeCommand.h>
+#include <activemq/connector/stomp/commands/UnsubscribeCommand.h>
#include <activemq/util/Guid.h>
@@ -60,5 +62,35 @@
}
queue.push( resp );
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+transport::Command* StompResponseBuilder::buildDisptachedMessage(
+ const cms::Message* message, long long consumerId AMQCPP_UNUSED )
+{
+ // Just clone and return, stomp only looks at destinations, so it will
+ // find its consumers based on that.
+ return dynamic_cast<transport::Command*>( message->clone() );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void StompResponseBuilder::maintainConsumers( const transport::Command* command ) {
+
+ if( typeid( *command ) == typeid( commands::SubscribeCommand ) ) {
+ const commands::SubscribeCommand* sub =
+ dynamic_cast<const commands::SubscribeCommand*>( command );
+
+ // Register it, just use -1 for Id as Stomp doesn't do anything that uses
+ // consumer Ids.
+ this->registerConsumer( sub->getDestination(), -1 );
+ }
+ else if( typeid( *command ) == typeid( commands::UnsubscribeCommand ) ) {
+ const commands::UnsubscribeCommand* unsub =
+ dynamic_cast<const commands::UnsubscribeCommand*>( command );
+
+ // Register it, just use -1 for Id as Stomp doesn't do anything that uses
+ // consumer Ids.
+ this->unregisterConsumer( unsub->getDestination(), -1 );
}
}
Modified: activemq/activemq-cpp/trunk/src/main/activemq/connector/stomp/StompResponseBuilder.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/activemq/connector/stomp/StompResponseBuilder.h?view=diff&rev=548825&r1=548824&r2=548825
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/activemq/connector/stomp/StompResponseBuilder.h (original)
+++ activemq/activemq-cpp/trunk/src/main/activemq/connector/stomp/StompResponseBuilder.h Tue Jun 19 12:08:20 2007
@@ -34,8 +34,8 @@
virtual void buildIncomingCommands(
const transport::Command* cmd, util::Queue<transport::Command*>& queue );
virtual transport::Command* buildDisptachedMessage(
- const cms::Message* message AMQCPP_UNUSED, long long consumerId AMQCPP_UNUSED )
- { return NULL; }
+ const cms::Message* message, long long consumerId );
+ virtual void maintainConsumers( const transport::Command* command );
};
Modified: activemq/activemq-cpp/trunk/src/main/activemq/transport/MockTransport.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/activemq/transport/MockTransport.h?view=diff&rev=548825&r1=548824&r2=548825
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/activemq/transport/MockTransport.h (original)
+++ activemq/activemq-cpp/trunk/src/main/activemq/transport/MockTransport.h Tue Jun 19 12:08:20 2007
@@ -67,9 +67,7 @@
// unregisterConsumer whenever a Consumer is created and destroyed.
ConsumersMap consumersMap;
- public:
-
- virtual ~ResponseBuilder(){}
+ protected:
/**
* Called by a derived class whenever a consumer is created
@@ -78,7 +76,6 @@
*/
void registerConsumer( const std::string& destination,
long long consumerId ) {
-
consumersMap.insert( std::make_pair( destination, consumerId ) );
}
@@ -87,8 +84,8 @@
* @param destination - String name of the Destination
* @param consumerId - unique Id of the consumer.
*/
- void removeConsumer( const std::string& destination,
- long long consumerId ) {
+ void unregisterConsumer( const std::string& destination,
+ long long consumerId ) {
ConsumersMap::iterator iter =
consumersMap.lower_bound( destination );
@@ -100,13 +97,17 @@
}
}
+ public:
+
+ virtual ~ResponseBuilder(){}
+
/**
* Checks if the named Destination has any registered consumers
* @param destination - Name of the Destination in question
* @returns true if there are any consumers on this destination
*/
bool hasConsumers( const std::string& destination ) const {
- return consumersMap.lower_bound( destination ) != consumersMap.end();
+ return consumersMap.find( destination ) != consumersMap.end();
}
/**
@@ -159,6 +160,16 @@
virtual Command* buildDisptachedMessage( const cms::Message* message,
long long consumerId ) = 0;
+ /**
+ * Called to allow the response builder to maintain the internal list
+ * of consumers by checking if the passed command is a register or
+ * unregister of a consumer and add or remove it from the internal map
+ * as needed. If the passed command is not either of these actions
+ * the responseBuilder should do nothing.
+ * @param command - Transport Command to check for consumer add / remove
+ */
+ virtual void maintainConsumers( const Command* command ) = 0;
+
};
/**
@@ -218,11 +229,13 @@
// chance to destroy the command.
responseBuilder->buildIncomingCommands( command, inboundQueue );
+ // Allow the ResponseBuilder to add or remove consumers
+ responseBuilder->maintainConsumers( command );
+
// Chech for message loop, outgoing messages get sent in to
// consumers on the destination they are sent to.
cms::Message* message = dynamic_cast<cms::Message*>( command );
if( message != NULL ) {
-
std::string destination =
message->getCMSDestination()->toProviderString();