1 /*------------------------------------------------------------------------------
2 Name: TopicProperty.cpp
3 Project: xmlBlaster.org
4 Copyright: xmlBlaster.org, see xmlBlaster-LICENSE file
5 ------------------------------------------------------------------------------*/
6
7 /**
8 * Data container handling properties of a message topic.
9 * <p />
10 * QoS Informations sent from the client to the server via the publish() method and back via the update() method<br />
11 * They are needed to control xmlBlaster and inform the client.
12 * <p />
13 * <p>
14 * This data holder is accessible through decorators, each of them allowing a specialized view on the data
15 * </p>
16 * @see org.xmlBlaster.util.qos.MsgQosSaxFactory
17 * @see org.xmlBlaster.test.classtest.qos.MsgQosFactoryTest
18 * @author xmlBlaster@marcelruff.info
19 * @author michele@laghi.eu
20 */
21
22 #include <util/qos/TopicProperty.h>
23
24 #include <util/Constants.h>
25 #include <util/Global.h>
26 #include <util/lexical_cast.h>
27
28
29
30 using namespace org::xmlBlaster::util;
31 using namespace org::xmlBlaster::util::qos::storage;
32
33 using namespace std;
34
35 namespace org { namespace xmlBlaster { namespace util { namespace qos {
36
37
38 /**
39 * A topic is destroyed 60 sec after state=UNREFERENCED is reached
40 * This default can be modified in xmlBlaster.properties:
41 * <pre>
42 * topic.destroyDelay=3600000 # One hour [millisec]
43 * </pre>
44 * Every message can set the destroyDelay value between 1 and destroyDelay_DEFAULT,
45 * -1L sets the life cycle on forever.
46 */ // TODO: Change to use glob instead of Global singleton! What about performance? Put variable into Global?
47 const long destroyDelay_DEFAULT_DEFAULT = 60*1000L;
48 /** Is readonly allows only one initial message */
49 const bool DEFAULT_readonly = false;
50
51
52 void TopicProperty::copy(const TopicProperty& prop)
53 {
54 msgUnitStoreProperty_ = NULL;
55 historyQueueProperty_ = NULL;
56 if (prop.msgUnitStoreProperty_)
57 msgUnitStoreProperty_ = new MsgUnitStoreProperty(*prop.msgUnitStoreProperty_);
58 if (prop.historyQueueProperty_)
59 historyQueueProperty_ = new HistoryQueueProperty(*prop.historyQueueProperty_);
60
61 destroyDelay_DEFAULT = prop.destroyDelay_DEFAULT;
62 destroyDelay_ = prop.destroyDelay_;
63 readonly_ = prop.readonly_;
64 }
65
66
67
68 TopicProperty::TopicProperty(Global& global)
69 : ME("TopicProperty"), global_(global), log_(global.getLog("org.xmlBlaster.util.qos")),
70 createDomEntry_(Prop<bool>(true))
71 {
72 msgUnitStoreProperty_ = NULL;
73 historyQueueProperty_= NULL;
74 destroyDelay_DEFAULT = global_.getProperty().getLongProperty("topic.destroyDelay", destroyDelay_DEFAULT_DEFAULT);
75
76 setDestroyDelay(destroyDelay_DEFAULT);
77 destroyDelay_ = destroyDelay_DEFAULT;
78 readonly_ = DEFAULT_readonly;
79 }
80
81 TopicProperty::TopicProperty(const TopicProperty& prop)
82 : ME(prop.ME), global_(prop.global_), log_(prop.log_),
83 createDomEntry_(prop.createDomEntry_)
84 {
85 copy(prop);
86 }
87
88 TopicProperty& TopicProperty::operator =(const TopicProperty& prop)
89 {
90 createDomEntry_ = prop.createDomEntry_;
91 copy(prop);
92 return *this;
93 }
94
95 TopicProperty::~TopicProperty()
96 {
97 delete msgUnitStoreProperty_;
98 delete historyQueueProperty_;
99 }
100
101 /**
102 * @return readonly Once published the message can't be changed.
103 */
104 void TopicProperty::setReadonly(bool readonly)
105 {
106 readonly_ = readonly;
107 }
108
109 /**
110 * @return true/false
111 */
112 bool TopicProperty::isReadonly()
113 {
114 return readonly_;
115 }
116
117 /**
118 * The life time of the message topic in state UNREFERENCED
119 */
120 long TopicProperty::getDestroyDelay()
121 {
122 return destroyDelay_;
123 }
124
125 /**
126 * The life time of the message topic in state UNREFERENCED
127 */
128 void TopicProperty::setDestroyDelay(long destroyDelay)
129 {
130 destroyDelay_ = destroyDelay;
131 }
132
133 /**
134 * Is the topic available in the internal DOM tree?
135 * @return true This is default and the topic is queryable with XPATH<br />
136 * false: No DOM tree is created for the topic and the topic is onvisible to XPATH queries
137 */
138 bool TopicProperty::createDomEntry() const
139 {
140 return createDomEntry_.getValue();
141 }
142
143 /**
144 * Set if the topic is available in the internal DOM tree.
145 * @param true This is default and the topic is queryable with XPATH<br />
146 * false: No DOM tree is created for the topic and the topic is onvisible to XPATH queries
147 */
148 void TopicProperty::setCreateDomEntry(bool createDomEntry) {
149 createDomEntry_.setValue(createDomEntry);
150 }
151
152 bool TopicProperty::hasMsgUnitStoreProperty()
153 {
154 return (msgUnitStoreProperty_ != NULL);
155 }
156
157 /**
158 * @return the configuration of the message store, is never null
159 */
160 MsgUnitStoreProperty TopicProperty::getMsgUnitStoreProperty()
161 {
162 if (msgUnitStoreProperty_ == NULL) {
163 msgUnitStoreProperty_ = new MsgUnitStoreProperty(global_, /*global_.getId()*/ "");
164 }
165 return *msgUnitStoreProperty_;
166 }
167
168 void TopicProperty::setMsgUnitStoreProperty(const MsgUnitStoreProperty& msgUnitStoreProperty)
169 {
170 if (msgUnitStoreProperty_) {
171 delete msgUnitStoreProperty_;
172 msgUnitStoreProperty_ = NULL;
173 }
174 msgUnitStoreProperty_ = new MsgUnitStoreProperty(msgUnitStoreProperty);
175 }
176
177 bool TopicProperty::hasHistoryQueueProperty()
178 {
179 return (historyQueueProperty_ != NULL);
180 }
181
182 /**
183 * @return the configuration of the history queue, is never null
184 */
185 HistoryQueueProperty TopicProperty::getHistoryQueueProperty()
186 {
187 if (historyQueueProperty_ == NULL) {
188 historyQueueProperty_ = new HistoryQueueProperty(global_, /*global_.getId()*/ "");
189 }
190 return *historyQueueProperty_;
191 }
192
193 void TopicProperty::setHistoryQueueProperty(const HistoryQueueProperty& historyQueueProperty)
194 {
195 if (historyQueueProperty_) {
196 delete historyQueueProperty_;
197 historyQueueProperty_ = NULL;
198 }
199 historyQueueProperty_ = new HistoryQueueProperty(historyQueueProperty);
200 }
201
202 string TopicProperty::toXml(const string& extraOffset)
203 {
204 string ret;
205 string offset = Constants::OFFSET + extraOffset;
206
207 ret += offset + "<topic";
208 if (DEFAULT_readonly != readonly_) {
209 ret += " readonly='" + lexical_cast<std::string>(readonly_) + "'";
210 }
211 if (destroyDelay_DEFAULT_DEFAULT != destroyDelay_) {
212 ret += " destroyDelay='" + lexical_cast<std::string>(destroyDelay_) + "'";
213 }
214 ret += ">";
215 //string subscriptionId;
216
217 if (hasMsgUnitStoreProperty()) {
218 ret += getMsgUnitStoreProperty().toXml(extraOffset+Constants::INDENT);
219 }
220 if (hasHistoryQueueProperty()) {
221 ret += getHistoryQueueProperty().toXml(extraOffset+Constants::INDENT);
222 }
223 ret += offset + "</topic>";
224
225 if (ret.length() < 22) {
226 return "";
227 }
228
229 return ret;
230 }
231
232 }}}}
syntax highlighted by Code2HTML, v. 0.9.1