44 #include <sys/socket.h>
49 #include <activemq/core/ActiveMQConnectionFactory.h>
50 #include <activemq/exceptions/ActiveMQException.h>
52 namespace pexExceptions = lsst::pex::exceptions;
54 namespace activemqCore = activemq::core;
61 init(hostName, topicName,
"", hostPort);
65 init(hostName, topicName, selector, hostPort);
70 void EventReceiver::init(
const std::string& hostName,
const std::string& topicName,
const std::string& selector,
int hostPort) {
85 string jmsURL =
"tcp://"+hostName+
":"+ss.str()+
"?wireFormat=openwire";
87 activemqCore::ActiveMQConnectionFactory* connectionFactory =
88 new activemqCore::ActiveMQConnectionFactory( jmsURL );
92 _connection = connectionFactory->createConnection();
94 delete connectionFactory;
96 catch (cms::CMSException& e) {
97 delete connectionFactory;
98 std::string msg(
"Failed to connect to broker: ");
99 msg += e.getMessage();
100 msg +=
" (is broker running?)";
101 throw LSST_EXCEPT(pexExceptions::RuntimeError, msg);
113 }
catch ( cms::CMSException& e ) {
114 throw LSST_EXCEPT(pexExceptions::RuntimeError, std::string(
"Trouble creating EventReceiver: ") + e.getMessage());
125 cms::TextMessage* textMessage;
127 cms::Message* msg =
_consumer->receive(timeout);
128 if (msg == NULL)
return NULL;
129 textMessage =
dynamic_cast<cms::TextMessage*
>(msg);
130 if (textMessage == NULL)
131 throw LSST_EXCEPT(pexExceptions::RuntimeError,
"Unexpected JMS Message type");
132 }
catch (activemq::exceptions::ActiveMQException& e) {
133 throw LSST_EXCEPT(pexExceptions::RuntimeError, e.getMessage());
153 }
catch ( cms::CMSException& e ) {
161 }
catch ( cms::CMSException& e ) {
170 }
catch ( cms::CMSException& e ) {
176 }
catch ( cms::CMSException& e ) {
183 }
catch ( cms::CMSException& e ) {
191 }
catch ( cms::CMSException& e ) {
virtual ~EventReceiver()
destructor
Singleton use to make sure the events library is initialized.
create LSST Events from JMS Messages
Include files required for standard LSST Exception handling.
cms::Connection * _connection
boost::shared_ptr< PropertySet > Ptr
EventReceiver(const std::string &hostName, const std::string &topicName, int hostPort=EventBroker::DEFAULTHOSTPORT)
Receives events from the specified host and topic.
defines the EventFactory class
static Event * createEvent(cms::TextMessage *msg)
cms::Destination * _destination
defines the EventLibrary class
Interface for DateTime class.
defines the EventReceiver class
#define LSST_EXCEPT(type,...)
information about the Event Broker
static const long infiniteTimeout
Representation of an LSST Event.
void init(const std::string &hostName, const std::string &topicName, const std::string &selector, int hostPort)
cms::MessageConsumer * _consumer
static void initializeLibrary()
initialize the ActiveMQ library, but only do it once.
Interface for PropertySet class.
std::string getTopicName()
get topic name
Event * receiveEvent()
Wait until an Event is received.
defines the EventSystem class