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
Public Member Functions | Static Public Member Functions | Protected Member Functions | Static Protected Attributes | Private Member Functions | Static Private Attributes | List of all members
lsst::ctrl::events::EventSystem Class Reference

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...

#include <EventSystem.h>

Public Member Functions

 ~EventSystem ()
 destructor More...
 
void createTransmitter (std::string const &hostName, std::string const &topicName, int hostPort=EventBroker::DEFAULTHOSTPORT)
 create an EventTransmitter to send messages to the message broker More...
 
void createReceiver (std::string const &hostName, std::string const &topicName, int hostPort=EventBroker::DEFAULTHOSTPORT)
 create an EventReceiver which will receive message More...
 
void createReceiver (std::string const &hostName, std::string const &topicName, std::string const &selector, int hostPort=EventBroker::DEFAULTHOSTPORT)
 create an EventReceiver which will receive message More...
 
void publishEvent (std::string const &topicName, Event &event)
 send an event on a topic More...
 
EventreceiveEvent (std::string const &topicName)
 blocking receive for events. Waits until an event is received for the topic specified in the constructor More...
 
EventreceiveEvent (std::string const &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...
 
LocationId::Ptr createOriginatorId () const
 create an LocationId More...
 
StatusEventcastToStatusEvent (Event *event)
 cast an Event to StatusEvent More...
 
CommandEventcastToCommandEvent (Event *event)
 cast an Event to CommandEvent More...
 

Static Public Member Functions

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

Protected Member Functions

 EventSystem ()
 

Static Protected Attributes

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

Private Member Functions

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

Static Private Attributes

static EventSystemdefaultEventSystem = 0
 

Detailed Description

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 65 of file EventSystem.h.

Constructor & Destructor Documentation

lsst::ctrl::events::EventSystem::~EventSystem ( )

destructor

Definition at line 66 of file EventSystem.cc.

66  {
67 }
lsst::ctrl::events::EventSystem::EventSystem ( )
protected

Definition at line 62 of file EventSystem.cc.

62  {
63  EventLibrary().initializeLibrary();
64 }

Member Function Documentation

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

cast an Event to CommandEvent

Parameters
eventan Event
Returns
a CommandEvent

Definition at line 159 of file EventSystem.cc.

159  {
160  return (CommandEvent *)event;
161 }
StatusEvent * lsst::ctrl::events::EventSystem::castToStatusEvent ( Event event)

cast an Event to StatusEvent

Parameters
eventan Event
Returns
a StatusEvent

Definition at line 155 of file EventSystem.cc.

155  {
156  return (StatusEvent *)event;
157 }
LocationId::Ptr lsst::ctrl::events::EventSystem::createOriginatorId ( ) const

create an LocationId

Returns
LocationId::Ptr

Definition at line 139 of file EventSystem.cc.

139  {
140  return LocationId::Ptr(new LocationId());
141 }
boost::shared_ptr< LocationId > Ptr
Definition: LocationId.h:52
void lsst::ctrl::events::EventSystem::createReceiver ( std::string const &  hostName,
std::string const &  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
Exceptions
lsst::pex::exceptions::RuntimeErrorif topic is already registered

Definition at line 89 of file EventSystem.cc.

89  {
90  boost::shared_ptr<EventReceiver> receiver;
91  if ((receiver = getReceiver(topicName)) == 0) {
92  boost::shared_ptr<EventReceiver> receiver(new EventReceiver(hostName, topicName, hostPort));
93  _receivers.push_back(receiver);
94  return;
95  }
96  throw LSST_EXCEPT(pexExceptions::RuntimeError, "topic "+ topicName + " is already registered with EventSystem");
97 }
static list< boost::shared_ptr< EventReceiver > > _receivers
Definition: EventSystem.h:165
boost::shared_ptr< EventReceiver > getReceiver(std::string const &name)
Definition: EventSystem.cc:145
#define LSST_EXCEPT(type,...)
Definition: Exception.h:46
void lsst::ctrl::events::EventSystem::createReceiver ( std::string const &  hostName,
std::string const &  topicName,
std::string const &  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 99 of file EventSystem.cc.

99  {
100  boost::shared_ptr<EventReceiver> receiver(new EventReceiver(hostName, topicName, selector, hostPort));
101  _receivers.push_back(receiver);
102 }
static list< boost::shared_ptr< EventReceiver > > _receivers
Definition: EventSystem.h:165
void lsst::ctrl::events::EventSystem::createTransmitter ( std::string const &  hostName,
std::string const &  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
Exceptions
lsst::pex::exceptions::RuntimeErrorif topic is already registered

Definition at line 79 of file EventSystem.cc.

79  {
80  boost::shared_ptr<EventTransmitter> transmitter;
81  if ((transmitter = getTransmitter(topicName)) == 0) {
82  boost::shared_ptr<EventTransmitter> transmitter(new EventTransmitter(hostName, topicName, hostPort));
83  _transmitters.push_back(transmitter);
84  return;
85  }
86  throw LSST_EXCEPT(pexExceptions::RuntimeError, "topic "+ topicName + " is already registered with EventSystem");
87 }
boost::shared_ptr< EventTransmitter > getTransmitter(std::string const &name)
Definition: EventSystem.cc:115
static list< boost::shared_ptr< EventTransmitter > > _transmitters
Definition: EventSystem.h:164
#define LSST_EXCEPT(type,...)
Definition: Exception.h:46
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 69 of file EventSystem.cc.

69  {
70  static EventSystem eventSystem;
71  return eventSystem;
72 
73 }
boost::shared_ptr< EventReceiver > lsst::ctrl::events::EventSystem::getReceiver ( std::string const &  name)
private

private method used to retrieve the named EventReceiver object

Definition at line 145 of file EventSystem.cc.

145  {
146  list<boost::shared_ptr<EventReceiver> >::iterator i;
147  for (i = _receivers.begin(); i != _receivers.end(); i++) {
148  if ((*i)->getTopicName() == name)
149  return *i;
150  }
151  return boost::shared_ptr<EventReceiver>();
152 }
table::Key< std::string > name
Definition: ApCorrMap.cc:71
static list< boost::shared_ptr< EventReceiver > > _receivers
Definition: EventSystem.h:165
boost::shared_ptr< EventTransmitter > lsst::ctrl::events::EventSystem::getTransmitter ( std::string const &  name)
private

private method to retrieve a transmitter from the internal list

Definition at line 115 of file EventSystem.cc.

115  {
116  list<boost::shared_ptr<EventTransmitter> >::iterator i;
117  for (i = _transmitters.begin(); i != _transmitters.end(); i++) {
118  if ((*i)->getTopicName() == name) {
119  return *i;
120  }
121  }
122  return boost::shared_ptr<EventTransmitter>();
123 }
table::Key< std::string > name
Definition: ApCorrMap.cc:71
static list< boost::shared_ptr< EventTransmitter > > _transmitters
Definition: EventSystem.h:164
void lsst::ctrl::events::EventSystem::publishEvent ( std::string const &  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 105 of file EventSystem.cc.

105  {
106  boost::shared_ptr<EventTransmitter> transmitter;
107  if ((transmitter = getTransmitter(topicName)) == 0) {
108  throw LSST_EXCEPT(pexExceptions::RuntimeError, "topic "+ topicName + " is not registered with EventSystem");
109  }
110  transmitter->publishEvent(event);
111 }
boost::shared_ptr< EventTransmitter > getTransmitter(std::string const &name)
Definition: EventSystem.cc:115
#define LSST_EXCEPT(type,...)
Definition: Exception.h:46
Event * lsst::ctrl::events::EventSystem::receiveEvent ( std::string const &  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 126 of file EventSystem.cc.

126  {
127  return receiveEvent(topicName, EventReceiver::infiniteTimeout);
128 }
Event * receiveEvent(std::string const &topicName)
blocking receive for events. Waits until an event is received for the topic specified in the construc...
Definition: EventSystem.cc:126
Event * lsst::ctrl::events::EventSystem::receiveEvent ( std::string const &  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

Definition at line 130 of file EventSystem.cc.

130  {
131  boost::shared_ptr<EventReceiver> receiver;
132  if ((receiver = getReceiver(topicName)) == 0) {
133  throw LSST_EXCEPT(pexExceptions::RuntimeError, "Topic "+ topicName +" is not registered with EventSystem");
134  }
135 
136  return receiver->receiveEvent(timeout);
137 }
boost::shared_ptr< EventReceiver > getReceiver(std::string const &name)
Definition: EventSystem.cc:145
#define LSST_EXCEPT(type,...)
Definition: Exception.h:46

Member Data Documentation

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

Definition at line 165 of file EventSystem.h.

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

Definition at line 164 of file EventSystem.h.

EventSystem * lsst::ctrl::events::EventSystem::defaultEventSystem = 0
staticprivate

Definition at line 155 of file EventSystem.h.


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