/
ActiveMQProducer.h
287 lines (239 loc) · 9.62 KB
/
ActiveMQProducer.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef _ACTIVEMQ_CORE_ACTIVEMQPRODUCER_H_
#define _ACTIVEMQ_CORE_ACTIVEMQPRODUCER_H_
#include <cms/MessageProducer.h>
#include <cms/Message.h>
#include <cms/Destination.h>
#include <cms/DeliveryMode.h>
#include <activemq/util/Config.h>
#include <activemq/util/MemoryUsage.h>
#include <activemq/commands/ProducerInfo.h>
#include <activemq/commands/ProducerAck.h>
#include <activemq/exceptions/ActiveMQException.h>
#include <memory>
namespace activemq{
namespace core{
using decaf::lang::Pointer;
class ActiveMQSession;
class AMQCPP_API ActiveMQProducer : public cms::MessageProducer {
private:
// Disable sending timestamps
bool disableTimestamps;
// Disable adding a Message Id
bool disableMessageId;
// The default delivery Mode of this Producer
int defaultDeliveryMode;
// The default priority Level to send at
int defaultPriority;
// The default time to live value for messages in milliseconds
long long defaultTimeToLive;
// The default Send Timeout for this Producer.
long long sendTimeout;
// Session that this producer sends to.
ActiveMQSession* session;
// This Producers protocol specific info object
Pointer<commands::ProducerInfo> producerInfo;
// Boolean that indicates if the consumer has been closed
bool closed;
// Memory Usage Class, created only if the Producer is tracking its usage.
std::auto_ptr<util::MemoryUsage> memoryUsage;
// The Destination assigned at creation, NULL if not assigned.
std::auto_ptr<cms::Destination> destination;
public:
/**
* Constructor, creates an instance of an ActiveMQProducer
*
* @param producerInfo
* Pointer to a ProducerInfo command which identifies this producer.
* @param destination
* The assigned Destination this Producer sends to, or null if not set.
* The Producer does not own the Pointer passed.
* @param session
* The Session which is the parent of this Producer.
*/
ActiveMQProducer( const Pointer<commands::ProducerInfo>& producerInfo,
const cms::Destination* destination,
ActiveMQSession* session );
virtual ~ActiveMQProducer();
/**
* Closes the Consumer. This will return all allocated resources
* and purge any outstanding messages. This method will block if
* there is a call to receive in progress, or a dispatch to a
* MessageListener in place
* @throws CMSException
*/
virtual void close() throw ( cms::CMSException );
/**
* Sends the message to the default producer destination.
* @param a Message Object Pointer
* @throws CMSException
*/
virtual void send( cms::Message* message ) throw ( cms::CMSException );
/**
* Sends the message to the default producer destination, but does
* not take ownership of the message, caller must still destroy it.
* @param message - a Message Object Pointer
* @param deliverMode The delivery mode to be used.
* @param priority The priority for this message.
* @param timeToLive The time to live value for this message in
* milliseconds.
* @throws CMSException
*/
virtual void send( cms::Message* message, int deliveryMode,
int priority, long long timeToLive )
throw ( cms::CMSException );
/**
* Sends the message to the designated destination.
* @param a Message Object Pointer
* @throws CMSException
*/
virtual void send( const cms::Destination* destination,
cms::Message* message ) throw ( cms::CMSException );
/**
* Sends the message to the designated destination, but does
* not take ownership of the message, caller must still destroy it.
* @param destination - a Message Object Pointer
* @param message - a Message Object Pointer
* @param deliverMode The delivery mode to be used.
* @param priority The priority for this message.
* @param timeToLive The time to live value for this message in
* milliseconds.
* @throws CMSException
*/
virtual void send( const cms::Destination* destination,
cms::Message* message, int deliveryMode,
int priority, long long timeToLive )
throw ( cms::CMSException );
/**
* Sets the delivery mode for this Producer
* @param The DeliveryMode
*/
virtual void setDeliveryMode( int mode ) {
this->defaultDeliveryMode = mode;
}
/**
* Gets the delivery mode for this Producer
* @return The DeliveryMode
*/
virtual int getDeliveryMode() const {
return this->defaultDeliveryMode;
}
/**
* Sets if Message Ids are disabled for this Producer
* @param boolean indicating enable / disable (true / false)
*/
virtual void setDisableMessageID( bool value ) {
this->disableMessageId = value;
}
/**
* Sets if Message Ids are disabled for this Producer
* @param boolean indicating enable / disable (true / false)
*/
virtual bool getDisableMessageID() const {
return this->disableMessageId;
}
/**
* Sets if Message Time Stamps are disabled for this Producer
* @param boolean indicating enable / disable (true / false)
*/
virtual void setDisableMessageTimeStamp( bool value ) {
this->disableTimestamps = value;
}
/**
* Sets if Message Time Stamps are disabled for this Producer
* @param boolean indicating enable / disable (true / false)
*/
virtual bool getDisableMessageTimeStamp() const {
return this->disableTimestamps;
}
/**
* Sets the Priority that this Producers sends messages at
* @param int value for Priority level
*/
virtual void setPriority( int priority ) {
this->defaultPriority = priority;
}
/**
* Gets the Priority level that this producer sends messages at
* @return int based priority level
*/
virtual int getPriority() const {
return this->defaultPriority;
}
/**
* Sets the Time to Live that this Producers sends messages with
* @param time The new default time to live value in milliseconds.
*/
virtual void setTimeToLive( long long time ) {
this->defaultTimeToLive = time;
}
/**
* Gets the Time to Live that this producer sends messages with
* @return The default time to live value in milliseconds.
*/
virtual long long getTimeToLive() const {
return this->defaultTimeToLive;
}
/**
* Sets the Send Timeout that this Producers sends messages with
* @param time The new default send timeout value in milliseconds.
*/
virtual void setSendTimeout( long long time ) {
this->sendTimeout = time;
}
/**
* Gets the Send Timeout that this producer sends messages with
* @return The default send timeout value in milliseconds.
*/
virtual long long getSendTimeout() const {
return this->sendTimeout;
}
public:
/**
* @returns true if this Producer has been closed.
*/
bool isClosed() const {
return this->closed;
}
/**
* Retries this object ProducerInfo pointer
* @return ProducerInfo Reference
*/
const commands::ProducerInfo& getProducerInfo() const {
this->checkClosed();
return *( this->producerInfo );
}
/**
* Retries this object ProducerId or NULL if closed.
* @return ProducerId Reference
*/
commands::ProducerId& getProducerId() const {
this->checkClosed();
return *( this->producerInfo->getProducerId() );
}
/**
* Handles the work of Processing a ProducerAck Command from the Broker.
* @param ack - The ProducerAck message received from the Broker.
*/
virtual void onProducerAck( const commands::ProducerAck& ack );
private:
// Checks for the closed state and throws if so.
void checkClosed() const throw( exceptions::ActiveMQException );
};
}}
#endif /*_ACTIVEMQ_CORE_ACTIVEMQPRODUCER_H_*/