RmsMessage.cpp
Go to the documentation of this file.
1 #include <NovaDAQUtilities/XMLDeserializationRegistry.h>
2 #include <rms/base/RmsMessage.h>
3 #include <rms/util/TimeUtils.h>
4 
5 namespace gov {
6 
7 namespace fnal {
8 
9 namespace cd {
10 
11 namespace rms {
12 
13 namespace base {
14 
15 /**
16  * Create an empty RmsMessage.
17  */
19 }
20 
21 /**
22  * Create an RmsMessage with a given body.
23  *
24  * @param body The message body to associate with
25  * this message.
26  */
28  this->body(body);
29 }
30 
31 /**
32  * Create an RMS message from a serialized string.
33  * (This constructor deserializes the input string to
34  * populate the attributes of the created instance.)
35  *
36  * @param serializedData The serialized string that is
37  * used to populate this message.
38  */
40  this->deserialize(serializedData);
41 }
42 
43 /**
44  * Creates an RMS message with the specified Tranmittable object
45  * as the message body.
46  *
47  * @param bodyObject The XMLSerializable object that will be used
48  * as the message body.
49  */
51  this->setBody(bodyObject);
52 }
53 
54 /**
55  * Get the UUID that is associated with this message.
56  *
57  * @return The UUID that is associated with this message
58  */
60  return this->id();
61 }
62 
63 /**
64  * Get the correlation ID that is associated with this
65  * message. The correlation ID is the UUID of the
66  * message to which this message is a reply to.
67  *
68  * @return The correlation ID of this message.
69  */
71  return this->correlationId().get();
72 }
73 
74 /**
75  * Get the destination that is associated with this message.
76  *
77  * @return The destination that is associated with this message.
78  */
81 
82  return destination;
83 }
84 
85 /**
86  * Get the destination that replies to this message are to
87  * be sent to.
88  *
89  * @return The destination that replies to this message
90  * are to be sent to.
91  */
93  RmsDestination destination(this->replyDestination().get());
94 
95  return destination;
96 }
97 
98 /**
99  * Get the time at which this message was sent.
100  *
101  * @return The time this message was sent.
102  */
103 boost::posix_time::ptime RmsMessage::getSentTime() const {
104  boost::posix_time::ptime sentTime =
105  util::TimeUtils::convertStringToPtime(this->sentTime());
106 
107  return sentTime;
108 }
109 
110 /**
111  * Get the correlation time. The correlation time
112  * is the time the message to which this message
113  * is a reply to was sent.
114  *
115  * @return The correlation time
116  */
117 boost::posix_time::ptime RmsMessage::getCorrelationTime() const {
118  boost::posix_time::ptime corrTime =
119  util::TimeUtils::convertStringToPtime(this->correlationTime().get());
120 
121  return corrTime;
122 }
123 
124 /**
125  * Get the time to live, in milliseconds, for this message.
126  *
127  * @return The time to live, in milliseconds, for this message.
128  */
130  return this->timeToLive();
131 }
132 
133 /**
134  * Get the priority of this message.
135  *
136  * @return The priority of this message.
137  */
139  return this->priority().get();
140 }
141 
142 /**
143  * Get the message source.
144  *
145  * @return The message source.
146  */
148  RmsMessageSource source(this->source().get());
149 
150  return source;
151 }
152 
153 /**
154  * Get the message body.
155  *
156  * @return The message body.
157  */
159  RmsMessageBody body(this->body().get());
160 
161  return body;
162 }
163 
164 /**
165  * Get the message body as a XMLSerializable object.
166  *
167  * @return A shared pointer to a XMLSerializable object created from
168  * the message body. The shared pointer will be empty
169  * if the RmsMessage body was empty.
170  */
171 boost::shared_ptr<novadaq::XMLSerializable> RmsMessage::getBodyObject() const {
172  boost::shared_ptr<novadaq::XMLSerializable> bodyObjectPtr;
173 
174  // fetch body quantities
175  RmsMessageBody ourBody = this->getBody();
176  std::string className = ourBody.getClassName();
177 
178  // create an instance of the class that is in the body
181  bodyObjectPtr = registry.createObject(className);
182 
183  // deserialize the body contents into the object
184  if (bodyObjectPtr.get() != NULL) {
185  bodyObjectPtr->deserialize(ourBody.getContent());
186  }
187 
188  // return the shared pointer
189  return bodyObjectPtr;
190 }
191 
192 /**
193  * Set the ID of this message.
194  *
195  * @param uuid An identifier that will uniquely identify
196  * this message.
197  */
198 void RmsMessage::setId(const std::string uuid) {
199  this->id(uuid);
200 }
201 
202 /**
203  * Set the correlation ID of this message. The correlation
204  * ID is the ID of the message of which this message is a reply
205  * to.
206  *
207  * @param uuid The correlation ID.
208  */
210  this->correlationId(uuid);
211 }
212 
213 /**
214  * Set the destination of this message.
215  *
216  * @param destination The new destination.
217  */
219  this->destination(destination);
220 }
221 
222 /**
223  * Set the destination that replies to this message
224  * will be sent to.
225  *
226  * @param destination The destination that replies to this
227  * message will be sent to.
228  */
230  this->replyDestination(destination);
231 }
232 
233 /**
234  * Set the time the message was sent to now.
235  */
237  boost::posix_time::ptime now = util::TimeUtils::getUniversalPtime();
238  this->setSentTime(now);
239 }
240 
241 /**
242  * Set the time the message was sent.
243  *
244  * @param timestamp The time the messages was sent.
245  */
246 void RmsMessage::setSentTime(boost::posix_time::ptime timestamp) {
247  this->sentTime(util::TimeUtils::convertPtimeToString(timestamp));
248 }
249 
250 /**
251  * Set the time that the message for which this message is
252  * a reply to was sent.
253  *
254  * @param timestamp The correlation time.
255  */
256 void RmsMessage::setCorrelationTime(boost::posix_time::ptime timestamp) {
257  this->correlationTime(util::TimeUtils::convertPtimeToString(timestamp));
258 }
259 
260 /**
261  * Set the time to live of this message, in milliseconds.
262  *
263  * @param msec The time to live in milliseconds.
264  */
265 void RmsMessage::setTimeToLive(long msec) {
266  this->timeToLive(msec);
267 }
268 
269 /**
270  * Set the priority of this message.
271  *
272  * @param value The priority of the message.
273  */
275  this->priority(value);
276 }
277 
278 /**
279  * Set the source for this message.
280  *
281  * @param source The source for this message.
282  */
284  this->source(source);
285 }
286 
287 /**
288  * Set the body of this message.
289  *
290  * @param body The body for this message.
291  *
292  * @bug implement
293  */
295  this->body(body);
296 }
297 
298 /**
299  * Set the body of this message.
300  *
301  * @param bodyObject The XMLSerializable object that serves as the body
302  * of this message.
303  */
307  translateClassName(bodyObject.getClassName()));
308  body.setContent(bodyObject.serialize());
309  this->body(body);
310 }
311 
312 /**
313  * Set the status of this message.
314  *
315  * @param messageStatus The status of this message.
316  */
317 void RmsMessage::setMessageStatus(const RmsStatus& messageStatus) {
318  _messageStatus = messageStatus;
319 }
320 
321 /**
322  * Get the status of this message.
323  *
324  * @return The status of this message.
325  */
327  return _messageStatus;
328 }
329 
330 /**
331  * Create a reply to this message. This will return
332  * an empty RmsMessage with the destination, reply destination,
333  * and correlation fields filled out.
334  *
335  * <b> Note that the reply destination will be wrong here. We'll
336  * have the provider correct that before it sends the reply. </b>
337  *
338  * @return An RmsMessage that is setup to be a reply to this
339  * message.
340  */
341 boost::shared_ptr<RmsMessage> RmsMessage::createReply() const {
342  boost::shared_ptr<RmsMessage> replyMsg (new RmsMessage);
343  replyMsg->setCorrelationId(getId());
344 
348  replyMsg->setDestination(newDest);
349 
350  replyMsg->setTimeToLive(getTimeToLive());
351  return replyMsg;
352 }
353 
354 } // end of namespace base
355 
356 } // end of namespace rms
357 
358 } // end of namespace cd
359 
360 } // end of namespace fnal
361 
362 } // end of namespace gov
::xsd::cxx::tree::id< char, ncname > id
Definition: Database.h:165
boost::shared_ptr< novadaq::XMLSerializable > getBodyObject() const
Definition: RmsMessage.cpp:171
RmsDestination getReplyDestination() const
Definition: RmsMessage.cpp:92
static std::string convertPtimeToString(boost::posix_time::ptime inputTime)
Definition: TimeUtils.h:50
void setMessageStatus(const RmsStatus &messageStatus)
Definition: RmsMessage.cpp:317
string body
Definition: readPickles.py:54
void setId(const std::string uuid)
Definition: RmsMessage.cpp:198
const XML_Char int const XML_Char int const XML_Char * base
Definition: expat.h:331
static boost::posix_time::ptime getUniversalPtime()
Definition: TimeUtils.h:35
static const std::string REPLY_MESSAGE_TYPE
void setSource(const RmsMessageSource &source)
Definition: RmsMessage.cpp:283
boost::posix_time::ptime getCorrelationTime() const
Definition: RmsMessage.cpp:117
RmsMessageBody getBody() const
Definition: RmsMessage.cpp:158
boost::shared_ptr< RmsMessage > createReply() const
Definition: RmsMessage.cpp:341
const XML_Char int const XML_Char * value
Definition: expat.h:331
void setCorrelationTime(boost::posix_time::ptime timestamp)
Definition: RmsMessage.cpp:256
void setBody(const RmsMessageBody &body)
Definition: RmsMessage.cpp:294
Definition: fnal.py:1
RmsMessageSource getSource() const
Definition: RmsMessage.cpp:147
const char * source
Definition: lz4.h:436
RmsDestination getDestination() const
Definition: RmsMessage.cpp:79
static XMLDeserializationRegistry & getInstance()
void setProperty(std::string name, std::string value)
void setDestination(const RmsDestination &destination)
Definition: RmsMessage.cpp:218
virtual std::string getClassName() const =0
boost::posix_time::ptime getSentTime() const
Definition: RmsMessage.cpp:103
const std::string getId() const
Definition: RmsMessage.cpp:59
static boost::posix_time::ptime convertStringToPtime(std::string inputString)
Definition: TimeUtils.h:102
virtual std::string serialize() const =0
void setReplyDestination(const RmsDestination &destination)
Definition: RmsMessage.cpp:229
void setCorrelationId(const std::string uuid)
Definition: RmsMessage.cpp:209
c cd(1)
boost::shared_ptr< XMLSerializable > createObject(std::string className)
static const std::string MESSAGE_TYPE_PROPERTY_NAME
const std::string getCorrelationId() const
Definition: RmsMessage.cpp:70
enum BeamMode string