LSSTApplications  8.0.0.0+107,8.0.0.1+13,9.1+18,9.2,master-g084aeec0a4,master-g0aced2eed8+6,master-g15627eb03c,master-g28afc54ef9,master-g3391ba5ea0,master-g3d0fb8ae5f,master-g4432ae2e89+36,master-g5c3c32f3ec+17,master-g60f1e072bb+1,master-g6a3ac32d1b,master-g76a88a4307+1,master-g7bce1f4e06+57,master-g8ff4092549+31,master-g98e65bf68e,master-ga6b77976b1+53,master-gae20e2b580+3,master-gb584cd3397+53,master-gc5448b162b+1,master-gc54cf9771d,master-gc69578ece6+1,master-gcbf758c456+22,master-gcec1da163f+63,master-gcf15f11bcc,master-gd167108223,master-gf44c96c709
LSSTDataManagementBasePackage
Public Member Functions | Static Public Member Functions | Protected Attributes | Static Protected Attributes | Private Member Functions | List of all members
lsst.ctrl.events::EventSystem Class Reference

Coordinate publishing and receiving events. More...

#include <EventSystem.h>

Public Member Functions

 EventSystem ()
 EventSystem object. This object allows creation of the system's event transmitters and receivers, which can be specified at the beginning, and later used by specifying the topic to receive from or send on. More...
 
 ~EventSystem ()
 destructor More...
 
void createTransmitter (const pexPolicy::Policy &policy)
 create an EventTransmitter to send messages to the message broker More...
 
void createTransmitter (const std::string &hostName, const std::string &topicName, int hostPort=EventBroker::DEFAULTHOSTPORT)
 create an EventTransmitter to send messages to the message broker More...
 
void createReceiver (const pexPolicy::Policy &policy)
 create an EventReceiver to receive messages from the message broker More...
 
void createReceiver (const std::string &hostName, const std::string &topicName, int hostPort=EventBroker::DEFAULTHOSTPORT)
 create an EventReceiver which will receive message More...
 
void createReceiver (const std::string &hostName, const std::string &topicName, const std::string &selector, int hostPort=EventBroker::DEFAULTHOSTPORT)
 create an EventReceiver which will receive message More...
 
void publishEvent (const std::string &topicName, Event &event)
 send an event on a topic More...
 
EventreceiveEvent (const std::string &topicName)
 blocking receive for events. Waits until an event is received for the topic specified in the constructor More...
 
EventreceiveEvent (const std::string &topicName, const long timeout)
 blocking receive for events, with timeout (in milliseconds). Waits until an event is received for the topic specified in the constructor, or until the timeout expires. More...
 
int64_t createOriginatorId ()
 
int extractIPId (int64_t identificationId)
 extract the 32-bit IPId embedded in this identificationId. This is the integer representation of the IPV4 network address of the host associated with this identificationId More...
 
int extractProcessId (int64_t identificationId)
 extract the 17-bit processId embedded in this identificationId More...
 
short extractLocalId (int64_t identificationId)
 extract the 15-bit localId embedded in this identificationId More...
 
StatusEventcastToStatusEvent (Event *event)
 
CommandEventcastToCommandEvent (Event *event)
 

Static Public Member Functions

static EventSystemgetDefaultEventSystem ()
 return the default EventSystem object, which can access all previously created Transmitters and receivers More...
 

Protected Attributes

list< boost::shared_ptr
< EventTransmitter > > 
_transmitters
 
list< boost::shared_ptr
< EventReceiver > > 
_receivers
 

Static Protected Attributes

static EventSystemdefaultEventSystem = 0
 
static short _localId = 0
 
static int _IPId = 0
 

Private Member Functions

boost::shared_ptr
< EventTransmitter
getTransmitter (const std::string &name)
 
boost::shared_ptr< EventReceivergetReceiver (const std::string &name)
 

Detailed Description

Coordinate publishing and receiving events.

Definition at line 65 of file EventSystem.h.

Constructor & Destructor Documentation

lsst.ctrl.events::EventSystem::EventSystem ( )

EventSystem object. This object allows creation of the system's event transmitters and receivers, which can be specified at the beginning, and later used by specifying the topic to receive from or send on.

Definition at line 67 of file EventSystem.cc.

67  {
68  EventLibrary().initializeLibrary();
69 }
lsst.ctrl.events::EventSystem::~EventSystem ( )

