activemq-cpp-3.9.5
MockTransport.h
Go to the documentation of this file.
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18#ifndef _ACTIVEMQ_TANSPORT_MOCK_MOCKTRANSPORT_H_
19#define _ACTIVEMQ_TANSPORT_MOCK_MOCKTRANSPORT_H_
20
29
30#include <decaf/lang/Thread.h>
31#include <decaf/lang/Pointer.h>
35
36#include <cms/Message.h>
37
38#include <map>
39#include <set>
40
41namespace activemq{
42namespace transport{
43namespace mock{
44
45 using decaf::lang::Pointer;
46 using activemq::commands::Command;
47 using activemq::commands::Response;
48
61 class AMQCPP_API MockTransport: public Transport {
62 private:
63
64 Pointer<ResponseBuilder> responseBuilder;
66 TransportListener* outgoingListener;
67 TransportListener* listener;
69 InternalCommandListener internalListener;
70 static MockTransport* instance;
71
72 std::string name;
73
74 bool failOnSendMessage;
75 int numSentMessageBeforeFail;
76 int numSentMessages;
77 bool failOnReceiveMessage;
78 int numReceivedMessageBeforeFail;
79 int numReceivedMessages;
80 bool failOnKeepAliveSends;
81 int numSentKeepAlivesBeforeFail;
82 int numSentKeepAlives;
83
84 bool failOnStart;
85 bool failOnStop;
86 bool failOnClose;
87
88 private:
89
90 MockTransport(const MockTransport&);
91 MockTransport operator=(const MockTransport&);
92
93 public:
94
96
97 virtual ~MockTransport() {}
98
99 static MockTransport* getInstance() {
100 return instance;
101 }
102
108 virtual void fireCommand(const Pointer<Command> command) {
109 if (listener != NULL) {
110 listener->onCommand(command);
111 }
112 }
113
122 if (listener != NULL) {
123 listener->onException(ex);
124 }
125 }
126
133 void setResponseBuilder(const Pointer<ResponseBuilder> responseBuilder) {
134 this->responseBuilder = responseBuilder;
135 }
136
143 virtual void setOutgoingListener(TransportListener* listener) {
144 outgoingListener = listener;
145 }
146
153 return this->wireFormat;
154 }
155
156 public: // Transport Methods
157
158 virtual void oneway(const Pointer<Command> command);
159
161 const Pointer<ResponseCallback> responseCallback);
162
164
165 virtual Pointer<Response> request(const Pointer<Command> command, unsigned int timeout);
166
167 virtual void setWireFormat(const Pointer<wireformat::WireFormat> wireFormat AMQCPP_UNUSED) {}
168
169 virtual void setTransportListener(TransportListener* listener) {
170 this->listener = listener;
171 }
172
174 return this->listener;
175 }
176
177 virtual void start();
178
179 virtual void stop();
180
181 virtual void close();
182
183 virtual Transport* narrow(const std::type_info& typeId) {
184 if (typeid( *this ) == typeId) {
185 return this;
186 }
187
188 return NULL;
189 }
190
191 virtual bool isFaultTolerant() const {
192 return false;
193 }
194
195 virtual bool isConnected() const {
196 return true;
197 }
198
199 virtual bool isClosed() const {
200 return false;
201 }
202
203 virtual std::string getRemoteAddress() const {
204 return "";
205 }
206
207 virtual void reconnect(const decaf::net::URI& uri AMQCPP_UNUSED) {}
208
209 public: // Property Getters and Setters
210
211 std::string getName() const {
212 return this->name;
213 }
214
215 void setName(const std::string& name) {
216 this->name = name;
217 }
218
219 bool isFailOnSendMessage() const {
220 return this->failOnSendMessage;
221 }
222
223 void setFailOnSendMessage(bool value) {
224 this->failOnSendMessage = value;
225 }
226
228 return this->numSentMessageBeforeFail;
229 }
230
232 this->numSentMessageBeforeFail = value;
233 }
234
235 int getNumSentMessages() const {
236 return this->numSentMessages;
237 }
238
239 void setNumSentMessages(int value) {
240 this->numSentMessages = value;
241 }
242
244 return this->failOnReceiveMessage;
245 }
246
247 void setFailOnReceiveMessage(bool value) {
248 this->failOnReceiveMessage = value;
249 }
250
252 return this->numReceivedMessageBeforeFail;
253 }
254
256 this->numReceivedMessageBeforeFail = value;
257 }
258
260 return this->numReceivedMessages;
261 }
262
263 void setNumReceivedMessages(int value) {
264 this->numReceivedMessages = value;
265 }
266
268 return this->failOnKeepAliveSends;
269 }
270
271 void setFailOnKeepAliveSends(bool value) {
272 this->failOnKeepAliveSends = value;
273 }
274
276 return this->numSentKeepAlivesBeforeFail;
277 }
278
280 this->numSentKeepAlivesBeforeFail = value;
281 }
282
284 return this->numSentKeepAlives;
285 }
286
287 void setNumSentKeepAlives(int value) {
288 this->numSentKeepAlives = value;
289 }
290
291 bool isFailOnStart() const {
292 return this->failOnReceiveMessage;
293 }
294
295 void setFailOnStart(bool value) {
296 this->failOnReceiveMessage = value;
297 }
298
299 bool isFailOnStop() const {
300 return this->failOnStop;
301 }
302
303 void setFailOnStop(bool value) {
304 this->failOnStop = value;
305 }
306
307 bool isFailOnClose() const {
308 return this->failOnClose;
309 }
310
311 void setFailOnClose(bool value) {
312 this->failOnClose = value;
313 }
314
315 virtual bool isReconnectSupported() const {
316 return false;
317 }
318
319 virtual bool isUpdateURIsSupported() const {
320 return false;
321 }
322
323 virtual void updateURIs(bool rebalance AMQCPP_UNUSED, const decaf::util::List<decaf::net::URI>& uris AMQCPP_UNUSED) {
325 }
326
327 };
328
329}}}
330
331#endif /*_ACTIVEMQ_TANSPORT_MOCK_MOCKTRANSPORT_H_*/
#define AMQCPP_API
Definition Config.h:30
Definition ActiveMQException.h:35
Interface for a transport layer for command objects.
Definition Transport.h:60
A listener of asynchronous exceptions from a command transport object.
Definition TransportListener.h:38
Listens for Commands sent from the MockTransport.
Definition InternalCommandListener.h:46
void setFailOnReceiveMessage(bool value)
Definition MockTransport.h:247
int getNumReceivedMessageBeforeFail() const
Definition MockTransport.h:251
void setFailOnClose(bool value)
Definition MockTransport.h:311
MockTransport(const Pointer< wireformat::WireFormat > wireFormat, const Pointer< ResponseBuilder > responseBuilder)
void setFailOnSendMessage(bool value)
Definition MockTransport.h:223
bool isFailOnStart() const
Definition MockTransport.h:291
virtual Pointer< Response > request(const Pointer< Command > command)
Sends the given command to the broker and then waits for the response.
virtual void fireCommand(const Pointer< Command > command)
Fires a Command back through this transport to its registered CommandListener if there is one.
Definition MockTransport.h:108
virtual std::string getRemoteAddress() const
Definition MockTransport.h:203
virtual bool isFaultTolerant() const
Is this Transport fault tolerant, meaning that it will reconnect to a broker on disconnect.
Definition MockTransport.h:191
void setNumSentKeepAlivesBeforeFail(int value)
Definition MockTransport.h:279
virtual void setOutgoingListener(TransportListener *listener)
Sets a Listener that gets notified for every command that would have been sent by this transport to t...
Definition MockTransport.h:143
virtual bool isReconnectSupported() const
Definition MockTransport.h:315
void setFailOnKeepAliveSends(bool value)
Definition MockTransport.h:271
virtual ~MockTransport()
Definition MockTransport.h:97
virtual void setWireFormat(const Pointer< wireformat::WireFormat > wireFormat AMQCPP_UNUSED)
Sets the WireFormat instance to use.
Definition MockTransport.h:167
int getNumSentKeepAlives() const
Definition MockTransport.h:283
void setName(const std::string &name)
Definition MockTransport.h:215
void setNumReceivedMessages(int value)
Definition MockTransport.h:263
int getNumReceivedMessages() const
Definition MockTransport.h:259
bool isFailOnReceiveMessage() const
Definition MockTransport.h:243
int getNumSentMessageBeforeFail() const
Definition MockTransport.h:227
void setNumSentMessages(int value)
Definition MockTransport.h:239
int getNumSentMessages() const
Definition MockTransport.h:235
std::string getName() const
Definition MockTransport.h:211
void setNumSentKeepAlives(int value)
Definition MockTransport.h:287
void setFailOnStart(bool value)
Definition MockTransport.h:295
virtual TransportListener * getTransportListener() const
Gets the observer of asynchronous events from this transport.
Definition MockTransport.h:173
virtual bool isClosed() const
Has the Transport been shutdown and no longer usable.
Definition MockTransport.h:199
int getNumSentKeepAlivesBeforeFail() const
Definition MockTransport.h:275
virtual bool isUpdateURIsSupported() const
Definition MockTransport.h:319
void setNumReceivedMessageBeforeFail(int value)
Definition MockTransport.h:255
void setResponseBuilder(const Pointer< ResponseBuilder > responseBuilder)
Sets the ResponseBuilder that this class uses to create Responses to Commands sent.
Definition MockTransport.h:133
virtual void setTransportListener(TransportListener *listener)
Sets the observer of asynchronous events from this transport.
Definition MockTransport.h:169
virtual Transport * narrow(const std::type_info &typeId)
Narrows down a Chain of Transports to a specific Transport to allow a higher level transport to skip ...
Definition MockTransport.h:183
virtual Pointer< Response > request(const Pointer< Command > command, unsigned int timeout)
Sends the given command to the broker and then waits for the response.
static MockTransport * getInstance()
Definition MockTransport.h:99
virtual void oneway(const Pointer< Command > command)
Sends a one-way command.
bool isFailOnSendMessage() const
Definition MockTransport.h:219
Pointer< wireformat::WireFormat > getWireFormat() const
Gets the currently set WireFormat.
Definition MockTransport.h:152
virtual void start()
Starts the Transport, the send methods of a Transport will throw an exception if used before the Tran...
virtual void fireException(const exceptions::ActiveMQException &ex)
Fires a Exception back through this transport to its registered ExceptionListener if there is one.
Definition MockTransport.h:121
virtual bool isConnected() const
Is the Transport Connected to its Broker.
Definition MockTransport.h:195
void setFailOnStop(bool value)
Definition MockTransport.h:303
virtual void close()
Closes this object and deallocates the appropriate resources.
bool isFailOnStop() const
Definition MockTransport.h:299
bool isFailOnClose() const
Definition MockTransport.h:307
virtual void stop()
Stops the Transport.
bool isFailOnKeepAliveSends() const
Definition MockTransport.h:267
virtual Pointer< FutureResponse > asyncRequest(const Pointer< Command > command, const Pointer< ResponseCallback > responseCallback)
Sends a commands asynchronously, returning a FutureResponse object that the caller can use to check t...
virtual void updateURIs(bool rebalance AMQCPP_UNUSED, const decaf::util::List< decaf::net::URI > &uris AMQCPP_UNUSED)
Definition MockTransport.h:323
virtual void reconnect(const decaf::net::URI &uri AMQCPP_UNUSED)
Definition MockTransport.h:207
void setNumSentMessageBeforeFail(int value)
Definition MockTransport.h:231
Definition IOException.h:28
Decaf's implementation of a Smart Pointer that is a template on a Type and is Thread Safe if the defa...
Definition Pointer.h:53
This class represents an instance of a URI as defined by RFC 2396.
Definition URI.h:37
An ordered collection (also known as a sequence).
Definition List.h:47
An int value that may be updated atomically.
Definition AtomicInteger.h:37
#define NULL
Definition Config.h:33
Definition InternalCommandListener.h:34
Definition AbstractTransportFactory.h:30
Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements.
Definition CachedConsumer.h:24