LSSTApplications  10.0+286,10.0+36,10.0+46,10.0-2-g4f67435,10.1+152,10.1+37,11.0,11.0+1,11.0-1-g47edd16,11.0-1-g60db491,11.0-1-g7418c06,11.0-2-g04d2804,11.0-2-g68503cd,11.0-2-g818369d,11.0-2-gb8b8ce7
LSSTDataManagementBasePackage
CommandEvent.cc
Go to the documentation of this file.
1 // -*- lsst-c++ -*-
2 
3 /*
4  * LSST Data Management System
5  * Copyright 2008-2015 AURA/LSST.
6  *
7  * This product includes software developed by the
8  * LSST Project (http://www.lsst.org/).
9  *
10  * This program is free software: you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation, either version 3 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the LSST License Statement and
21  * the GNU General Public License along with this program. If not,
22  * see <https://www.lsstcorp.org/LegalNotices/>.
23  */
24 
33 #include <iomanip>
34 #include <sstream>
35 #include <stdexcept>
36 #include <limits>
37 #include <cstring>
38 
41 #include "lsst/ctrl/events/Event.h"
44 #include "lsst/daf/base/DateTime.h"
46 #include "lsst/pex/exceptions.h"
47 #include <sys/socket.h>
48 #include <sys/un.h>
49 #include <netdb.h>
50 #include <time.h>
51 
52 #include <activemq/core/ActiveMQConnectionFactory.h>
53 
54 
55 using namespace std;
56 
57 namespace lsst {
58 namespace ctrl {
59 namespace events {
60 
61 const std::string CommandEvent::ORIG_HOSTNAME = "ORIG_HOSTNAME";
62 const std::string CommandEvent::ORIG_PROCESSID = "ORIG_PROCESSID";
63 const std::string CommandEvent::ORIG_LOCALID = "ORIG_LOCALID";
64 
65 const std::string CommandEvent::DEST_HOSTNAME = "DEST_HOSTNAME";
66 const std::string CommandEvent::DEST_PROCESSID = "DEST_PROCESSID";
67 const std::string CommandEvent::DEST_LOCALID = "DEST_LOCALID";
68 
69 CommandEvent::CommandEvent() : Event() {
70  _init();
71 }
72 
73 
77  _keywords.insert(ORIG_HOSTNAME);
78  _keywords.insert(ORIG_PROCESSID);
79  _keywords.insert(ORIG_LOCALID);
80 
81  _keywords.insert(DEST_HOSTNAME);
82  _keywords.insert(DEST_PROCESSID);
83  _keywords.insert(DEST_LOCALID);
84 }
85 
86 CommandEvent::CommandEvent(cms::TextMessage *msg) : Event(msg) {
87  _init();
88 
89 
90  _psp->set(ORIG_HOSTNAME, (std::string)msg->getStringProperty(ORIG_HOSTNAME));
91  _psp->set(ORIG_PROCESSID, (int)msg->getIntProperty(ORIG_PROCESSID));
92  _psp->set(ORIG_LOCALID, (int)msg->getIntProperty(ORIG_LOCALID));
93 
94  _psp->set(DEST_HOSTNAME, (std::string)msg->getStringProperty(DEST_HOSTNAME));
95  _psp->set(DEST_PROCESSID, (int)msg->getIntProperty(DEST_PROCESSID));
96  _psp->set(DEST_LOCALID, (int)msg->getIntProperty(DEST_LOCALID));
97 
98 }
99 
100 CommandEvent::CommandEvent(LocationId const& originator, LocationId const& destination, CONST_PTR(PropertySet) const& psp) : Event(*psp) {
101  _constructor(originator, destination);
102 }
103 
104 CommandEvent::CommandEvent(LocationId const& originator, LocationId const& destination, PropertySet const& ps) : Event(ps) {
105  _constructor(originator, destination);
106 }
107 
108 CommandEvent::CommandEvent(LocationId const& originator, LocationId const& destination, PropertySet const& ps, PropertySet const& filterable) : Event(ps, filterable) {
109  _constructor(originator, destination);
110 }
111 
112 CommandEvent::CommandEvent(std::string const& runId, LocationId const& originator, LocationId const& destination, CONST_PTR(PropertySet) const& psp) : Event(runId, *psp) {
113  _constructor(originator, destination);
114 }
115 
116 CommandEvent::CommandEvent( std::string const& runId, LocationId const& originator, LocationId const& destination, PropertySet const& ps) : Event(runId, ps) {
117  _constructor(originator, destination);
118 }
119 
120 CommandEvent::CommandEvent(std::string const& runId, LocationId const& originator, LocationId const& destination, PropertySet const& ps, PropertySet const& filterable) : Event(runId, ps, filterable) {
121  _constructor(originator, destination);
122 }
123 
128 void CommandEvent::_constructor(LocationId const& originator, LocationId const& destination) {
129  _init();
130 
131  _psp->set(ORIG_HOSTNAME, originator.getHostName());
132  _psp->set(ORIG_PROCESSID, originator.getProcessID());
133  _psp->set(ORIG_LOCALID, originator.getLocalID());
134 
135  _psp->set(DEST_HOSTNAME, destination.getHostName());
136  _psp->set(DEST_PROCESSID, destination.getProcessID());
137  _psp->set(DEST_LOCALID, destination.getLocalID());
138 
140 
141 }
142 
143 void CommandEvent::populateHeader(cms::TextMessage* msg) const {
145 
146  msg->setStringProperty(ORIG_HOSTNAME, _psp->get<std::string>(ORIG_HOSTNAME));
147  msg->setIntProperty(ORIG_PROCESSID, _psp->get<int>(ORIG_PROCESSID));
148  msg->setIntProperty(ORIG_LOCALID, _psp->get<int>(ORIG_LOCALID));
149 
150  msg->setStringProperty(DEST_HOSTNAME, _psp->get<std::string>(DEST_HOSTNAME));
151  msg->setIntProperty(DEST_PROCESSID, _psp->get<int>(DEST_PROCESSID));
152  msg->setIntProperty(DEST_LOCALID, _psp->get<int>(DEST_LOCALID));
153 }
154 
156  std::string hostname = _psp->get<std::string>(ORIG_HOSTNAME);
157  int pid = _psp->get<int>(ORIG_PROCESSID);
158  int local = _psp->get<int>(ORIG_LOCALID);
159  return LocationId::Ptr(new LocationId(hostname, pid, local));
160 }
161 
163  std::string hostname = _psp->get<std::string>(DEST_HOSTNAME);
164  int pid = _psp->get<int>(DEST_PROCESSID);
165  int local = _psp->get<int>(DEST_LOCALID);
166  return LocationId::Ptr(new LocationId(hostname, pid, local));
167 }
168 
170 }
171 
172 }}}
static const std::string DEST_LOCALID
Definition: CommandEvent.h:72
CommandEvent()
Creates CommandEvent which contains a PropertySet consisting of an origination location ID and a dest...
Definition: CommandEvent.cc:69
static const std::string ORIG_HOSTNAME
Definition: CommandEvent.h:66
defines the LocationId class
Include files required for standard LSST Exception handling.
PropertySet::Ptr _psp
Definition: Event.h:236
static const std::string ORIG_PROCESSID
Definition: CommandEvent.h:67
boost::shared_ptr< LocationId > Ptr
Definition: LocationId.h:52
defines EventTypes
virtual void populateHeader(cms::TextMessage *msg) const
populate a cms::TextMessage header with properties
static const std::string DEST_PROCESSID
Definition: CommandEvent.h:71
virtual void populateHeader(cms::TextMessage *msg) const
populate a cms::TextMessage header with properties
Definition: Event.cc:241
void _constructor(LocationId const &originator, LocationId const &destination)
defines the CommandEvent class
set< std::string > _keywords
Definition: Event.h:238
defines the Event class
static const std::string ORIG_LOCALID
Definition: CommandEvent.h:68
Interface for DateTime class.
LocationId::Ptr getOriginator() const
retrieve an object containing the OriginatoDesination LocationId
virtual ~CommandEvent()
destructor
static const std::string TYPE
Definition: Event.h:66
Representation of an LSST Event.
Definition: Event.h:62
Class for storing generic metadata.
Definition: PropertySet.h:82
Represent process that created an event.
Definition: LocationId.h:49
#define CONST_PTR(...)
Definition: base.h:47
static const std::string DEST_HOSTNAME
Definition: CommandEvent.h:70
Interface for PropertySet class.
std::string getHostName() const
Retrieve the host name.
Definition: LocationId.cc:64
static const std::string COMMAND
Definition: EventTypes.h:49
defines the EventSystem class
int getProcessID() const
Retrieve the process id.
Definition: LocationId.cc:68
int getLocalID() const
Retrieve the local id.
Definition: LocationId.cc:72
LocationId::Ptr getDestination() const
retrieve an object containing the OriginatoDesination LocationId