1 /*------------------------------------------------------------------------------
2 Name: org::xmlBlaster::util::qos::address::AddressBase.h
3 Project: xmlBlaster.org
4 Copyright: xmlBlaster.org, see xmlBlaster-LICENSE file
5 Comment: Holding connect address and callback address std::string including protocol
6 Version: $Id: AddressBase.h 14269 2005-12-06 12:25:08Z ruff $
7 ------------------------------------------------------------------------------*/
8
9 /**
10 * Abstract helper class holding connect address and callback address std::string
11 * and protocol std::string.
12 * <p />
13 * See examples in the implementing classes
14 * @see org::xmlBlaster::util::qos::address::Address
15 * @see org::xmlBlaster::util::qos::address::CallbackAddress
16 */
17
18 #ifndef _UTIL_CFG_ADDRESSBASE_H
19 #define _UTIL_CFG_ADDRESSBASE_H
20
21 #include <util/xmlBlasterDef.h>
22 #include <util/Constants.h>
23 #include <util/I_Log.h>
24 #include <util/qos/ClientProperty.h>
25 #include <string>
26 #include <map>
27 #include <util/ReferenceCounterBase.h>
28 #include <util/ReferenceHolder.h>
29
30 namespace org { namespace xmlBlaster { namespace util { namespace qos { namespace address {
31
32 extern Dll_Export const int DEFAULT_port;
33 extern Dll_Export const std::string DEFAULT_type;
34 extern Dll_Export const std::string DEFAULT_version;
35 extern Dll_Export const long DEFAULT_collectTime;
36 extern Dll_Export const int DEFAULT_burstModeMaxEntries;
37 extern Dll_Export const long DEFAULT_burstModeMaxBytes;
38 extern Dll_Export const bool DEFAULT_oneway;
39 extern Dll_Export const bool DEFAULT_dispatcherActive;
40 extern Dll_Export const std::string DEFAULT_compressType;
41 extern Dll_Export const long DEFAULT_minSize;
42 extern Dll_Export const bool DEFAULT_ptpAllowed;
43 extern Dll_Export const std::string DEFAULT_sessionId;
44 extern Dll_Export const bool DEFAULT_useForSubjectQueue;
45 extern Dll_Export std::string DEFAULT_dispatchPlugin;
46 extern Dll_Export std::string ATTRIBUTE_TAG;
47
48
49
50 class Dll_Export AddressBase : public org::xmlBlaster::util::ReferenceCounterBase
51 {
52 friend class AddressFactory;
53
54 public: typedef std::map<std::string, org::xmlBlaster::util::qos::ClientProperty> ClientPropertyMap;
55
56 private:
57 int port_;
58
59 /**
60 * Sets the root xml tag, <callback> or <address>
61 */
62 void setRootTag(const std::string& rootTag)
63 {
64 rootTag_ = rootTag;
65 }
66
67 protected:
68 std::string ME;
69 org::xmlBlaster::util::Global& global_;
70 org::xmlBlaster::util::I_Log& log_;
71
72 std::string rootTag_;
73
74 /** The node id to which we want to connect */
75 std::string nodeId_;
76
77 /** TODO: Move this attribute to CbQueueProperty.java */
78 long maxEntries_; // only used in org::xmlBlaster::util::qos::address::Address
79
80 /** The unique address, e.g. the CORBA IOR std::string */
81 mutable std::string address_;
82
83 mutable std::string hostname_;
84 bool isHardcodedHostname_; // = false; // set to true if setHostname() was explicitly called by user
85
86 /** The unique protocol type, e.g. "IOR" */
87 std::string type_; // = DEFAULT_type;
88
89 /** The protocol version, e.g. "1.0" */
90 std::string version_; // = DEFAULT_version;
91
92 /** BurstMode: The time to collect messages for publish/update */
93 long collectTime_; // = DEFAULT_collectTime;
94
95 /**
96 * How many messages maximum shall the callback thread take in one bulk out of the
97 * callback queue and deliver to the client in one bulk.
98 * Defaults to all available of highest priority
99 */
100 int burstModeMaxEntries_; // = 1
101
102 /**
103 * How many bytes maximum shall the callback thread take in one bulk out of the
104 * callback queue and deliver to the client in one bulk.
105 */
106 long burstModeMaxBytes_; // = -1L
107
108 /** Ping interval: pinging every given milliseconds */
109 long pingInterval_; // = getDefaultPingInterval();
110
111 /** How often to retry if connection fails */
112 int retries_; // = getDefaultRetries();
113
114 /** Delay between connection retries in milliseconds */
115 long delay_; // = getDefaultDelay();
116
117 /**
118 * Shall the update() or publish() messages be send oneway (no application level ACK).
119 * <p />
120 * For more info read the CORBA spec. Only CORBA and our native SOCKET protocol support oneway.
121 * Defaults to false (the update() or publish() has a return value and can throw an exception).
122 */
123 bool oneway_; // = DEFAULT_oneway;
124
125 /**
126 * Control if the dispatcher is activated on login, i.e. if it is
127 * able to deliver asynchronous messages from the queue.
128 * defaults to true
129 */
130 bool dispatcherActive_; // = DEFAULT_dispatcherActive;
131
132 /** Compress messages if set to "gzip" or "zip" */
133 std::string compressType_; // = DEFAULT_compressType;
134
135 /** Messages bigger this size in bytes are compressed */
136 long minSize_; // = DEFAULT_minSize;
137
138 /** PtP messages wanted? Defaults to true, false prevents spamming */
139 bool ptpAllowed_; // = DEFAULT_ptpAllowed;
140
141 /** The identifier sent to the callback client, the client can decide if he trusts this invocation */
142 std::string sessionId_; // = DEFAULT_sessionId;
143
144 /** Shall this session callback be used for subjectQueue messages as well? For <callback> only */
145 bool useForSubjectQueue_; // = DEFAULT_useForSubjectQueue;
146
147 /**
148 * Does client whish a dispatcher plugin.
149 * <p>
150 * Set to "undef" forces to switch off, or e.g. "Priority,1.0" to access the PriorizedDispatchPlugin
151 * </p>
152 * <p>
153 * Setting it to 'null' (which is the default) lets the server choose the plugin
154 * </p>
155 * @see <a href="http://www.xmlBlaster.org/xmlBlaster/doc/requirements/dispatch.control.plugin.html">The dispatch.control.plugin requirement</a>
156 */
157 std::string dispatchPlugin_; // = DEFAULT_dispatchPlugin;
158
159 ClientPropertyMap attributes_;
160
161 void initHostname(const std::string& hostname)
162 {
163 hostname_ = hostname;
164 address_ = ""; // reset cache
165 }
166
167 void copy(const AddressBase& addr);
168
169 long defaultPingInterval_;
170 int defaultRetries_;
171 long defaultDelay_;
172
173 public:
174
175 /**
176 * common constructor
177 */
178 AddressBase(org::xmlBlaster::util::Global& global, const std::string& rootTag="");
179
180 /**
181 * copy constructor
182 */
183 AddressBase(const AddressBase& addr);
184
185 /**
186 * Assignment operator
187 */
188 AddressBase& operator =(const AddressBase& addr);
189
190 virtual ~AddressBase();
191
192 /**
193 * A nice human readable name for this address (used for logging)
194 */
195 std::string getName();
196
197 /**
198 * Check if supplied address would connect to the address of this instance
199 */
200 bool isSameAddress(AddressBase& other);
201
202 /**
203 * Show some important settings for logging
204 */
205 std::string getSettings() const;
206
207 void addAttribute(const ClientProperty& attribute);
208
209 const ClientPropertyMap& getAttributes() const;
210
211 /**
212 * The address and callbackAddress may contain additional attributes
213 * which are passed to the protocol plugin
214 */
215 std::string dumpAttributes(const std::string& extraOffset, bool clearText=false) const;
216
217 /**
218 * @param type The protocol type, e.g. "IOR", "SOCKET", "XMLRPC"
219 */
220 void setType(const std::string& type);
221
222 /**
223 * @param version The protocol version, e.g. "1.0"
224 */
225 void setVersion(const std::string& version);
226
227 /**
228 * Updates the internal address as well.
229 * @param host An IP or DNS
230 */
231 void setHostname(const std::string& host);
232
233 /**
234 * @return true if the bootstrapHostname is explicitly set by user with setHostname()
235 * false if it is determined automatically
236 */
237 bool isHardcodedHostname();
238
239 /**
240 * Check if a bootstrapHostname is set already
241 */
242 bool hasHostname();
243
244 /**
245 * @return The Hostname, IP or "" if not known
246 */
247 std::string getHostname() const;
248
249 /**
250 * Set the bootstrapping port.
251 * Updates the internal address as well.
252 */
253 void setPort(int port);
254
255 int getPort() const;
256
257 /**
258 * Set the callback address, it should fit to the protocol-type.
259 *
260 * @param address The callback address, e.g. "et@mars.univers"
261 */
262 void setAddress(const std::string& address);
263
264 /**
265 * Returns the address.
266 * @return e.g. "IOR:00001100022...." or "et@universe.com" or "socket://192.168.1.1:7607" or ""
267 */
268 std::string getRawAddress() const;
269
270 /**
271 * Returns the protocol type.
272 * @return e.g. "SOCKET" or "IOR" (never null).
273 */
274 std::string getType() const;
275
276 /**
277 * Returns the protocol version.
278 * @return e.g. "1.0" or null
279 */
280 std::string getVersion() const;
281
282 /**
283 * What to do if max retries is exhausted.
284 * <p />
285 * This mode is currently not configurable, we always destroy the login session.
286 * This is interpreted only server side if callback fails.
287 * @return Constants.ONEXHAUST_KILL_SESSION="killSession"
288 */
289 std::string getOnExhaust() const;
290
291 /**
292 * Kill login session if max callback retries is exhausted?
293 */
294 bool getOnExhaustKillSession() const;
295
296 /**
297 * BurstMode: The time span to collect messages before sending.
298 * @return The time to collect in milliseconds
299 */
300 long getCollectTime() const;
301
302 /**
303 * BurstMode: The time to collect messages for sending in a bulk.
304 * @param The time to collect in milliseconds
305 */
306 void setCollectTime(long collectTime);
307
308 /**
309 * How many messages maximum shall the callback thread take in one bulk out of the
310 * callback queue and deliver to the client in one bulk.
311 * -1 is unlimited (all of the available messages with same priority are send)
312 */
313 int getBurstModeMaxEntries() const;
314
315 /**
316 * How many messages maximum shall the callback thread take in one bulk out of the
317 * callback queue and deliver to the client in one bulk.
318 * @param -1 takes all available messages from highest priority in a bulk (default)
319 * only limited by burstModeMaxBytes; Defaults to 1
320 */
321 void setBurstModeMaxEntries(int burstModeMaxEntries);
322
323 /**
324 * How many bytes maximum shall the callback thread take in one bulk out of the
325 * callback queue and deliver to the client in one bulk.
326 */
327 long getBurstModeMaxBytes() const;
328
329 /**
330 * How many bytes maximum shall the callback thread take in one bulk out of the
331 * callback queue and deliver to the client in one bulk.
332 * @param -1 takes all available messages from highest priority in a bulk (default)
333 * only limited by burstModeMaxEntries
334 */
335 void setBurstModeMaxBytes(long BurstModeMaxBytes);
336
337 /**
338 * How long to wait between pings to the callback server.
339 * @return The pause time between pings in millis
340 */
341 long getPingInterval() const;
342
343 /**
344 * How long to wait between pings to the callback server.
345 * @param pingInterval The pause time between pings in millis
346 */
347 void setPingInterval(long pingInterval);
348
349 /**
350 * How often shall we retry callback attempt on callback failure
351 * @return -1 forever, 0 no retry, > 0 number of retries
352 */
353 int getRetries() const;
354
355 /**
356 * How often shall we retry callback attempt on callback failure
357 * @param -1 forever, 0 no retry, > 0 number of retries
358 */
359 void setRetries(int retries);
360
361 /**
362 * Delay between callback retries in milliseconds, defaults to one minute
363 * @return The delay in millisconds
364 */
365 long getDelay() const;
366
367 /**
368 * Delay between callback retries in milliseconds, defaults to one minute
369 */
370 void setDelay(long delay);
371
372 /**
373 * Shall the publish() or callback update() message be oneway.
374 * Is only with CORBA and our native SOCKET protocol supported
375 * @return true if you want to force oneway sending
376 */
377 bool oneway() const;
378
379 /**
380 * Shall the publish() or callback update() message be oneway.
381 * Is only with CORBA and our native SOCKET protocol supported
382 * @param oneway false is default
383 */
384 void setOneway(bool oneway);
385
386 /**
387 * Inhibits/activates the delivery of asynchronous dispatches of messages.
388 * @param dispatcherActive
389 */
390 void setDispatcherActive(bool dispatcherActive);
391
392 /**
393 * @return true if the dispatcher is currently activated, i.e. if it is
394 * able to deliver asynchronous messages from the queue.
395 */
396 bool isDispatcherActive() const;
397
398 /**
399 * @param Set if we accept point to point messages
400 */
401 void setPtpAllowed(bool ptpAllowed);
402
403 /**
404 * @return true if we may send PtP messages
405 */
406 bool isPtpAllowed();
407
408 void setCompressType(const std::string& compressType);
409
410 /**
411 * The identifier sent to the callback client, the client can decide if he trusts this invocation
412 * @return never null
413 */
414 std::string getSecretSessionId() const;
415
416 /** The identifier sent to the callback client, the client can decide if he trusts this invocation */
417 void setSecretSessionId(const std::string& sessionId);
418
419 /**
420 * Get the compression method.
421 * @return "" No compression
422 */
423 std::string getCompressType() const;
424
425 /**
426 * Messages bigger this size in bytes are compressed.
427 * <br />
428 * Note: This value is only used if compressType is set to a supported value
429 * @return size in bytes
430 */
431 long getMinSize() const;
432
433 /**
434 * Messages bigger this size in bytes are compressed.
435 * <br />
436 * Note: This value is only evaluated if compressType is set to a supported value
437 * @return size in bytes
438 */
439 void setMinSize(long minSize);
440
441 /**
442 * Specify your dispatcher plugin configuration.
443 * <p>
444 * Set to "undef" to switch off, or to e.g. "Priority,1.0" to access the PriorizedDispatchPlugin
445 * </p>
446 * <p>
447 * This overwrites the xmlBlaster.properties default setting e.g.:
448 * <pre>
449 * DispatchPlugin[Priority][1.0]=org.xmlBlaster.util.dispatch.plugins.prio.PriorizedDispatchPlugin
450 * DispatchPlugin[SlowMotion][1.0]=org.xmlBlaster.util.dispatch.plugins.motion.SlowMotion
451 * DispatchPlugin/defaultPlugin=Priority,1.0
452 * </pre>
453 * </p>
454 * @see <a href="http://www.xmlBlaster.org/xmlBlaster/doc/requirements/dispatch.control.plugin.html">The dispatch.control.plugin requirement</a>
455 */
456 void setDispatchPlugin(const std::string& dispatchPlugin);
457
458 /**
459 * @return "undef" or e.g. "Priority,1.0"
460 */
461 std::string getDispatchPlugin() const;
462
463 const ClientPropertyMap& getClientProperties() const;
464
465 /**
466 * Dump state of this object into a XML ASCII std::string.
467 * <br>
468 * Only none default values are dumped for performance reasons
469 * @param extraOffset indenting of tags for nice output
470 * @return The xml representation
471 */
472 std::string toXml(const std::string& extraOffset = "") const;
473 };
474
475 typedef org::xmlBlaster::util::ReferenceHolder<AddressBase> AddressBaseRef;
476
477 }}}}}
478
479 #endif
syntax highlighted by Code2HTML, v. 0.9.1