|
activemq-cpp-3.4.0
|
00001 /* 00002 * Licensed to the Apache Software Foundation (ASF) under one or more 00003 * contributor license agreements. See the NOTICE file distributed with 00004 * this work for additional information regarding copyright ownership. 00005 * The ASF licenses this file to You under the Apache License, Version 2.0 00006 * (the "License"); you may not use this file except in compliance with 00007 * the License. You may obtain a copy of the License at 00008 * 00009 * http://www.apache.org/licenses/LICENSE-2.0 00010 * 00011 * Unless required by applicable law or agreed to in writing, software 00012 * distributed under the License is distributed on an "AS IS" BASIS, 00013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00014 * See the License for the specific language governing permissions and 00015 * limitations under the License. 00016 */ 00017 00018 #ifndef _ACTIVEMQ_TANSPORT_MOCK_MOCKTRANSPORT_H_ 00019 #define _ACTIVEMQ_TANSPORT_MOCK_MOCKTRANSPORT_H_ 00020 00021 #include <activemq/util/Config.h> 00022 #include <activemq/exceptions/ActiveMQException.h> 00023 #include <activemq/transport/Transport.h> 00024 #include <activemq/transport/TransportListener.h> 00025 #include <activemq/transport/DefaultTransportListener.h> 00026 #include <activemq/transport/mock/ResponseBuilder.h> 00027 #include <activemq/transport/mock/InternalCommandListener.h> 00028 #include <activemq/wireformat/WireFormat.h> 00029 00030 #include <decaf/lang/Thread.h> 00031 #include <decaf/lang/Pointer.h> 00032 #include <decaf/util/concurrent/Concurrent.h> 00033 #include <decaf/util/concurrent/atomic/AtomicInteger.h> 00034 #include <decaf/util/concurrent/CountDownLatch.h> 00035 00036 #include <cms/Message.h> 00037 00038 #include <map> 00039 #include <set> 00040 00041 namespace activemq{ 00042 namespace transport{ 00043 namespace mock{ 00044 00045 using decaf::lang::Pointer; 00046 using activemq::commands::Command; 00047 using activemq::commands::Response; 00048 00061 class AMQCPP_API MockTransport : public Transport { 00062 private: 00063 00064 Pointer<ResponseBuilder> responseBuilder; 00065 Pointer<wireformat::WireFormat> wireFormat; 00066 TransportListener* outgoingListener; 00067 TransportListener* listener; 00068 decaf::util::concurrent::atomic::AtomicInteger nextCommandId; 00069 InternalCommandListener internalListener; 00070 static MockTransport* instance; 00071 00072 std::string name; 00073 00074 bool failOnSendMessage; 00075 int numSentMessageBeforeFail; 00076 int numSentMessages; 00077 bool failOnReceiveMessage; 00078 int numReceivedMessageBeforeFail; 00079 int numReceivedMessages; 00080 bool failOnKeepAliveSends; 00081 int numSentKeepAlivesBeforeFail; 00082 int numSentKeepAlives; 00083 00084 bool failOnStart; 00085 bool failOnStop; 00086 bool failOnClose; 00087 00088 private: 00089 00090 MockTransport( const MockTransport& ); 00091 MockTransport operator= ( const MockTransport& ); 00092 00093 public: 00094 00095 MockTransport( const Pointer<wireformat::WireFormat>& wireFormat, 00096 const Pointer<ResponseBuilder>& responseBuilder ); 00097 00098 virtual ~MockTransport() {} 00099 00100 static MockTransport* getInstance() { 00101 return instance; 00102 } 00103 00109 virtual void fireCommand( const Pointer<Command>& command ){ 00110 if( listener != NULL ){ 00111 listener->onCommand( command ); 00112 } 00113 } 00114 00122 virtual void fireException( const exceptions::ActiveMQException& ex ){ 00123 if( listener != NULL ){ 00124 listener->onException( ex ); 00125 } 00126 } 00127 00134 void setResponseBuilder( const Pointer<ResponseBuilder>& responseBuilder ){ 00135 this->responseBuilder = responseBuilder; 00136 } 00137 00138 00145 virtual void setOutgoingListener( TransportListener* listener ){ 00146 outgoingListener = listener; 00147 } 00148 00154 Pointer<wireformat::WireFormat> getWireFormat() const { 00155 return this->wireFormat; 00156 } 00157 00158 public: // Transport Methods 00159 00160 virtual void oneway( const Pointer<Command>& command ); 00161 00162 virtual Pointer<Response> request( const Pointer<Command>& command ); 00163 00164 virtual Pointer<Response> request( const Pointer<Command>& command, unsigned int timeout ); 00165 00166 virtual void setWireFormat( const Pointer<wireformat::WireFormat>& wireFormat AMQCPP_UNUSED ) {} 00167 00168 virtual void setTransportListener( TransportListener* listener ){ 00169 this->listener = listener; 00170 } 00171 00172 virtual TransportListener* getTransportListener() const { 00173 return this->listener; 00174 } 00175 00176 virtual void start(); 00177 00178 virtual void stop(); 00179 00180 virtual void close(); 00181 00182 virtual Transport* narrow( const std::type_info& typeId ) { 00183 if( typeid( *this ) == typeId ) { 00184 return this; 00185 } 00186 00187 return NULL; 00188 } 00189 00190 virtual bool isFaultTolerant() const { 00191 return false; 00192 } 00193 00194 virtual bool isConnected() const { 00195 return true; 00196 } 00197 00198 virtual bool isClosed() const { 00199 return false; 00200 } 00201 00202 virtual std::string getRemoteAddress() const { 00203 return ""; 00204 } 00205 00206 virtual void reconnect( const decaf::net::URI& uri AMQCPP_UNUSED ) {} 00207 00208 public: // Property Getters and Setters 00209 00210 std::string getName() const { 00211 return this->name; 00212 } 00213 00214 void setName( const std::string& name ) { 00215 this->name = name; 00216 } 00217 00218 bool isFailOnSendMessage() const { 00219 return this->failOnSendMessage; 00220 } 00221 00222 void setFailOnSendMessage( bool value ) { 00223 this->failOnSendMessage = value; 00224 } 00225 00226 int getNumSentMessageBeforeFail() const { 00227 return this->numSentMessageBeforeFail; 00228 } 00229 00230 void setNumSentMessageBeforeFail( int value ) { 00231 this->numSentMessageBeforeFail = value; 00232 } 00233 00234 int getNumSentMessages() const { 00235 return this->numSentMessages; 00236 } 00237 00238 void setNumSentMessages( int value ) { 00239 this->numSentMessages = value; 00240 } 00241 00242 bool isFailOnReceiveMessage() const { 00243 return this->failOnReceiveMessage; 00244 } 00245 00246 void setFailOnReceiveMessage( bool value ) { 00247 this->failOnReceiveMessage = value; 00248 } 00249 00250 int getNumReceivedMessageBeforeFail() const { 00251 return this->numReceivedMessageBeforeFail; 00252 } 00253 00254 void setNumReceivedMessageBeforeFail( int value ) { 00255 this->numReceivedMessageBeforeFail = value; 00256 } 00257 00258 int getNumReceivedMessages() const { 00259 return this->numReceivedMessages; 00260 } 00261 00262 void setNumReceivedMessages( int value ) { 00263 this->numReceivedMessages = value; 00264 } 00265 00266 bool isFailOnKeepAliveSends() const { 00267 return this->failOnKeepAliveSends; 00268 } 00269 00270 void setFailOnKeepAliveSends( bool value ) { 00271 this->failOnKeepAliveSends = value; 00272 } 00273 00274 int getNumSentKeepAlivesBeforeFail() const { 00275 return this->numSentKeepAlivesBeforeFail; 00276 } 00277 00278 void setNumSentKeepAlivesBeforeFail( int value ) { 00279 this->numSentKeepAlivesBeforeFail = value; 00280 } 00281 00282 int getNumSentKeepAlives() const { 00283 return this->numSentKeepAlives; 00284 } 00285 00286 void setNumSentKeepAlives( int value ) { 00287 this->numSentKeepAlives = value; 00288 } 00289 00290 bool isFailOnStart() const { 00291 return this->failOnReceiveMessage; 00292 } 00293 00294 void setFailOnStart( bool value ) { 00295 this->failOnReceiveMessage = value; 00296 } 00297 00298 bool isFailOnStop() const { 00299 return this->failOnStop; 00300 } 00301 00302 void setFailOnStop( bool value ) { 00303 this->failOnStop = value; 00304 } 00305 00306 bool isFailOnClose() const { 00307 return this->failOnClose; 00308 } 00309 00310 void setFailOnClose( bool value ) { 00311 this->failOnClose = value; 00312 } 00313 00314 virtual bool isReconnectSupported() const { 00315 return false; 00316 } 00317 00318 virtual bool isUpdateURIsSupported() const { 00319 return false; 00320 } 00321 00322 virtual void updateURIs( bool rebalance AMQCPP_UNUSED, 00323 const decaf::util::List<decaf::net::URI>& uris AMQCPP_UNUSED ) { 00324 throw decaf::io::IOException(); 00325 } 00326 00327 }; 00328 00329 }}} 00330 00331 #endif /*_ACTIVEMQ_TANSPORT_MOCK_MOCKTRANSPORT_H_*/