destructor

Definition at line 73 of file EventSystem.cc.

73  {
74 }

Member Function Documentation

CommandEvent * lsst.ctrl.events::EventSystem::castToCommandEvent ( Event event)

Definition at line 283 of file EventSystem.cc.

283  {
284  return (CommandEvent *)event;
285 }
StatusEvent * lsst.ctrl.events::EventSystem::castToStatusEvent ( Event event)

Definition at line 279 of file EventSystem.cc.

279  {
280  return (StatusEvent *)event;
281 }
int64_t lsst.ctrl.events::EventSystem::createOriginatorId ( )

Definition at line 244 of file EventSystem.cc.

244  {
245  int64_t pid = getpid();
246 
247  int64_t originatorId = _IPId & 0x0FFFFFFFF;
248  int64_t locid = _localId & 0x7FFF;
249 
250  originatorId = (locid << 49) | (pid << 32) | originatorId;
251 
252  _localId++;
253  return originatorId;
254 }
void lsst.ctrl.events::EventSystem::createReceiver ( const pexPolicy::Policy policy)

create an EventReceiver to receive messages from the message broker

Parameters
policythe Policy object to use to configure the EventReceiver

Definition at line 143 of file EventSystem.cc.

143  {
144  boost::shared_ptr<EventReceiver> receiver(new EventReceiver(policy));
145  boost::shared_ptr<EventReceiver> receiver2;
146  if ((receiver2 = getReceiver(receiver->getTopicName())) == 0) {
147  _receivers.push_back(receiver);
148  return;
149  }
150  throw LSST_EXCEPT(pexExceptions::RuntimeError, "topic " + receiver->getTopicName() + " is already registered with EventSystem");
151 }
list< boost::shared_ptr< EventReceiver > > _receivers
Definition: EventSystem.h:106
#define LSST_EXCEPT(type,...)
Definition: Exception.h:46
boost::shared_ptr< EventReceiver > getReceiver(const std::string &name)
Definition: EventSystem.cc:235
void lsst.ctrl.events::EventSystem::createReceiver ( const std::string &  hostName,
const std::string &  topicName,
int  hostPort = EventBroker::DEFAULTHOSTPORT 
)

create an EventReceiver which will receive message

Parameters
hostNamethe location of the message broker to use
topicNamethe topic to receive messages from
hostPortthe port where the broker can be reached

Definition at line 158 of file EventSystem.cc.

158  {
159  boost::shared_ptr<EventReceiver> receiver;
160  if ((receiver = getReceiver(topicName)) == 0) {
161  boost::shared_ptr<EventReceiver> receiver(new EventReceiver(hostName, topicName, hostPort));
162  _receivers.push_back(receiver);
163  return;
164  }
165  throw LSST_EXCEPT(pexExceptions::RuntimeError, "topic "+ topicName + " is already registered with EventSystem");
166 }
list< boost::shared_ptr< EventReceiver > > _receivers
Definition: EventSystem.h:106
#define LSST_EXCEPT(type,...)
Definition: Exception.h:46
boost::shared_ptr< EventReceiver > getReceiver(const std::string &name)
Definition: EventSystem.cc:235
void lsst.ctrl.events::EventSystem::createReceiver ( const std::string &  hostName,
const std::string &  topicName,
const std::string &  selector,
int  hostPort = EventBroker::DEFAULTHOSTPORT 
)

create an EventReceiver which will receive message

Parameters
hostNamethe location of the message broker to use
topicNamethe topic to receive messages from
selectorthe message selector to specify which messages to receive
hostPortthe port where the broker can be reached

Definition at line 174 of file EventSystem.cc.

174  {
175  boost::shared_ptr<EventReceiver> receiver(new EventReceiver(hostName, topicName, selector, hostPort));
176  _receivers.push_back(receiver);
177 }
list< boost::shared_ptr< EventReceiver > > _receivers
Definition: EventSystem.h:106
void lsst.ctrl.events::EventSystem::createTransmitter ( const pexPolicy::Policy policy)

create an EventTransmitter to send messages to the message broker

Parameters
policythe Policy object to use to configure the EventTransmitter

Definition at line 115 of file EventSystem.cc.

