activemq-cpp-3.9.5
ActiveMQMessageTemplate.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_COMMANDS_ACTIVEMQMESSAGETEMPLATE_H_
19#define _ACTIVEMQ_COMMANDS_ACTIVEMQMESSAGETEMPLATE_H_
20
21#include <cms/DeliveryMode.h>
29
31
36
37namespace activemq {
38namespace commands {
39
40 template<typename T>
41 class AMQCPP_API ActiveMQMessageTemplate: public T, public Message {
42 private:
43
44 std::auto_ptr<wireformat::openwire::utils::MessagePropertyInterceptor> propertiesInterceptor;
45
46 public:
47
48 ActiveMQMessageTemplate() : commands::Message(), propertiesInterceptor() {
49 this->propertiesInterceptor.reset(new wireformat::openwire::utils::MessagePropertyInterceptor(this, &this->getMessageProperties()));
50 }
51
52 virtual ~ActiveMQMessageTemplate() throw () {
53 }
54
55 public:
56
57 virtual void acknowledge() const {
58 try {
59 this->getAckHandler()->acknowledgeMessage(this);
60 }
62 }
63
64 virtual void onSend() {
65 this->setReadOnlyBody(true);
66 this->setReadOnlyProperties(true);
67 }
68
69 virtual bool equals(const DataStructure* value) const {
70 try {
71
72 if (this == value) {
73 return true;
74 }
75
76 const ActiveMQMessageTemplate<T>* object =
77 dynamic_cast<const ActiveMQMessageTemplate<T>*> (value);
78
79 if (object == NULL) {
80 return false;
81 }
82
84 decaf::lang::Pointer<MessageId> otherMsgId = object->getMessageId();
85
86 return thisMsgId != NULL && otherMsgId != NULL && otherMsgId->equals(thisMsgId.get());
87 }
89 }
90
91 virtual void clearBody() {
92 try {
93 this->setContent(std::vector<unsigned char>());
94 this->setReadOnlyBody(false);
95 }
97 }
98
99 virtual void clearProperties() {
100 try {
101 this->getMessageProperties().clear();
102 this->setReadOnlyProperties(false);
103 }
105 }
106
107 virtual std::vector<std::string> getPropertyNames() const {
108 try {
109 return getMessageProperties().keySet().toArray();
110 }
112 }
113
114 virtual bool propertyExists(const std::string& name) const {
115 try {
116 return getMessageProperties().containsKey(name);
117 }
119 }
120
159
160 virtual bool getBooleanProperty(const std::string& name) const {
161 try {
162 return this->propertiesInterceptor->getBooleanProperty(name);
165 }
167 }
168
169 virtual unsigned char getByteProperty(const std::string& name) const {
170 try {
171 return this->propertiesInterceptor->getByteProperty(name);
174 }
176 }
177
178 virtual double getDoubleProperty(const std::string& name) const {
179
180 try {
181 return this->propertiesInterceptor->getDoubleProperty(name);
184 }
186 }
187
188 virtual float getFloatProperty(const std::string& name) const {
189
190 try {
191 return this->propertiesInterceptor->getFloatProperty(name);
194 }
196 }
197
198 virtual int getIntProperty(const std::string& name) const {
199
200 try {
201 return this->propertiesInterceptor->getIntProperty(name);
204 }
206 }
207
208 virtual long long getLongProperty(const std::string& name) const {
209
210 try {
211 return this->propertiesInterceptor->getLongProperty(name);
214 }
216 }
217
218 virtual short getShortProperty(const std::string& name) const {
219
220 try {
221 return this->propertiesInterceptor->getShortProperty(name);
224 }
226 }
227
228 virtual std::string getStringProperty(const std::string& name) const {
229
230 try {
231 return this->propertiesInterceptor->getStringProperty(name);
234 }
236 }
237
238 virtual void setBooleanProperty(const std::string& name, bool value) {
239
240 if (name == "") {
241 throw cms::CMSException("Message Property names must not be empty", NULL);
242 }
243
245 try {
246 this->propertiesInterceptor->setBooleanProperty(name, value);
247 }
249 }
250
251 virtual void setByteProperty(const std::string& name, unsigned char value) {
252
253 if (name == "") {
254 throw cms::CMSException("Message Property names must not be empty", NULL);
255 }
256
258 try {
259 this->propertiesInterceptor->setByteProperty(name, value);
260 }
262 }
263
264 virtual void setDoubleProperty(const std::string& name, double value) {
265
266 if (name == "") {
267 throw cms::CMSException("Message Property names must not be empty", NULL);
268 }
269
271 try {
272 this->propertiesInterceptor->setDoubleProperty(name, value);
273 }
275 }
276
277 virtual void setFloatProperty(const std::string& name, float value) {
278
279 if (name == "") {
280 throw cms::CMSException("Message Property names must not be empty", NULL);
281 }
282
284 try {
285 this->propertiesInterceptor->setFloatProperty(name, value);
286 }
288 }
289
290 virtual void setIntProperty(const std::string& name, int value) {
291
292 if (name == "") {
293 throw cms::CMSException("Message Property names must not be empty", NULL);
294 }
295
297 try {
298 this->propertiesInterceptor->setIntProperty(name, value);
299 }
301 }
302
303 virtual void setLongProperty(const std::string& name, long long value) {
304
305 if (name == "") {
306 throw cms::CMSException("Message Property names must not be empty", NULL);
307 }
308
310 try {
311 this->propertiesInterceptor->setLongProperty(name, value);
312 }
314 }
315
316 virtual void setShortProperty(const std::string& name, short value) {
317
318 if (name == "") {
319 throw cms::CMSException("Message Property names must not be empty", NULL);
320 }
321
323 try {
324 this->propertiesInterceptor->setShortProperty(name, value);
325 }
327 }
328
329 virtual void setStringProperty(const std::string& name, const std::string& value) {
330
331 if (name == "") {
332 throw cms::CMSException("Message Property names must not be empty", NULL);
333 }
334
336 try {
337 this->propertiesInterceptor->setStringProperty(name, value);
338 }
340 }
341
342 virtual std::string getCMSCorrelationID() const {
343 return this->getCorrelationId();
344 }
345
346 virtual void setCMSCorrelationID(const std::string& correlationId) {
348 }
349
350 virtual int getCMSDeliveryMode() const {
351 return !this->isPersistent();
352 }
353
354 virtual void setCMSDeliveryMode(int mode) {
355 this->setPersistent(mode == (int) cms::DeliveryMode::PERSISTENT);
356 }
357
358 virtual const cms::Destination* getCMSDestination() const {
359 return dynamic_cast<const cms::Destination*> (this->getDestination().get());
360 }
361
363
364 try {
365 if (destination != NULL) {
367 dynamic_cast<ActiveMQDestination*> (destination->clone())));
368 } else {
369 this->getDestination().reset(NULL);
370 }
371 }
373 }
374
375 virtual long long getCMSExpiration() const {
376 return this->getExpiration();
377 }
378
379 virtual void setCMSExpiration(long long expireTime) {
380 this->setExpiration(expireTime);
381 }
382
383 virtual std::string getCMSMessageID() const {
384 try {
386 }
388 }
389
390 virtual void setCMSMessageID(const std::string& value) {
391 try {
392 Pointer<MessageId> id(new MessageId(value));
393 this->setMessageId(id);
395 // we must be some foreign JMS provider or strange user-supplied
396 // String so lets set the IDs to be 1
398 id->setTextView(value);
399 this->setMessageId(messageId);
400 }
401 }
402
403 virtual int getCMSPriority() const {
404 return this->getPriority();
405 }
406
407 virtual void setCMSPriority(int priority) {
408 this->setPriority((unsigned char) priority);
409 }
410
411 virtual bool getCMSRedelivered() const {
412 return this->getRedeliveryCounter() != 0;
413 }
414
415 virtual void setCMSRedelivered(bool redelivered AMQCPP_UNUSED ) {
416 }
417
418 virtual const cms::Destination* getCMSReplyTo() const {
419 return dynamic_cast<const cms::Destination*> (this->getReplyTo().get());
420 }
421
423
424 try {
425 if (destination != NULL) {
427 dynamic_cast<ActiveMQDestination*> (destination->clone())));
428 } else {
430 }
431 }
433 }
434
435 virtual long long getCMSTimestamp() const {
436 return this->getTimestamp();
437 }
438
439 virtual void setCMSTimestamp(long long timeStamp) {
440 this->setTimestamp(timeStamp);
441 }
442
443 virtual std::string getCMSType() const {
444 return this->getType();
445 }
446
447 virtual void setCMSType(const std::string& type) {
448 this->setType(type);
449 }
450
451 protected:
452
453 void failIfWriteOnlyBody() const {
454 if (!this->isReadOnlyBody()) {
455 throw cms::MessageNotReadableException("message is in write-only mode and cannot be read from", NULL);
456 }
457 }
458
459 void failIfReadOnlyBody() const {
460 if (this->isReadOnlyBody()) {
461 throw cms::MessageNotWriteableException("Message Body is Read-Only.", NULL);
462 }
463 }
464
466 if (this->isReadOnlyProperties()) {
467 throw cms::MessageNotWriteableException("Message Properties are Read-Only.", NULL);
468 }
469 }
470
471 };
472
473}
474}
475
476#endif /* _ACTIVEMQ_COMMANDS_ACTIVEMQMESSAGETEMPLATE_H_ */
#define AMQ_CATCH_ALL_THROW_CMSEXCEPTION()
Macro for catching an exception of one type and then re-throwing as a Basic CMSException,...
Definition CMSExceptionSupport.h:73
#define AMQCPP_API
Definition Config.h:30
Definition ActiveMQDestination.h:39
virtual long long getCMSTimestamp() const
Definition ActiveMQMessageTemplate.h:435
virtual int getCMSDeliveryMode() const
Definition ActiveMQMessageTemplate.h:350
virtual void setLongProperty(const std::string &name, long long value)
Definition ActiveMQMessageTemplate.h:303
virtual void setCMSRedelivered(bool redelivered AMQCPP_UNUSED)
Definition ActiveMQMessageTemplate.h:415
virtual void setCMSTimestamp(long long timeStamp)
Definition ActiveMQMessageTemplate.h:439
virtual long long getLongProperty(const std::string &name) const
Definition ActiveMQMessageTemplate.h:208
virtual long long getCMSExpiration() const
Definition ActiveMQMessageTemplate.h:375
virtual unsigned char getByteProperty(const std::string &name) const
Definition ActiveMQMessageTemplate.h:169
virtual void setCMSMessageID(const std::string &value)
Definition ActiveMQMessageTemplate.h:390
void failIfWriteOnlyBody() const
Definition ActiveMQMessageTemplate.h:453
virtual bool equals(const DataStructure *value) const
Compares the DataStructure passed in to this one, and returns if they are equivalent.
Definition ActiveMQMessageTemplate.h:69
virtual bool getCMSRedelivered() const
Definition ActiveMQMessageTemplate.h:411
virtual void setCMSDestination(const cms::Destination *destination)
Definition ActiveMQMessageTemplate.h:362
virtual void setCMSCorrelationID(const std::string &correlationId)
Definition ActiveMQMessageTemplate.h:346
virtual short getShortProperty(const std::string &name) const
Definition ActiveMQMessageTemplate.h:218
virtual void setFloatProperty(const std::string &name, float value)
Definition ActiveMQMessageTemplate.h:277
virtual float getFloatProperty(const std::string &name) const
Definition ActiveMQMessageTemplate.h:188
virtual void setCMSDeliveryMode(int mode)
Definition ActiveMQMessageTemplate.h:354
virtual void setIntProperty(const std::string &name, int value)
Definition ActiveMQMessageTemplate.h:290
virtual cms::Message::ValueType getPropertyValueType(const std::string &name) const
Definition ActiveMQMessageTemplate.h:121
void failIfReadOnlyBody() const
Definition ActiveMQMessageTemplate.h:459
virtual bool propertyExists(const std::string &name) const
Definition ActiveMQMessageTemplate.h:114
virtual void setBooleanProperty(const std::string &name, bool value)
Definition ActiveMQMessageTemplate.h:238
virtual double getDoubleProperty(const std::string &name) const
Definition ActiveMQMessageTemplate.h:178
virtual bool getBooleanProperty(const std::string &name) const
Definition ActiveMQMessageTemplate.h:160
virtual std::string getCMSMessageID() const
Definition ActiveMQMessageTemplate.h:383
virtual const cms::Destination * getCMSReplyTo() const
Definition ActiveMQMessageTemplate.h:418
virtual std::string getStringProperty(const std::string &name) const
Definition ActiveMQMessageTemplate.h:228
virtual void setStringProperty(const std::string &name, const std::string &value)
Definition ActiveMQMessageTemplate.h:329
virtual void clearProperties()
Definition ActiveMQMessageTemplate.h:99
virtual int getCMSPriority() const
Definition ActiveMQMessageTemplate.h:403
virtual int getIntProperty(const std::string &name) const
Definition ActiveMQMessageTemplate.h:198
virtual void clearBody()
Definition ActiveMQMessageTemplate.h:91
virtual void acknowledge() const
Definition ActiveMQMessageTemplate.h:57
virtual const cms::Destination * getCMSDestination() const
Definition ActiveMQMessageTemplate.h:358
virtual void setCMSReplyTo(const cms::Destination *destination)
Definition ActiveMQMessageTemplate.h:422
virtual std::string getCMSCorrelationID() const
Definition ActiveMQMessageTemplate.h:342
virtual void onSend()
Allows derived Message classes to perform tasks before a message is sent.
Definition ActiveMQMessageTemplate.h:64
virtual std::string getCMSType() const
Definition ActiveMQMessageTemplate.h:443
virtual ~ActiveMQMessageTemplate()
Definition ActiveMQMessageTemplate.h:52
virtual void setDoubleProperty(const std::string &name, double value)
Definition ActiveMQMessageTemplate.h:264
virtual void setCMSType(const std::string &type)
Definition ActiveMQMessageTemplate.h:447
void failIfReadOnlyProperties() const
Definition ActiveMQMessageTemplate.h:465
virtual void setByteProperty(const std::string &name, unsigned char value)
Definition ActiveMQMessageTemplate.h:251
ActiveMQMessageTemplate()
Definition ActiveMQMessageTemplate.h:48
virtual void setCMSPriority(int priority)
Definition ActiveMQMessageTemplate.h:407
virtual void setShortProperty(const std::string &name, short value)
Definition ActiveMQMessageTemplate.h:316
virtual std::vector< std::string > getPropertyNames() const
Definition ActiveMQMessageTemplate.h:107
virtual void setCMSExpiration(long long expireTime)
Definition ActiveMQMessageTemplate.h:379
Definition DataStructure.h:27
virtual const Pointer< ActiveMQDestination > & getReplyTo() const
virtual void setDestination(const Pointer< ActiveMQDestination > &destination)
virtual const std::string & getCorrelationId() const
unsigned char priority
Definition Message.h:73
virtual const std::string & getType() const
virtual long long getExpiration() const
virtual void setTimestamp(long long timestamp)
virtual int getRedeliveryCounter() const
virtual void setType(const std::string &type)
bool isReadOnlyBody() const
Returns if the Message Body is Read Only.
Definition Message.h:263
virtual Pointer< core::ActiveMQAckHandler > getAckHandler() const
Gets the Acknowledgment Handler that this Message will use when the Acknowledge method is called.
Definition Message.h:190
virtual const Pointer< MessageId > & getMessageId() const
void setReadOnlyBody(bool value)
Set the Read Only State of the Message Content.
Definition Message.h:271
virtual void setPriority(unsigned char priority)
virtual void setContent(const std::vector< unsigned char > &content)
virtual void setCorrelationId(const std::string &correlationId)
virtual long long getTimestamp() const
virtual void setExpiration(long long expiration)
Pointer< ActiveMQDestination > destination
Definition Message.h:63
virtual const Pointer< ActiveMQDestination > & getDestination() const
virtual void setReplyTo(const Pointer< ActiveMQDestination > &replyTo)
std::string type
Definition Message.h:76
Pointer< MessageId > messageId
Definition Message.h:66
virtual bool isPersistent() const
virtual unsigned char getPriority() const
virtual void setMessageId(const Pointer< MessageId > &messageId)
std::string correlationId
Definition Message.h:70
virtual void setPersistent(bool persistent)
util::PrimitiveMap & getMessageProperties()
Gets a reference to the Message's Properties object, allows the derived classes to get and set their ...
Definition Message.h:236
void setReadOnlyProperties(bool value)
Set the Read Only State of the Message Properties.
Definition Message.h:255
bool isReadOnlyProperties() const
Returns if the Message Properties Are Read Only.
Definition Message.h:247
Definition MessageId.h:49
static cms::MessageFormatException createMessageFormatException(const decaf::lang::Exception &cause)
PrimitiveType
Enumeration for the various primitive types.
Definition PrimitiveValueNode.h:44
@ BOOLEAN_TYPE
Definition PrimitiveValueNode.h:46
@ DOUBLE_TYPE
Definition PrimitiveValueNode.h:52
@ FLOAT_TYPE
Definition PrimitiveValueNode.h:53
@ BYTE_ARRAY_TYPE
Definition PrimitiveValueNode.h:55
@ CHAR_TYPE
Definition PrimitiveValueNode.h:48
@ INTEGER_TYPE
Definition PrimitiveValueNode.h:50
@ LONG_TYPE
Definition PrimitiveValueNode.h:51
@ NULL_TYPE
Definition PrimitiveValueNode.h:45
@ BYTE_TYPE
Definition PrimitiveValueNode.h:47
@ BIG_STRING_TYPE
Definition PrimitiveValueNode.h:58
@ SHORT_TYPE
Definition PrimitiveValueNode.h:49
@ STRING_TYPE
Definition PrimitiveValueNode.h:54
static std::string toString(const commands::MessageId *id)
Converts the object to a String.
Used the base ActiveMQMessage class to intercept calls to get and set properties in order to capture ...
Definition MessagePropertyInterceptor.h:47
CMS API Exception that is the base for all exceptions thrown from CMS classes.
Definition CMSException.h:50
@ PERSISTENT
Definition DeliveryMode.h:55
A Destination object encapsulates a provider-specific address.
Definition Destination.h:39
ValueType
Defines the Type Identifiers used to identify the type contained within a specific Message property o...
Definition Message.h:112
@ LONG_TYPE
Definition Message.h:119
@ DOUBLE_TYPE
Definition Message.h:120
@ FLOAT_TYPE
Definition Message.h:121
@ BYTE_ARRAY_TYPE
Definition Message.h:123
@ BOOLEAN_TYPE
Definition Message.h:114
@ BYTE_TYPE
Definition Message.h:115
@ CHAR_TYPE
Definition Message.h:116
@ INTEGER_TYPE
Definition Message.h:118
@ UNKNOWN_TYPE
Definition Message.h:124
@ STRING_TYPE
Definition Message.h:122
@ SHORT_TYPE
Definition Message.h:117
@ NULL_TYPE
Definition Message.h:113
This exception must be thrown when a CMS client attempts to read a write-only message.
Definition MessageNotReadableException.h:31
This exception must be thrown when a CMS client attempts to write to a read-only message.
Definition MessageNotWriteableException.h:31
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
PointerType get() const
Gets the real pointer that is contained within this Pointer.
Definition Pointer.h:188
Definition NumberFormatException.h:33
Definition UnsupportedOperationException.h:32
#define NULL
Definition Config.h:33
Definition ActiveMQBlobMessage.h:28
Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements.
Definition CachedConsumer.h:24