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, const Pointer<ResponseBuilder> responseBuilder); 00096 00097 virtual ~MockTransport() {} 00098 00099 static MockTransport* getInstance() { 00100 return instance; 00101 } 00102 00108 virtual void fireCommand(const Pointer<Command> command) { 00109 if (listener != NULL) { 00110 listener->onCommand(command); 00111 } 00112 } 00113 00121 virtual void fireException(const exceptions::ActiveMQException& ex) { 00122 if (listener != NULL) { 00123 listener->onException(ex); 00124 } 00125 } 00126 00133 void setResponseBuilder(const Pointer<ResponseBuilder> responseBuilder) { 00134 this->responseBuilder = responseBuilder; 00135 } 00136 00143 virtual void setOutgoingListener(TransportListener* listener) { 00144 outgoingListener = listener; 00145 } 00146 00152 Pointer<wireformat::WireFormat> getWireFormat() const { 00153 return this->wireFormat; 00154 } 00155 00156 public: // Transport Methods 00157 00158 virtual void oneway(const Pointer<Command> command); 00159 00160 virtual Pointer<FutureResponse> asyncRequest(const Pointer<Command> command, 00161 const Pointer<ResponseCallback> responseCallback); 00162 00163 virtual Pointer<Response> request(const Pointer<Command> command); 00164 00165 virtual Pointer<Response> request(const Pointer<Command> command, unsigned int timeout); 00166 00167 virtual void setWireFormat(const Pointer<wireformat::WireFormat> wireFormat AMQCPP_UNUSED) {} 00168 00169 virtual void setTransportListener(TransportListener* listener) { 00170 this->listener = listener; 00171 } 00172 00173 virtual TransportListener* getTransportListener() const { 00174 return this->listener; 00175 } 00176 00177 virtual void start(); 00178 00179 virtual void stop(); 00180 00181 virtual void close(); 00182 00183 virtual Transport* narrow(const std::type_info& typeId) { 00184 if (typeid( *this ) == typeId) { 00185 return this; 00186 } 00187 00188 return NULL; 00189 } 00190 00191 virtual bool isFaultTolerant() const { 00192 return false; 00193 } 00194 00195 virtual bool isConnected() const { 00196 return true; 00197 } 00198 00199 virtual bool isClosed() const { 00200 return false; 00201 } 00202 00203 virtual std::string getRemoteAddress() const { 00204 return ""; 00205 } 00206 00207 virtual void reconnect(const decaf::net::URI& uri AMQCPP_UNUSED) {} 00208 00209 public: // Property Getters and Setters 00210 00211 std::string getName() const { 00212 return this->name; 00213 } 00214 00215 void setName(const std::string& name) { 00216 this->name = name; 00217 } 00218 00219 bool isFailOnSendMessage() const { 00220 return this->failOnSendMessage; 00221 } 00222 00223 void setFailOnSendMessage(bool value) { 00224 this->failOnSendMessage = value; 00225 } 00226 00227 int getNumSentMessageBeforeFail() const { 00228 return this->numSentMessageBeforeFail; 00229 } 00230 00231 void setNumSentMessageBeforeFail(int value) { 00232 this->numSentMessageBeforeFail = value; 00233 } 00234 00235 int getNumSentMessages() const { 00236 return this->numSentMessages; 00237 } 00238 00239 void setNumSentMessages(int value) { 00240 this->numSentMessages = value; 00241 } 00242 00243 bool isFailOnReceiveMessage() const { 00244 return this->failOnReceiveMessage; 00245 } 00246 00247 void setFailOnReceiveMessage(bool value) { 00248 this->failOnReceiveMessage = value; 00249 } 00250 00251 int getNumReceivedMessageBeforeFail() const { 00252 return this->numReceivedMessageBeforeFail; 00253 } 00254 00255 void setNumReceivedMessageBeforeFail(int value) { 00256 this->numReceivedMessageBeforeFail = value; 00257 } 00258 00259 int getNumReceivedMessages() const { 00260 return this->numReceivedMessages; 00261 } 00262 00263 void setNumReceivedMessages(int value) { 00264 this->numReceivedMessages = value; 00265 } 00266 00267 bool isFailOnKeepAliveSends() const { 00268 return this->failOnKeepAliveSends; 00269 } 00270 00271 void setFailOnKeepAliveSends(bool value) { 00272 this->failOnKeepAliveSends = value; 00273 } 00274 00275 int getNumSentKeepAlivesBeforeFail() const { 00276 return this->numSentKeepAlivesBeforeFail; 00277 } 00278 00279 void setNumSentKeepAlivesBeforeFail(int value) { 00280 this->numSentKeepAlivesBeforeFail = value; 00281 } 00282 00283 int getNumSentKeepAlives() const { 00284 return this->numSentKeepAlives; 00285 } 00286 00287 void setNumSentKeepAlives(int value) { 00288 this->numSentKeepAlives = value; 00289 } 00290 00291 bool isFailOnStart() const { 00292 return this->failOnReceiveMessage; 00293 } 00294 00295 void setFailOnStart(bool value) { 00296 this->failOnReceiveMessage = value; 00297 } 00298 00299 bool isFailOnStop() const { 00300 return this->failOnStop; 00301 } 00302 00303 void setFailOnStop(bool value) { 00304 this->failOnStop = value; 00305 } 00306 00307 bool isFailOnClose() const { 00308 return this->failOnClose; 00309 } 00310 00311 void setFailOnClose(bool value) { 00312 this->failOnClose = value; 00313 } 00314 00315 virtual bool isReconnectSupported() const { 00316 return false; 00317 } 00318 00319 virtual bool isUpdateURIsSupported() const { 00320 return false; 00321 } 00322 00323 virtual void updateURIs(bool rebalance AMQCPP_UNUSED, 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_*/
1.6.1