115  {
116  boost::shared_ptr<EventTransmitter> transmitter(new EventTransmitter(policy));
117  boost::shared_ptr<EventTransmitter> transmitter2;
118  if ((transmitter2 = getTransmitter(transmitter->getTopicName())) == 0) {
119  _transmitters.push_back(transmitter);
120  return;
121  }
122  throw LSST_EXCEPT(pexExceptions::RuntimeError, "topic "+ transmitter->getTopicName() + " is already registered with EventSystem");
123 }
boost::shared_ptr< EventTransmitter > getTransmitter(const std::string &name)
Definition: EventSystem.cc:196
list< boost::shared_ptr< EventTransmitter > > _transmitters
Definition: EventSystem.h:105
#define LSST_EXCEPT(type,...)
Definition: Exception.h:46
void lsst.ctrl.events::EventSystem::createTransmitter ( const std::string &  hostName,
const std::string &  topicName,
int  hostPort = EventBroker::DEFAULTHOSTPORT 
)

create an EventTransmitter to send messages to the message broker

Parameters
hostNamethe location of the message broker to use
topicNamethe topic to transmit events to
hostPortthe port where the broker can be reached

Definition at line 130 of file EventSystem.cc.

130  {
131  boost::shared_ptr<EventTransmitter> transmitter;
132  if ((transmitter = getTransmitter(topicName)) == 0) {
133  boost::shared_ptr<EventTransmitter> transmitter(new EventTransmitter(hostName, topicName, hostPort));
134  _transmitters.push_back(transmitter);
135  return;
136  }
137  throw LSST_EXCEPT(pexExceptions::RuntimeError, "topic "+ topicName + " is already registered with EventSystem");
138 }
boost::shared_ptr< EventTransmitter > getTransmitter(const std::string &name)
Definition: EventSystem.cc:196
list< boost::shared_ptr< EventTransmitter > > _transmitters
Definition: EventSystem.h:105
#define LSST_EXCEPT(type,...)
Definition: Exception.h:46
int lsst.ctrl.events::EventSystem::extractIPId ( int64_t  identificationId)

extract the 32-bit IPId embedded in this identificationId. This is the integer representation of the IPV4 network address of the host associated with this identificationId

Returns
the 32-bit IPId

Definition at line 261 of file EventSystem.cc.

261  {
262  return identificationId & 0xFFFFFFFF;
263 }
short lsst.ctrl.events::EventSystem::extractLocalId ( int64_t  identificationId)

extract the 15-bit localId embedded in this identificationId

Returns
the 15-bit localId

Definition at line 275 of file EventSystem.cc.

275  {
276  return (identificationId & 0xFFFE000000000000LL) >> 49;
277 }
int lsst.ctrl.events::EventSystem::extractProcessId ( int64_t  identificationId)

extract the 17-bit processId embedded in this identificationId

Returns
the 17-bit processId

Definition at line 268 of file EventSystem.cc.

268  {
269  return (identificationId & 0x1FFFF00000000LL) >> 32;
270 }
EventSystem & lsst.ctrl.events::EventSystem::getDefaultEventSystem ( )
static

return the default EventSystem object, which can access all previously created Transmitters and receivers

Returns
The EventSystem object

Definition at line 80 of file EventSystem.cc.

80  {
81  if (defaultEventSystem == 0) {
82 
83  // create the _IPId here, rather than
84  // reconstructing it every time we create an
85  // identificationId
86 
87  char buf [255];
88  struct hostent *ent;
89  unsigned char a,b,c,d;
90 
91  gethostname(buf, 255) ;
92  ent = (struct hostent *)gethostbyname(buf) ;
93 
94  a = ent->h_addr_list[0][0] & 0xFF;
95  b = ent->h_addr_list[0][1] & 0xFF;
96  c = ent->h_addr_list[0][2] & 0xFF;
97  d = ent->h_addr_list[0][3] & 0xFF;
98 
99  _IPId = (a << 24) | (b << 16) | (c << 8) | d;
100 
101  // create the default EventSystem object
103  }
104  return *defaultEventSystem;
105 
106 }
int d
Definition: KDTree.cc:89
afw::table::Key< double > b
static EventSystem * defaultEventSystem
Definition: EventSystem.h:100
EventSystem()
EventSystem object. This object allows creation of the system&#39;s event transmitters and receivers...
Definition: EventSystem.cc:67
boost::shared_ptr< EventReceiver > lsst.ctrl.events::EventSystem::getReceiver ( const std::string &  name)
private

private method used to retrieve the named EventReceiver object

