1 /*------------------------------------------------------------------------------
2 Name: QueuePropertyBase.h
3 Project: xmlBlaster.org
4 Copyright: xmlBlaster.org, see xmlBlaster-LICENSE file
5 Comment: Holding callback queue properties
6 Version: $Id: QueuePropertyBase.h 13445 2005-07-15 01:54:35Z ruff $
7 ------------------------------------------------------------------------------*/
8
9 /**
10 * Helper class holding callback queue properties.
11 * <p />
12 * See org::xmlBlaster::util::qos::ConnectQos for XML syntax.
13 * @see org.xmlBlaster.client.qos.ConnectQos
14 */
15
16 #ifndef _UTIL_QUEUE_QUEUEPROPERTYBASE_H
17 #define _UTIL_QUEUE_QUEUEPROPERTYBASE_H
18
19 #include <util/xmlBlasterDef.h>
20 #include <util/Constants.h>
21 #include <util/qos/address/AddressBase.h>
22
23 #include <string>
24 #include <vector>
25
26 namespace org { namespace xmlBlaster { namespace util { namespace qos { namespace storage {
27
28 extern Dll_Export const long DEFAULT_maxEntriesDefault;
29 extern Dll_Export const long DEFAULT_maxEntriesCacheDefault;
30 extern Dll_Export const long DEFAULT_bytesDefault;
31 extern Dll_Export const long DEFAULT_bytesCacheDefault;
32 /** The default settings (as a ratio relative to the maxBytesCache) for the storeSwapLevel */
33 extern Dll_Export const double DEFAULT_storeSwapLevelRatio;
34 /** The default settings (as a ratio relative to the maxBytesCache) for the storeSwapBytes */
35 extern Dll_Export const double DEFAULT_storeSwapBytesRatio;
36 /** The default settings (as a ratio relative to the maxBytesCache) for the storeSwapLevel */
37 extern Dll_Export const double DEFAULT_reloadSwapLevelRatio;
38 /** The default settings (as a ratio relative to the maxBytesCache) for the storeSwapBytes */
39 extern Dll_Export const double DEFAULT_reloadSwapBytesRatio;
40 extern Dll_Export const Timestamp DEFAULT_minExpires;
41 extern Dll_Export const Timestamp DEFAULT_maxExpires;
42 extern Dll_Export const std::string DEFAULT_onOverflow;
43 extern Dll_Export const std::string DEFAULT_onFailure;
44
45 // static variables
46 extern Dll_Export std::string DEFAULT_type;
47 extern Dll_Export std::string DEFAULT_version;
48 /** If not otherwise noted a queue dies after the max value, changeable with property e.g. "queue/expires=3600000" milliseconds */
49 extern Dll_Export long DEFAULT_expires;
50
51 typedef std::vector<org::xmlBlaster::util::qos::address::AddressBaseRef> AddressVector;
52
53 class Dll_Export QueuePropertyBase
54 {
55 friend class QueuePropertyFactory;
56 protected:
57 std::string ME; // = "QueuePropertyBase";
58 org::xmlBlaster::util::Global& global_;
59 org::xmlBlaster::util::I_Log& log_;
60
61 /** The queue plugin type "CACHE" "RAM" "JDBC" */
62 std::string type_;
63
64 /** The queue plugin version "1.0" or similar */
65 std::string version_;
66
67 /** The max setting allowed for queue maxEntries is adjustable with property "queue/maxEntries=1000" (1000 messages is default) */
68 long maxEntriesDefault_;
69
70 /** The max setting allowed for queue maxEntriesCache is adjustable with property "queue/maxEntriesCache=1000" (1000 messages is default) */
71 long maxEntriesCacheDefault_;
72
73 /** The max setting allowed for queue maxBytes in Bytes is adjustable with property "queue/maxBytes=4194304" (4 MBytes is default) */
74 long maxBytesDefault_;
75
76 /** The max setting allowed for queue maxBytesCache in Bytes is adjustable with property "queue/maxBytesCache=4000" (4 MBytes is default) */
77 long maxBytesCacheDefault_;
78
79 /** The min span of life is one second, changeable with property e.g. "queue/expires.min=2000" milliseconds */
80 Timestamp minExpires_;
81
82 /** The max span of life of a queue is currently forever (=0), changeable with property e.g. "queue/expires.max=3600000" milliseconds */
83 Timestamp maxExpires_;
84
85
86 /** The unique protocol relating, e.g. "IOR" */
87 std::string relating_; // = Constants.RELATING_CALLBACK;
88 /** Span of life of this queue in milliseconds */
89 Timestamp expires_; // = DEFAULT_expires;
90 /** The max. capacity of the queue in number of entries */
91 long maxEntries_;
92 /** The max. capacity of the queue in Bytes */
93 long maxBytes_;
94 /** The max. capacity of the cache of the queue in number of entries */
95 long maxEntriesCache_;
96
97 /** The settings for the storeSwapLevel */
98 long storeSwapLevel_;
99
100 /** The settings for the storeSwapBytes */
101 long storeSwapBytes_;
102
103 /** The settings for the storeSwapLevel */
104 long reloadSwapLevel_;
105
106 /** The settings for the storeSwapBytes */
107 long reloadSwapBytes_;
108
109 /** The max. capacity of the queue in Bytes for the cache */
110 long maxBytesCache_;
111
112 /** Error handling when queue is full: Constants.ONOVERFLOW_DEADMESSAGE | Constants.ONOVERFLOW_DISCARDOLDEST */
113 std::string onOverflow_;
114
115 /** Error handling when callback failed (after all retries etc.): Constants.ONOVERFLOW_DEADMESSAGE */
116 std::string onFailure_;
117
118 /** The corresponding callback address */
119 AddressVector addressArr_; // = new org::xmlBlaster::util::qos::address::AddressBase[0];
120
121 /** To allow specific configuration parameters for specific cluster nodes */
122 std::string nodeId_; // = null;
123
124 /** Relating "connection", "history", "callback" etc. */
125 std::string propertyPrefix_;
126
127 std::string rootTagName_;
128
129 void copy(const QueuePropertyBase& prop)
130 {
131 type_ = prop.type_;
132 version_ = prop.version_;
133 maxEntriesDefault_ = prop.maxEntriesDefault_;
134 maxEntriesCacheDefault_= prop.maxEntriesCacheDefault_;
135 maxBytesDefault_ = prop.maxBytesDefault_;
136 maxBytesCacheDefault_ = prop.maxBytesCacheDefault_;
137 minExpires_ = prop.maxExpires_;
138 relating_ = prop.relating_;
139 expires_ = prop.expires_;
140 maxEntries_ = prop.maxEntries_;
141 maxBytes_ = prop.maxBytes_;
142 maxEntriesCache_ = prop.maxEntriesCache_;
143 storeSwapLevel_ = prop.storeSwapLevel_;
144 storeSwapBytes_ = prop.storeSwapBytes_;
145 reloadSwapLevel_ = prop.reloadSwapLevel_;
146 reloadSwapBytes_ = prop.reloadSwapBytes_;
147 maxBytesCache_ = prop.maxBytesCache_;
148 onOverflow_ = prop.onOverflow_;
149 onFailure_ = prop.onFailure_;
150 addressArr_ = prop.addressArr_;
151 nodeId_ = prop.nodeId_;
152 propertyPrefix_ = prop.propertyPrefix_;
153 rootTagName_ = prop.rootTagName_;
154 }
155
156 /**
157 * Configure property settings, add your own defaults in the derived class
158 */
159 /*inline*/ void initialize(const std::string& propertyPrefix);
160
161 void setMaxExpires(Timestamp maxExpires)
162 {
163 maxExpires_ = maxExpires;
164 }
165
166 Timestamp getMaxExpires() const
167 {
168 return maxExpires_;
169 }
170
171 void setMinExpires(Timestamp minExpires)
172 {
173 minExpires_ = minExpires;
174 }
175
176 Timestamp getMinExpires()
177 {
178 return minExpires_;
179 }
180
181 public:
182
183 /**
184 * @param nodeId If not null, the command line properties will look for prop[nodeId] as well,
185 * e.g. -queue/maxEntries and -queue/maxEntries[heron] will be searched
186 */
187 QueuePropertyBase(org::xmlBlaster::util::Global& global, const std::string& nodeId);
188
189 QueuePropertyBase(const QueuePropertyBase& prop);
190
191 QueuePropertyBase& operator =(const QueuePropertyBase& prop);
192
193 virtual ~QueuePropertyBase();
194
195 /**
196 * @param relating To what is this queue related: Constants.RELATING_CALLBACK | Constants.RELATING_SUBJECT | Constants.RELATING_CLIENT
197 */
198 void setRelating(const std::string& relating);
199
200 /**
201 * Returns the queue type.
202 * @return relating To what is this queue related: Constants.RELATING_CALLBACK | Constants.RELATING_SUBJECT
203 */
204 std::string getRelating() const;
205
206 /**
207 * Span of life of this queue.
208 * @return Expiry time in milliseconds or 0L if forever
209 */
210 Timestamp getExpires() const;
211
212 /**
213 * Span of life of this queue.
214 * @param Expiry time in milliseconds
215 */
216 void setExpires(Timestamp expires);
217
218 /**
219 * Max number of messages for this queue.
220 * <br />
221 * @return number of messages
222 */
223 long getMaxEntries() const;
224
225 /**
226 * Max number of messages for this queue.
227 * <br />
228 * @param maxEntries
229 */
230 void setMaxEntries(long maxEntries);
231
232 /**
233 * The plugin type.
234 * <br />
235 * @return e.g. "CACHE"
236 */
237 std::string getType() const;
238
239 /**
240 * The plugin type
241 * <br />
242 * @param type
243 */
244 void setType(const std::string& type);
245
246 /**
247 * The plugin version.
248 * <br />
249 * @return e.g. "1.0"
250 */
251 std::string getVersion() const;
252
253 /**
254 * The plugin version
255 * <br />
256 * @param version
257 */
258 void setVersion(const std::string& version);
259
260 /**
261 * Max number of messages for the cache of this queue.
262 * <br />
263 * @return number of messages
264 */
265 long getMaxEntriesCache() const;
266
267 /**
268 * Max number of messages for the cache of this queue.
269 * <br />
270 * @param maxEntries
271 */
272 void setMaxEntriesCache(long maxEntriesCache);
273
274 /**
275 * Max message queue size.
276 * <br />
277 * @return Get max. message queue size in Bytes
278 */
279 long getMaxBytes() const;
280
281 /**
282 * Max message queue size.
283 * <br />
284 * @return Set max. message queue size in Bytes
285 */
286 void setMaxBytes(long maxBytes);
287
288 /**
289 * Max message queue size for the cache of this queue.
290 * <br />
291 * @return Get max. message queue size in Bytes
292 */
293 long getMaxBytesCache() const;
294
295 /**
296 * Gets the storeSwapLevel for the queue (only used on cache queues).
297 * <br />
298 * @return Get storeSwapLevel in bytes.
299 */
300 long getStoreSwapLevel() const;
301
302 /**
303 * Sets the storeSwapLevel for the queue (only used on cache queues).
304 * <br />
305 * @param Set storeSwapLevel in bytes.
306 */
307 void setStoreSwapLevel(long storeSwapLevel);
308
309 /**
310 * Gets the storeSwapBytes for the queue (only used on cache queues).
311 * <br />
312 * @return Get storeSwapBytes in bytes.
313 */
314 long getStoreSwapBytes() const;
315
316 /**
317 * Sets the storeSwapBytes for the queue (only used on cache queues).
318 * <br />
319 * @param Set storeSwapBytes in bytes.
320 */
321 void setStoreSwapBytes(long storeSwapBytes);
322
323 /**
324 * Gets the reloadSwapLevel for the queue (only used on cache queues).
325 * <br />
326 * @return Get reloadSwapLevel in bytes.
327 */
328 long getReloadSwapLevel() const;
329
330 /**
331 * Sets the reloadSwapLevel for the queue (only used on cache queues).
332 * <br />
333 * @param Set reloadSwapLevel in bytes.
334 */
335 void setReloadSwapLevel(long reloadSwapLevel);
336
337 /**
338 * Gets the reloadSwapBytes for the queue (only used on cache queues).
339 * <br />
340 * @return Get reloadSwapBytes in bytes.
341 */
342 long getReloadSwapBytes() const;
343
344 /**
345 * Sets the reloadSwapBytes for the queue (only used on cache queues).
346 * <br />
347 * @param Set reloadSwapBytes in bytes.
348 */
349 void setReloadSwapBytes(long reloadSwapBytes);
350
351 /**
352 * Max message queue size for the cache of this queue.
353 * <br />
354 * @return Set max. message queue size in Bytes
355 */
356 void setMaxBytesCache(long maxBytesCache);
357
358 /**
359 * Set the callback onOverflow, it should fit to the protocol-relating.
360 *
361 * @param onOverflow The callback onOverflow, e.g. "et@mars.univers"
362 */
363 void setOnOverflow(const std::string& onOverflow);
364
365 /**
366 * Returns the onOverflow.
367 * @return e.g. "IOR:00001100022...." or "et@universe.com"
368 */
369 std::string getOnOverflow() const;
370
371 /*
372 * The default mode, when queue is full the publisher blocks until
373 * there is space again.
374 public final boolean onOverflowBlock() {
375 if (Constants.ONOVERFLOW_BLOCK.equalsIgnoreCase(getOnOverflow()))
376 return true;
377 return false;
378 }
379 */
380
381 /**
382 * Set the callback onFailure, it should fit to the protocol-relating.
383 *
384 * @param onFailure The callback onFailure, e.g. "et@mars.univers"
385 */
386 void setOnFailure(const std::string& onFailure);
387
388 /**
389 * Returns the onFailure.
390 * @return e.g. "IOR:00001100022...." or "et@universe.com"
391 */
392 std::string getOnFailure() const;
393
394 /**
395 * The default mode is to send a dead letter if callback fails permanently
396 */
397 bool onFailureDeadMessage();
398
399 /**
400 * Access all addresses, they are reference counted.
401 * @return null if none available
402 */
403 AddressVector getAddresses() const;
404
405 /**
406 * Dump state of this object into a XML ASCII std::string.
407 * <br>
408 * @param extraOffset indenting of tags for nice output
409 * @return The xml representation
410 */
411 std::string toXml(const std::string& extraOffset="") const;
412
413 /**
414 * returns the global object
415 */
416 org::xmlBlaster::util::Global& getGlobal();
417
418 // void cleanupAddresses();
419
420 /** Relating "connection", "history", "callback" etc. */
421 std::string getPropertyPrefix() const;
422 void setpropertyPrefix(const std::string& prefix);
423
424 /**
425 * The command line prefix to configure the queue or msgUnitStore
426 * @return e.g. "persistence/msgUnitStore/" or "queue/history/"
427 */
428 std::string getPrefix();
429
430 /**
431 * Helper for logging output, creates the property key for configuration (the command line property).
432 * @param prop e.g. "maxEntries"
433 * @return e.g. "-queue/history/maxEntries" or "-queue/history/maxEntriesCache"
434 */
435 std::string getPropName(const std::string& token);
436
437 std::string getRootTagName() const;
438
439 };
440
441 }}}}} // namespaces
442
443 #endif
syntax highlighted by Code2HTML, v. 0.9.1