|
activemq-cpp-3.3.0
|
00001 00018 #ifndef _ACTIVEMQ_WIREFORMAT_OPENWIRE_OPENWIREFORMAT_H_ 00019 #define _ACTIVEMQ_WIREFORMAT_OPENWIRE_OPENWIREFORMAT_H_ 00020 00021 #include <activemq/util/Config.h> 00022 #include <activemq/commands/WireFormatInfo.h> 00023 #include <activemq/commands/DataStructure.h> 00024 #include <activemq/wireformat/WireFormat.h> 00025 #include <activemq/wireformat/openwire/utils/BooleanStream.h> 00026 #include <decaf/lang/Pointer.h> 00027 #include <decaf/util/Properties.h> 00028 #include <decaf/util/concurrent/atomic/AtomicBoolean.h> 00029 #include <decaf/lang/exceptions/IllegalStateException.h> 00030 #include <decaf/lang/exceptions/IllegalArgumentException.h> 00031 #include <memory> 00032 00033 namespace activemq{ 00034 namespace wireformat{ 00035 namespace openwire{ 00036 00037 namespace marshal { 00038 class DataStreamMarshaller; 00039 } 00040 00041 using decaf::lang::Pointer; 00042 00043 class AMQCPP_API OpenWireFormat : public wireformat::WireFormat { 00044 protected: 00045 00046 // Declared here to make life easier. 00047 static const unsigned char NULL_TYPE; 00048 00049 // V1 if the default version we start at. 00050 static const int DEFAULT_VERSION; 00051 00052 // Defines the maximum supported openwire version 00053 static const int MAX_SUPPORTED_VERSION; 00054 00055 private: 00056 00057 // Configuration parameters 00058 decaf::util::Properties properties; 00059 00060 // Preferred WireFormatInfo 00061 Pointer<commands::WireFormatInfo> preferedWireFormatInfo; 00062 00063 // Marshalers 00064 std::vector< marshal::DataStreamMarshaller* > dataMarshallers; 00065 00066 // Uniquely Generated ID, initialize in the Ctor 00067 std::string id; 00068 00069 // Indicates when we are in the doUnmarshal call 00070 decaf::util::concurrent::atomic::AtomicBoolean receiving; 00071 00072 // WireFormat Data 00073 int version; 00074 bool stackTraceEnabled; 00075 bool tcpNoDelayEnabled; 00076 bool cacheEnabled; 00077 int cacheSize; 00078 bool tightEncodingEnabled; 00079 bool sizePrefixDisabled; 00080 long long maxInactivityDuration; 00081 long long maxInactivityDurationInitialDelay; 00082 00083 public: 00084 00089 OpenWireFormat( const decaf::util::Properties& properties ); 00090 00091 virtual ~OpenWireFormat(); 00092 00096 virtual bool hasNegotiator() const { 00097 return true; 00098 } 00099 00103 virtual Pointer<transport::Transport> createNegotiator( 00104 const Pointer<transport::Transport>& transport ); 00105 00111 void addMarshaller( marshal::DataStreamMarshaller* marshaler ); 00112 00116 virtual void marshal( const Pointer<commands::Command>& command, 00117 const activemq::transport::Transport* transport, 00118 decaf::io::DataOutputStream* out ); 00119 00123 virtual Pointer<commands::Command> unmarshal( const activemq::transport::Transport* transport, 00124 decaf::io::DataInputStream* in ); 00125 00126 public: 00127 00135 virtual int tightMarshalNestedObject1( commands::DataStructure* object, 00136 utils::BooleanStream* bs ); 00137 00147 void tightMarshalNestedObject2( commands::DataStructure* o, 00148 decaf::io::DataOutputStream* ds, 00149 utils::BooleanStream* bs ); 00150 00160 commands::DataStructure* tightUnmarshalNestedObject( decaf::io::DataInputStream* dis, 00161 utils::BooleanStream* bs ); 00162 00172 commands::DataStructure* looseUnmarshalNestedObject( decaf::io::DataInputStream* dis ); 00173 00182 void looseMarshalNestedObject( commands::DataStructure* o, 00183 decaf::io::DataOutputStream* dataOut ); 00184 00194 void renegotiateWireFormat( const commands::WireFormatInfo& info ); 00195 00204 void setPreferedWireFormatInfo( const Pointer<commands::WireFormatInfo>& info ); 00205 00210 const Pointer<commands::WireFormatInfo>& getPreferedWireFormatInfo() const { 00211 return this->preferedWireFormatInfo; 00212 } 00213 00218 bool isStackTraceEnabled() const { 00219 return stackTraceEnabled; 00220 } 00221 00226 void setStackTraceEnabled( bool stackTraceEnabled ) { 00227 this->stackTraceEnabled = stackTraceEnabled; 00228 } 00229 00234 bool isTcpNoDelayEnabled() const { 00235 return tcpNoDelayEnabled; 00236 } 00237 00242 void setTcpNoDelayEnabled( bool tcpNoDelayEnabled ) { 00243 this->tcpNoDelayEnabled = tcpNoDelayEnabled; 00244 } 00245 00250 int getVersion() const { 00251 return version; 00252 } 00253 00262 void setVersion( int version ); 00263 00269 virtual bool inReceive() const { 00270 return this->receiving.get(); 00271 } 00272 00277 bool isCacheEnabled() const { 00278 return cacheEnabled; 00279 } 00280 00285 void setCacheEnabled( bool cacheEnabled ) { 00286 this->cacheEnabled = cacheEnabled; 00287 } 00288 00293 int getCacheSize() const { 00294 return cacheSize; 00295 } 00296 00301 void setCacheSize( int value ) { 00302 this->cacheSize = value; 00303 } 00304 00309 bool isTightEncodingEnabled() const { 00310 return tightEncodingEnabled; 00311 } 00312 00317 void setTightEncodingEnabled( bool tightEncodingEnabled ) { 00318 this->tightEncodingEnabled = tightEncodingEnabled; 00319 } 00320 00325 bool isSizePrefixDisabled() const { 00326 return sizePrefixDisabled; 00327 } 00328 00333 void setSizePrefixDisabled( bool sizePrefixDisabled ) { 00334 this->sizePrefixDisabled = sizePrefixDisabled; 00335 } 00336 00341 long long getMaxInactivityDuration() const { 00342 return this->maxInactivityDuration; 00343 } 00344 00349 void setMaxInactivityDuration( long long value ) { 00350 this->maxInactivityDuration = value; 00351 } 00352 00357 long long getMaxInactivityDurationInitialDelay() const { 00358 return this->maxInactivityDurationInitialDelay; 00359 } 00360 00365 void setMaxInactivityDurationInitialDelay( long long value ) { 00366 this->maxInactivityDurationInitialDelay = value; 00367 } 00368 00369 protected: 00370 00384 commands::DataStructure* doUnmarshal( decaf::io::DataInputStream* dis ); 00385 00391 void destroyMarshalers(); 00392 00393 }; 00394 00395 }}} 00396 00397 #endif /*_ACTIVEMQ_WIREFORMAT_OPENWIRE_OPENWIREFORMAT_H_*/