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/10/19 15:15:17 UTC
svn commit: r586425 - in
/activemq/activemq-cpp/trunk/src/main/activemq/connector/openwire:
OpenWireFormat.cpp OpenWireFormat.h
Author: tabish
Date: Fri Oct 19 06:15:16 2007
New Revision: 586425
URL: http://svn.apache.org/viewvc?rev=586425&view=rev
Log:
https://issues.apache.org/activemq/browse/AMQCPP-142
Added the support for negotiating the version of openwire which now support V1 and V2
Modified:
activemq/activemq-cpp/trunk/src/main/activemq/connector/openwire/OpenWireFormat.cpp
activemq/activemq-cpp/trunk/src/main/activemq/connector/openwire/OpenWireFormat.h
Modified: activemq/activemq-cpp/trunk/src/main/activemq/connector/openwire/OpenWireFormat.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/activemq/connector/openwire/OpenWireFormat.cpp?rev=586425&r1=586424&r2=586425&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/activemq/connector/openwire/OpenWireFormat.cpp (original)
+++ activemq/activemq-cpp/trunk/src/main/activemq/connector/openwire/OpenWireFormat.cpp Fri Oct 19 06:15:16 2007
@@ -29,6 +29,7 @@
#include <activemq/connector/openwire/marshal/MarshalAware.h>
#include <activemq/connector/openwire/marshal/DataStreamMarshaller.h>
#include <activemq/connector/openwire/marshal/v2/MarshallerFactory.h>
+#include <activemq/connector/openwire/marshal/v1/MarshallerFactory.h>
using namespace std;
using namespace activemq;
@@ -41,7 +42,6 @@
using namespace activemq::connector::openwire;
using namespace activemq::connector::openwire::commands;
using namespace activemq::connector::openwire::marshal;
-using namespace activemq::connector::openwire::marshal::v2;
using namespace activemq::connector::openwire::utils;
////////////////////////////////////////////////////////////////////////////////
@@ -56,36 +56,76 @@
// Fill in that DataStreamMarshallers collection
dataMarshallers.resize( 256 );
- MarshallerFactory().configure( this );
// Generate an ID
this->id = Guid::createGUIDString();
// Set defaults for initial WireFormat negotiation
+ this->version = 0;
this->stackTraceEnabled = false;
this->cacheEnabled = false;
this->tcpNoDelayEnabled = false;
this->tightEncodingEnabled = false;
this->sizePrefixDisabled = false;
+
+ // Set to Default as lowest common denominator, then we will try
+ // and move up to the prefered when the wireformat is negotiated.
+ this->setVersion( DEFAULT_VERSION );
}
////////////////////////////////////////////////////////////////////////////////
OpenWireFormat::~OpenWireFormat()
{
try {
+ this->destroyMarshalers();
+ delete preferedWireFormatInfo;
+ }
+ AMQ_CATCH_NOTHROW( ActiveMQException )
+ AMQ_CATCHALL_NOTHROW()
+}
- for( size_t i = 0; i < dataMarshallers.size(); ++i )
- {
+////////////////////////////////////////////////////////////////////////////////
+void OpenWireFormat::destroyMarshalers() {
+ try {
+ for( size_t i = 0; i < dataMarshallers.size(); ++i ) {
delete dataMarshallers[i];
+ dataMarshallers[i] = NULL;
}
-
- delete preferedWireFormatInfo;
}
AMQ_CATCH_NOTHROW( ActiveMQException )
AMQ_CATCHALL_NOTHROW()
}
////////////////////////////////////////////////////////////////////////////////
+void OpenWireFormat::setVersion( int version ) throw ( IllegalArgumentException ) {
+
+ std::cout << "OpenWireFormat::setVersion - called for with V" << version << std::endl;
+ if( version == this->getVersion() ){
+ return;
+ }
+
+ // Clear old marshalers in preperation for the new set.
+ this->destroyMarshalers();
+ this->version = version;
+
+ switch( this->version ){
+ case 1:
+ v1::MarshallerFactory().configure( this );
+ std::cout << "setting to V1" << std::endl;
+ break;
+ case 2:
+ v2::MarshallerFactory().configure( this );
+ std::cout << "setting to V2" << std::endl;
+ break;
+ default:
+ throw IllegalArgumentException(
+ __FILE__, __LINE__,
+ "OpenWireFormat::setVersion - "
+ "Given Version: %d , is not supported", version );
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////
void OpenWireFormat::addMarshaller( DataStreamMarshaller* marshaller )
{
unsigned char type = marshaller->getDataStructureType();
@@ -175,7 +215,7 @@
transport::Command* OpenWireFormat::unmarshal( io::DataInputStream* dis )
throw ( io::IOException ) {
- try{
+ try {
if( !sizePrefixDisabled ) {
dis->readInt();
Modified: activemq/activemq-cpp/trunk/src/main/activemq/connector/openwire/OpenWireFormat.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/activemq/connector/openwire/OpenWireFormat.h?rev=586425&r1=586424&r2=586425&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/activemq/connector/openwire/OpenWireFormat.h (original)
+++ activemq/activemq-cpp/trunk/src/main/activemq/connector/openwire/OpenWireFormat.h Fri Oct 19 06:15:16 2007
@@ -24,6 +24,7 @@
#include <activemq/connector/openwire/utils/BooleanStream.h>
#include <activemq/util/Properties.h>
#include <activemq/exceptions/IllegalStateException.h>
+#include <activemq/exceptions/IllegalArgumentException.h>
namespace activemq{
namespace connector{
@@ -31,8 +32,7 @@
class DataStreamMarshaller;
- class OpenWireFormat : public wireformat::WireFormat
- {
+ class OpenWireFormat : public wireformat::WireFormat {
public:
/**
@@ -198,9 +198,7 @@
* Set the current Wireformat Version
* @param version - int that identifies the version
*/
- void setVersion( int version ) {
- this->version = version;
- }
+ void setVersion( int version ) throw ( exceptions::IllegalArgumentException );
/**
* Checks if the cacheEnabled flag is on
@@ -264,10 +262,20 @@
commands::DataStructure* doUnmarshal( io::DataInputStream* dis )
throw ( io::IOException );
+ /**
+ * Cleans up all registered Marshallers and empties the dataMarshallers
+ * vector. This should be called before a reconfiguration of the version
+ * marshallers, or on destruction of this object
+ */
+ void destroyMarshalers();
+
protected:
// Declared here to make life easier.
static const unsigned char NULL_TYPE;
+
+ // V1 if the default version we start at.
+ static const int DEFAULT_VERSION = 1;
private: