You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by nm...@apache.org on 2008/02/10 00:16:16 UTC
svn commit: r620215 - in
/activemq/activemq-cpp/trunk/src/main/activemq/cmsutil: CmsTemplate.cpp
CmsTemplate.h
Author: nmittler
Date: Sat Feb 9 15:16:14 2008
New Revision: 620215
URL: http://svn.apache.org/viewvc?rev=620215&view=rev
Log:
AMQCPP-152 - Adding synchronous receive to CmsTemplate
Modified:
activemq/activemq-cpp/trunk/src/main/activemq/cmsutil/CmsTemplate.cpp
activemq/activemq-cpp/trunk/src/main/activemq/cmsutil/CmsTemplate.h
Modified: activemq/activemq-cpp/trunk/src/main/activemq/cmsutil/CmsTemplate.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/activemq/cmsutil/CmsTemplate.cpp?rev=620215&r1=620214&r2=620215&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/activemq/cmsutil/CmsTemplate.cpp (original)
+++ activemq/activemq-cpp/trunk/src/main/activemq/cmsutil/CmsTemplate.cpp Sat Feb 9 15:16:14 2008
@@ -529,11 +529,8 @@
}
////////////////////////////////////////////////////////////////////////////////
-cms::Message* CmsTemplate::doReceive(cms::MessageConsumer* consumer,
- long long receiveTime )
-throw (cms::CMSException) {
-
- cms::Message* message = NULL;
+cms::Message* CmsTemplate::doReceive(cms::MessageConsumer* consumer )
+throw (cms::CMSException) {
try {
@@ -541,18 +538,17 @@
throw new ActiveMQException(__FILE__, __LINE__, "consumer is NULL");
}
+ long long receiveTime = getReceiveTimeout();
+
switch( receiveTime ) {
case RECEIVE_TIMEOUT_NO_WAIT: {
- message = consumer->receiveNoWait();
- break;
+ return consumer->receiveNoWait();
}
case RECEIVE_TIMEOUT_INDEFINITE_WAIT: {
- message = consumer->receive();
- break;
+ return consumer->receive();
}
default: {
- message = consumer->receive(receiveTime);
- break;
+ return consumer->receive(receiveTime);
}
}
@@ -560,9 +556,6 @@
e.setMark(__FILE__, __LINE__ );
- // Destroy the message resource.
- destroyMessage(message);
-
throw e;
}
}
@@ -579,7 +572,7 @@
consumer = parent->createConsumer(session, getDestination(session), selector, noLocal);
// Receive the message.
- message = parent->doReceive(consumer, receiveTime);
+ message = parent->doReceive(consumer);
// Destroy the consumer resource.
parent->destroyConsumer(consumer);
@@ -609,3 +602,99 @@
AMQ_CATCH_RETHROW( ActiveMQException )
AMQ_CATCHALL_THROW( ActiveMQException )
}
+
+////////////////////////////////////////////////////////////////////////////////
+cms::Message* CmsTemplate::receive()
+throw (cms::CMSException, IllegalStateException) {
+
+ try {
+ ReceiveExecutor receiveExecutor(this, NULL,
+ "", isNoLocal());
+ execute(&receiveExecutor);
+
+ return receiveExecutor.getMessage();
+ }
+ AMQ_CATCH_RETHROW( ActiveMQException )
+ AMQ_CATCHALL_THROW( ActiveMQException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+cms::Message* CmsTemplate::receive(cms::Destination* destination )
+throw (cms::CMSException, IllegalStateException) {
+
+ try {
+ ReceiveExecutor receiveExecutor(this, destination,
+ "", isNoLocal());
+ execute(&receiveExecutor);
+
+ return receiveExecutor.getMessage();
+ }
+ AMQ_CATCH_RETHROW( ActiveMQException )
+ AMQ_CATCHALL_THROW( ActiveMQException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+cms::Message* CmsTemplate::receive(const std::string& destinationName)
+throw (cms::CMSException, IllegalStateException) {
+
+ try {
+ ResolveReceiveExecutor receiveExecutor(this,
+ "", isNoLocal(),
+ destinationName);
+ execute(&receiveExecutor);
+
+ return receiveExecutor.getMessage();
+ }
+ AMQ_CATCH_RETHROW( ActiveMQException )
+ AMQ_CATCHALL_THROW( ActiveMQException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+cms::Message* CmsTemplate::receiveSelected(const std::string& selector)
+throw (cms::CMSException, IllegalStateException) {
+
+ try {
+ ReceiveExecutor receiveExecutor(this, NULL,
+ selector, isNoLocal());
+ execute(&receiveExecutor);
+
+ return receiveExecutor.getMessage();
+ }
+ AMQ_CATCH_RETHROW( ActiveMQException )
+ AMQ_CATCHALL_THROW( ActiveMQException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+cms::Message* CmsTemplate::receiveSelected(cms::Destination* destination,
+ const std::string& selector)
+throw (cms::CMSException, IllegalStateException) {
+
+ try {
+ ReceiveExecutor receiveExecutor(this, destination,
+ selector, isNoLocal());
+ execute(&receiveExecutor);
+
+ return receiveExecutor.getMessage();
+ }
+ AMQ_CATCH_RETHROW( ActiveMQException )
+ AMQ_CATCHALL_THROW( ActiveMQException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+cms::Message* CmsTemplate::receiveSelected(const std::string& destinationName,
+ const std::string& selector)
+throw (cms::CMSException, IllegalStateException) {
+
+ try {
+ ResolveReceiveExecutor receiveExecutor(this,
+ selector, isNoLocal(),
+ destinationName);
+ execute(&receiveExecutor);
+
+ return receiveExecutor.getMessage();
+ }
+ AMQ_CATCH_RETHROW( ActiveMQException )
+ AMQ_CATCHALL_THROW( ActiveMQException )
+}
+
+
Modified: activemq/activemq-cpp/trunk/src/main/activemq/cmsutil/CmsTemplate.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/activemq/cmsutil/CmsTemplate.h?rev=620215&r1=620214&r2=620215&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/activemq/cmsutil/CmsTemplate.h (original)
+++ activemq/activemq-cpp/trunk/src/main/activemq/cmsutil/CmsTemplate.h Sat Feb 9 15:16:14 2008
@@ -182,19 +182,16 @@
bool noLocal;
cms::Message* message;
CmsTemplate* parent;
- long long receiveTime;
public:
ReceiveExecutor( CmsTemplate* parent,
cms::Destination* destination,
const std::string& selector,
- bool noLocal,
- long long receiveTime) {
+ bool noLocal) {
this->parent = parent;
this->destination = destination;
this->selector = selector;
- this->noLocal = noLocal;
- this->receiveTime = receiveTime;
+ this->noLocal = noLocal;
this->message = NULL;
}
@@ -207,6 +204,10 @@
throw (cms::CMSException) {
return destination;
}
+
+ cms::Message* getMessage() {
+ return message;
+ }
};
/**
@@ -223,11 +224,10 @@
ResolveReceiveExecutor(CmsTemplate* parent,
const std::string& selector,
- bool noLocal,
- long long receiveTime,
+ bool noLocal,
const std::string& destinationName)
:
- ReceiveExecutor( parent, NULL, selector, noLocal, receiveTime) {
+ ReceiveExecutor( parent, NULL, selector, noLocal) {
this->destinationName = destinationName;
}
@@ -565,6 +565,90 @@
MessageCreator* messageCreator)
throw (cms::CMSException, decaf::lang::exceptions::IllegalStateException);
+ /**
+ * Performs a synchronous read from the default destination.
+ * @return the message
+ * @throws cms::CMSException thrown if an error occurs
+ * @throws decaf::lang::exceptions::IllegalStateException thrown if the
+ * default destination has not been specified.
+ */
+ virtual cms::Message* receive()
+ throw (cms::CMSException, decaf::lang::exceptions::IllegalStateException);
+
+ /**
+ * Performs a synchronous read from the specified destination.
+ * @param destination
+ * the destination to receive on
+ * @return the message
+ * @throws cms::CMSException thrown if an error occurs
+ * @throws decaf::lang::exceptions::IllegalStateException thrown if the
+ * default destination has not been specified.
+ */
+ virtual cms::Message* receive(cms::Destination* destination )
+ throw (cms::CMSException, decaf::lang::exceptions::IllegalStateException);
+
+ /**
+ * Performs a synchronous read from the specified destination.
+ * @param destinationName
+ * the name of the destination to receive on
+ * (will be resolved to destination internally).
+ * @return the message
+ * @throws cms::CMSException thrown if an error occurs
+ * @throws decaf::lang::exceptions::IllegalStateException thrown if the
+ * default destination has not been specified.
+ */
+ virtual cms::Message* receive(const std::string& destinationName )
+ throw (cms::CMSException, decaf::lang::exceptions::IllegalStateException);
+
+ /**
+ * Performs a synchronous read consuming only messages identified by the
+ * given selector.
+ *
+ * @param selector
+ * the selector expression.
+ * @return the message
+ * @throws cms::CMSException thrown if an error occurs
+ * @throws decaf::lang::exceptions::IllegalStateException thrown if the
+ * default destination has not been specified.
+ */
+ virtual cms::Message* receiveSelected(const std::string& selector )
+ throw (cms::CMSException, decaf::lang::exceptions::IllegalStateException);
+
+ /**
+ * Performs a synchronous read from the specified destination, consuming
+ * only messages identified by the given selector.
+ *
+ * @param destination
+ * the destination to receive on.
+ * @param selector
+ * the selector expression.
+ * @return the message
+ * @throws cms::CMSException thrown if an error occurs
+ * @throws decaf::lang::exceptions::IllegalStateException thrown if the
+ * default destination has not been specified.
+ */
+ virtual cms::Message* receiveSelected( cms::Destination* destination,
+ const std::string& selector )
+ throw (cms::CMSException, decaf::lang::exceptions::IllegalStateException);
+
+ /**
+ * Performs a synchronous read from the specified destination, consuming
+ * only messages identified by the given selector.
+ *
+ * @param destinationName
+ * the name of the destination to receive on
+ * (will be resolved to destination internally).
+ * @param selector
+ * the selector expression.
+ * @return the message
+ * @throws cms::CMSException thrown if an error occurs
+ * @throws decaf::lang::exceptions::IllegalStateException thrown if the
+ * default destination has not been specified.
+ */
+ virtual cms::Message* receiveSelected( const std::string& destinationName,
+ const std::string& selector )
+ throw (cms::CMSException, decaf::lang::exceptions::IllegalStateException);
+
private:
/**
@@ -685,13 +769,11 @@
* Receives a message from a destination.
* @param consumer
* the consumer to receive from
- * @param receiveTime
- * the time to wait for the receive.
* @return the message that was read
* @throws cms::CMSException thrown if the CMS API throws.
*/
- cms::Message* doReceive(cms::MessageConsumer* consumer,
- long long receiveTime ) throw (cms::CMSException);
+ cms::Message* doReceive(cms::MessageConsumer* consumer )
+ throw (cms::CMSException);
/**
* Resolves the default destination and returns it.