1 /*------------------------------------------------------------------------------
2 Name: ClientQueueProperty.cpp
3 Project: xmlBlaster.org
4 Copyright: xmlBlaster.org, see xmlBlaster-LICENSE file
5 Comment: Holding callback queue properties
6 ------------------------------------------------------------------------------*/
7
8 #include <util/qos/storage/ClientQueueProperty.h>
9 #include <util/lexical_cast.h>
10 #include <util/Global.h>
11
12 namespace org { namespace xmlBlaster { namespace util { namespace qos { namespace storage {
13
14 using namespace std;
15 using namespace org::xmlBlaster::util;
16 using namespace org::xmlBlaster::util::qos::address;
17
18 ClientQueueProperty::ClientQueueProperty(Global& global, const string& nodeId) :
19 QueuePropertyBase(global, nodeId)
20 {
21 ME = "ClientQueueProperty";
22 relating_ = Constants::RELATING_CLIENT; // == "connection"
23 QueuePropertyBase::initialize(Constants::RELATING_CLIENT); // == "connection"
24
25 /*
26 # if !defined (XMLBLASTER_PERSISTENT_QUEUE) || !defined (XMLBLASTER_PERSISTENT_QUEUE_SQLITE3)
27 // TODO !!!: Hack: We need to force default to RAM instead of CACHE
28 // as we have no C++ CACHE implementation (see QueueFactory.cpp for the other workaround)
29 string envType = global_.getProperty().getStringProperty("queue/connection/type", "");
30 if (envType == "") {
31 setType("RAM");
32 }
33 # endif
34 */
35 }
36
37 ClientQueueProperty::ClientQueueProperty(const QueuePropertyBase& prop)
38 : QueuePropertyBase(prop)
39 {
40 }
41
42 ClientQueueProperty& ClientQueueProperty::operator =(const QueuePropertyBase& prop)
43 {
44 copy(prop);
45 return *this;
46 }
47
48 /**
49 * Show some important settings for logging
50 */
51 string ClientQueueProperty::getSettings()
52 {
53 string ret;
54 ret += string("type=") + getType() + string(" onOverflow=") +
55 getOnOverflow() + string(" onFailure=") + getOnFailure() +
56 string(" maxEntries=") + lexical_cast<std::string>(getMaxEntries());
57 if (!addressArr_.empty())
58 ret += string(" ") + getCurrentAddress()->getSettings();
59 return ret;
60 }
61
62 /**
63 */
64 void ClientQueueProperty::setAddress(const AddressBaseRef& address)
65 {
66 // this differes from the current java code (2002-12-07) since it allows
67 // multiple addresses
68 addressArr_.insert(addressArr_.begin(), address);
69 }
70
71 /**
72 * clears up all addresses and allocates new ones.
73 */
74 void ClientQueueProperty::setAddresses(const AddressVector& addresses)
75 {
76 addressArr_ = AddressVector(addresses);
77 }
78
79
80 /**
81 * @return If none is available a default is created
82 */
83 AddressBaseRef ClientQueueProperty::getCurrentAddress()
84 {
85 if (addressArr_.empty()) {
86 addressArr_.push_back(new Address(global_));
87 }
88 // otherwise get the last one added
89 return *addressArr_.begin();
90 }
91
92 /**
93 * Get a usage string for the connection parameters
94 */
95 string ClientQueueProperty::usage()
96 {
97 string text = "";
98 text += string("Control client side failsafe queue properties (message recorder):\n");
99 text += string(" -queue/connection/maxEntries [") + lexical_cast<std::string>(DEFAULT_maxEntriesDefault) + string("]\n");
100 text += string(" The maximum allowed number of messages in this queue.\n");
101 text += string(" 0 switches recording of invocations off, -1 sets it to unlimited.\n");
102 text += string(" -queue/connection/type [CACHE].\n");
103 text += string(" The C++ client side queue plugin type, choose 'RAM' for a pure memory based queue.\n");
104 # if defined(XMLBLASTER_PERSISTENT_QUEUE) || defined(XMLBLASTER_PERSISTENT_QUEUE_SQLITE3)
105 text += string(" Choose 'SQLite' for a pure persistent client side queue.\n");
106 # else
107 text += string(" Please recompile with -DXMLBLASTER_PERSISTENT_QUEUE_SQLITE3=1 defined\n");
108 text += string(" to have a persistent client side queue 'SQLite'.\n");
109 # endif
110 text += string(" -queue/connection/version ") + DEFAULT_version + string("].\n");
111 text += string(" The queue plugin type.\n");
112 text += string(" -queue/connection/maxBytes [" + lexical_cast<std::string>(DEFAULT_bytesDefault) + "].\n");
113 text += string(" The maximum size in bytes of this queue.\n");
114 # if defined(XMLBLASTER_PERSISTENT_QUEUE) || defined (XMLBLASTER_PERSISTENT_QUEUE_SQLITE3)
115 text += string("SQLite specific setting:\n");
116 text += string(" -queue/connection/url [xmlBlasterClientCpp.db].\n");
117 text += string(" The location and file name of the database.\n");
118 # endif
119 //text += string(" -queue/connection/expires If not otherwise noted a queue dies after these milliseconds [" + DEFAULT_expiresDefault + "].\n";
120 //text += string(" -queue/connection/onOverflow What happens if queue is full. " + Constants.ONOVERFLOW_BLOCK + " | " + Constants.ONOVERFLOW_DEADMESSAGE + " [" + DEFAULT_onOverflow + "]\n";
121 //text += string(" -queue/connection/onFailure What happens if the data sink connection has a failure [" + DEFAULT_onFailure + "]\n";
122 return text;
123 }
124
125 }}}}} // namespace
126
127 #ifdef _XMLBLASTER_CLASSTEST
128
129 using namespace std;
130 using namespace org::xmlBlaster::util::qos::storage;
131
132 /** For testing: java org.xmlBlaster.authentication.plugins.simple.SecurityQos */
133 int main(int args, char* argv[])
134 {
135 Global& glob = Global::getInstance();
136 glob.initialize(args, argv);
137 ClientQueueProperty prop(glob, "");
138 cout << prop.toXml() << endl;
139 Address adr(glob, "EMAIL");
140 adr.setAddress("et@mars.sun");
141 prop.setAddress(adr);
142 cout << prop.toXml() << endl;
143 }
144
145 #endif
syntax highlighted by Code2HTML, v. 0.9.1