activemq-cpp-3.8.2
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 
21 #include <activemq/util/Config.h>
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 
41 namespace activemq{
42 namespace transport{
43 namespace mock{
44 
48 
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 
91  MockTransport operator=(const MockTransport&);
92 
93  public:
94 
95  MockTransport(const Pointer<wireformat::WireFormat> wireFormat, const Pointer<ResponseBuilder> responseBuilder);
96 
97  virtual ~MockTransport() {}
98 
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 
160  virtual Pointer<FutureResponse> asyncRequest(const Pointer<Command> command,
161  const Pointer<ResponseCallback> responseCallback);
162 
163  virtual Pointer<Response> request(const Pointer<Command> command);
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 
231  void setNumSentMessageBeforeFail(int value) {
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 
243  bool isFailOnReceiveMessage() const {
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 
267  bool isFailOnKeepAliveSends() const {
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 
283  int getNumSentKeepAlives() const {
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) {
324  throw decaf::io::IOException();
325  }
326 
327  };
328 
329 }}}
330 
331 #endif /*_ACTIVEMQ_TANSPORT_MOCK_MOCKTRANSPORT_H_*/
virtual bool isClosed() const
Has the Transport been shutdown and no longer usable.
Definition: MockTransport.h:199
virtual bool isFaultTolerant() const
Is this Transport fault tolerant, meaning that it will reconnect to a broker on disconnect.
Definition: MockTransport.h:191
int getNumSentKeepAlives() const
Definition: MockTransport.h:283
virtual void updateURIs(bool rebalance AMQCPP_UNUSED, const decaf::util::List< decaf::net::URI > &uris AMQCPP_UNUSED)
Definition: MockTransport.h:323
virtual void setWireFormat(const Pointer< wireformat::WireFormat > wireFormat AMQCPP_UNUSED)
Sets the WireFormat instance to use.
Definition: MockTransport.h:167
int getNumReceivedMessageBeforeFail() const
Definition: MockTransport.h:251
void setFailOnReceiveMessage(bool value)
Definition: MockTransport.h:247
virtual TransportListener * getTransportListener() const
Gets the observer of asynchronous events from this transport.
Definition: MockTransport.h:173
void setNumReceivedMessages(int value)
Definition: MockTransport.h:263
#define AMQCPP_API
Definition: Config.h:30
void setFailOnStart(bool value)
Definition: MockTransport.h:295
void setFailOnSendMessage(bool value)
Definition: MockTransport.h:223
void setNumSentMessages(int value)
Definition: MockTransport.h:239
#define NULL
Definition: Config.h:33
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
int getNumSentMessageBeforeFail() const
Definition: MockTransport.h:227
void setNumSentKeepAlivesBeforeFail(int value)
Definition: MockTransport.h:279
Definition: Response.h:46
void setNumSentKeepAlives(int value)
Definition: MockTransport.h:287
Definition: IOException.h:28
virtual void setTransportListener(TransportListener *listener)
Sets the observer of asynchronous events from this transport.
Definition: MockTransport.h:169
bool isFailOnKeepAliveSends() const
Definition: MockTransport.h:267
bool isFailOnStop() const
Definition: MockTransport.h:299
virtual void reconnect(const decaf::net::URI &uri AMQCPP_UNUSED)
Definition: MockTransport.h:207
static MockTransport * getInstance()
Definition: MockTransport.h:99
Pointer< wireformat::WireFormat > getWireFormat() const
Gets the currently set WireFormat.
Definition: MockTransport.h:152
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
Listens for Commands sent from the MockTransport.
Definition: InternalCommandListener.h:45
virtual std::string getRemoteAddress() const
Definition: MockTransport.h:203
Interface for a transport layer for command objects.
Definition: Transport.h:59
virtual ~MockTransport()
Definition: MockTransport.h:97
An int value that may be updated atomically.
Definition: AtomicInteger.h:37
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 onException(const decaf::lang::Exception &ex)=0
Event handler for an exception from a command transport.
int getNumSentKeepAlivesBeforeFail() const
Definition: MockTransport.h:275
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 isUpdateURIsSupported() const
Definition: MockTransport.h:319
void setNumSentMessageBeforeFail(int value)
Definition: MockTransport.h:231
This class represents an instance of a URI as defined by RFC 2396.
Definition: URI.h:36
void setName(const std::string &name)
Definition: MockTransport.h:215
The MockTransport defines a base level Transport class that is intended to be used in place of an a r...
Definition: MockTransport.h:61
bool isFailOnClose() const
Definition: MockTransport.h:307
virtual void onCommand(const Pointer< Command > command)=0
Event handler for the receipt of a command.
Definition: ActiveMQException.h:35
std::string getName() const
Definition: MockTransport.h:211
void setFailOnStop(bool value)
Definition: MockTransport.h:303
int getNumSentMessages() const
Definition: MockTransport.h:235
void setNumReceivedMessageBeforeFail(int value)
Definition: MockTransport.h:255
Definition: Command.h:33
bool isFailOnReceiveMessage() const
Definition: MockTransport.h:243
virtual bool isReconnectSupported() const
Definition: MockTransport.h:315
void setFailOnClose(bool value)
Definition: MockTransport.h:311
Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements...
Definition: CachedConsumer.h:24
bool isFailOnStart() const
Definition: MockTransport.h:291
int getNumReceivedMessages() const
Definition: MockTransport.h:259
bool isFailOnSendMessage() const
Definition: MockTransport.h:219
void setFailOnKeepAliveSends(bool value)
Definition: MockTransport.h:271
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 bool isConnected() const
Is the Transport Connected to its Broker.
Definition: MockTransport.h:195
Decaf&#39;s implementation of a Smart Pointer that is a template on a Type and is Thread Safe if the defa...
Definition: Pointer.h:53
A listener of asynchronous exceptions from a command transport object.
Definition: TransportListener.h:38