Definition at line 235 of file EventSystem.cc.

235  {
236  list<boost::shared_ptr<EventReceiver> >::iterator i;
237  for (i = _receivers.begin(); i != _receivers.end(); i++) {
238  if ((*i)->getTopicName() == name)
239  return *i;
240  }
241  return boost::shared_ptr<EventReceiver>();
242 }
list< boost::shared_ptr< EventReceiver > > _receivers
Definition: EventSystem.h:106
boost::shared_ptr< EventTransmitter > lsst.ctrl.events::EventSystem::getTransmitter ( const std::string &  name)
private

private method to retrieve a transmitter from the internal list

Definition at line 196 of file EventSystem.cc.

196  {
197  list<boost::shared_ptr<EventTransmitter> >::iterator i;
198  for (i = _transmitters.begin(); i != _transmitters.end(); i++) {
199  if ((*i)->getTopicName() == name)
200  return *i;
201  }
202  return boost::shared_ptr<EventTransmitter>();
203 }
list< boost::shared_ptr< EventTransmitter > > _transmitters
Definition: EventSystem.h:105
void lsst.ctrl.events::EventSystem::publishEvent ( const std::string &  topicName,
Event event 
)

send an event on a topic

Parameters
topicNamethe topic to send messages to
eventthe Event to send
Exceptions
Runtimeexception if the topic wasn't already registered using the createTransmitter method

Definition at line 186 of file EventSystem.cc.

186  {
187  boost::shared_ptr<EventTransmitter> transmitter;
188  if ((transmitter = getTransmitter(topicName)) == 0) {
189  throw LSST_EXCEPT(pexExceptions::RuntimeError, "topic "+ topicName + " is not registered with EventSystem");
190  }
191  transmitter->publishEvent(event);
192 }
boost::shared_ptr< EventTransmitter > getTransmitter(const std::string &name)
Definition: EventSystem.cc:196
#define LSST_EXCEPT(type,...)
Definition: Exception.h:46
Event * lsst.ctrl.events::EventSystem::receiveEvent ( const std::string &  topicName)

blocking receive for events. Waits until an event is received for the topic specified in the constructor

Parameters
topicNamethe topic to listen on
Returns
a PropertySet::Ptr object

Definition at line 211 of file EventSystem.cc.

211  {
212  return receiveEvent(topicName, EventReceiver::infiniteTimeout);
213 }
Event * receiveEvent(const std::string &topicName)
blocking receive for events. Waits until an event is received for the topic specified in the construc...
Definition: EventSystem.cc:211
static const long infiniteTimeout
Definition: EventReceiver.h:79
Event * lsst.ctrl.events::EventSystem::receiveEvent ( const std::string &  topicName,
const long  timeout 
)

blocking receive for events, with timeout (in milliseconds). Waits until an event is received for the topic specified in the constructor, or until the timeout expires.

Parameters
topicNamethe topic to listen on
timeoutthe time in milliseconds to wait before returning
Returns
a Property::Ptr object on success, 0 on failure see note in receive()

Definition at line 223 of file EventSystem.cc.

223  {
224  boost::shared_ptr<EventReceiver> receiver;
225  if ((receiver = getReceiver(topicName)) == 0) {
226  throw LSST_EXCEPT(pexExceptions::RuntimeError, "Topic "+ topicName +" is not registered with EventSystem");
227  }
228 
229  return receiver->receiveEvent(timeout);
230 }
#define LSST_EXCEPT(type,...)
Definition: Exception.h:46
boost::shared_ptr< EventReceiver > getReceiver(const std::string &name)
Definition: EventSystem.cc:235

Member Data Documentation

int lsst.ctrl.events::EventSystem::_IPId = 0
staticprotected

Definition at line 103 of file EventSystem.h.

short lsst.ctrl.events::EventSystem::_localId = 0
staticprotected

Definition at line 102 of file EventSystem.h.

list<boost::shared_ptr<EventReceiver> > lsst.ctrl.events::EventSystem::_receivers
protected

Definition at line 106 of file EventSystem.h.

list<boost::shared_ptr<EventTransmitter> > lsst.ctrl.events::EventSystem::_transmitters
protected

Definition at line 105 of file EventSystem.h.

EventSystem * lsst.ctrl.events::EventSystem::defaultEventSystem = 0
staticprotected

Definition at line 100 of file EventSystem.h.


The documentation for this class was generated from the following files: