activemq-cpp-3.4.0

activemq::cmsutil::CmsTemplate Class Reference

CmsTemplate simplifies performing synchronous CMS operations. More...

#include <src/main/activemq/cmsutil/CmsTemplate.h>

Inheritance diagram for activemq::cmsutil::CmsTemplate:

Data Structures

class  ProducerExecutor
class  ReceiveExecutor
class  ResolveProducerExecutor
class  ResolveReceiveExecutor
class  SendExecutor

Public Member Functions

 CmsTemplate ()
 CmsTemplate (cms::ConnectionFactory *connectionFactory)
virtual ~CmsTemplate () throw ()
virtual void setDefaultDestination (cms::Destination *defaultDestination)
 Sets the destination object to be used by default for send/receive operations.
virtual const cms::DestinationgetDefaultDestination () const
 Retrieves the default destination to be used for send/receive operations.
virtual cms::DestinationgetDefaultDestination ()
 Retrieves the default destination to be used for send/receive operations.
virtual void setDefaultDestinationName (const std::string &defaultDestinationName)
 Sets the name of the default destination to be used from send/receive operations.
virtual const std::string getDefaultDestinationName () const
 Gets the name of the default destination to be used for send/receive operations.
virtual void setPubSubDomain (bool pubSubDomain)
 Indicates whether the default destination is a topic (true) or a queue (false).
virtual void setMessageIdEnabled (bool messageIdEnabled)
virtual bool isMessageIdEnabled () const
virtual void setMessageTimestampEnabled (bool messageTimestampEnabled)
virtual bool isMessageTimestampEnabled () const
virtual void setNoLocal (bool noLocal)
virtual bool isNoLocal () const
virtual void setReceiveTimeout (long long receiveTimeout)
virtual long long getReceiveTimeout () const
virtual void setExplicitQosEnabled (bool explicitQosEnabled)
 Set if the QOS values (deliveryMode, priority, timeToLive) should be used for sending a message.
virtual bool isExplicitQosEnabled () const
 If "true", then the values of deliveryMode, priority, and timeToLive will be used when sending a message.
virtual void setDeliveryPersistent (bool deliveryPersistent)
 Set whether message delivery should be persistent or non-persistent, specified as boolean value ("true" or "false").
virtual void setDeliveryMode (int deliveryMode)
 Set the delivery mode to use when sending a message.
virtual int getDeliveryMode () const
 Return the delivery mode to use when sending a message.
virtual void setPriority (int priority)
 Set the priority of a message when sending.
virtual int getPriority () const
 Return the priority of a message when sending.
virtual void setTimeToLive (long long timeToLive)
 Set the time-to-live of the message when sending.
virtual long long getTimeToLive () const
 Return the time-to-live of the message when sending.
virtual void execute (SessionCallback *action)
 Executes the given action within a CMS Session.
virtual void execute (ProducerCallback *action)
 Executes the given action and provides it with a CMS Session and producer.
virtual void execute (cms::Destination *dest, ProducerCallback *action)
 Executes the given action and provides it with a CMS Session and producer.
virtual void execute (const std::string &destinationName, ProducerCallback *action)
 Executes the given action and provides it with a CMS Session and producer.
virtual void send (MessageCreator *messageCreator)
 Convenience method for sending a message to the default destination.
virtual void send (cms::Destination *dest, MessageCreator *messageCreator)
 Convenience method for sending a message to the specified destination.
virtual void send (const std::string &destinationName, MessageCreator *messageCreator)
 Convenience method for sending a message to the specified destination.
virtual cms::Messagereceive ()
 Performs a synchronous read from the default destination.
virtual cms::Messagereceive (cms::Destination *destination)
 Performs a synchronous read from the specified destination.
virtual cms::Messagereceive (const std::string &destinationName)
 Performs a synchronous read from the specified destination.
virtual cms::MessagereceiveSelected (const std::string &selector)
 Performs a synchronous read consuming only messages identified by the given selector.
virtual cms::MessagereceiveSelected (cms::Destination *destination, const std::string &selector)
 Performs a synchronous read from the specified destination, consuming only messages identified by the given selector.
virtual cms::MessagereceiveSelected (const std::string &destinationName, const std::string &selector)
 Performs a synchronous read from the specified destination, consuming only messages identified by the given selector.

Static Public Attributes

static const long long RECEIVE_TIMEOUT_NO_WAIT
 Timeout value indicating that a receive operation should check if a message is immediately available without blocking.
static const long long RECEIVE_TIMEOUT_INDEFINITE_WAIT
 Timeout value indicating a blocking receive without timeout.
static const int DEFAULT_PRIORITY
 Default message priority.
static const long long DEFAULT_TIME_TO_LIVE
 My default, messages should live forever.

Protected Member Functions

void init ()
 Initializes this object and prepares it for use.
void destroy ()
 Shuts down this object and destroys any allocated resources.

Friends

class ProducerExecutor
class ResolveProducerExecutor
class SendExecutor
class ReceiveExecutor
class ResolveReceiveExecutor

Detailed Description

CmsTemplate simplifies performing synchronous CMS operations.

This class is intended to be for CMS what Spring's JmsTemplate is for JMS. Provided with a CMS ConnectionFactory, creates and manages all other CMS resources internally.

Before using CmsTemplate the user must first set the destination (either by name or by setting the destination object directly) and then call init to initialize the object for use.

CmsTemplate allows the user to get access to a CMS Session through a user-defined SessionCallback. Similarly, if the user wants direct access to a CMS MessageProducer, it can provide a ProducerCallback. As a convenience, the user can bypass having to provide callbacks altogether for sending messages, by calling one of the send methods.

See also:
SessionCallback
ProducerCallback
MessageCreator

Constructor & Destructor Documentation

activemq::cmsutil::CmsTemplate::CmsTemplate ( )
activemq::cmsutil::CmsTemplate::CmsTemplate ( cms::ConnectionFactory connectionFactory)
virtual activemq::cmsutil::CmsTemplate::~CmsTemplate ( ) throw () [virtual]

Member Function Documentation

void activemq::cmsutil::CmsTemplate::destroy ( ) [protected, virtual]

Shuts down this object and destroys any allocated resources.

Exceptions:
CMSExceptionif an error occurs during destruction.
IllegalStateExceptionif this object has already been destroyed.

Reimplemented from activemq::cmsutil::CmsDestinationAccessor.

virtual void activemq::cmsutil::CmsTemplate::execute ( SessionCallback action) [virtual]

Executes the given action within a CMS Session.

Parameters:
actionthe action to perform within a CMS Session
Exceptions:
cms::CMSExceptionthrown if an error occurs.
virtual void activemq::cmsutil::CmsTemplate::execute ( ProducerCallback action) [virtual]

Executes the given action and provides it with a CMS Session and producer.

Parameters:
actionthe action to perform
Exceptions:
cms::CMSExceptionthrown if an error occurs.
virtual void activemq::cmsutil::CmsTemplate::execute ( cms::Destination dest,
ProducerCallback action 
) [virtual]

Executes the given action and provides it with a CMS Session and producer.

Parameters:
destthe destination to send messages to
actionthe action to perform
Exceptions:
cms::CMSExceptionthrown if an error occurs.
virtual void activemq::cmsutil::CmsTemplate::execute ( const std::string &  destinationName,
ProducerCallback action 
) [virtual]

Executes the given action and provides it with a CMS Session and producer.

Parameters:
destinationNamethe name of the destination to send messages to (to internally be resolved to an actual destination)
actionthe action to perform
Exceptions:
cms::CMSExceptionthrown if an error occurs.
virtual cms::Destination* activemq::cmsutil::CmsTemplate::getDefaultDestination ( ) [inline, virtual]

Retrieves the default destination to be used for send/receive operations.

Returns:
the default destination. Non-const version of this method.
virtual const cms::Destination* activemq::cmsutil::CmsTemplate::getDefaultDestination ( ) const [inline, virtual]

Retrieves the default destination to be used for send/receive operations.

Returns:
the default destination. Const version of this method.
virtual const std::string activemq::cmsutil::CmsTemplate::getDefaultDestinationName ( ) const [inline, virtual]

Gets the name of the default destination to be used for send/receive operations.

The destination type (topic/queue) is determined by the pubSubDomain property.

Returns:
the default name of the destination for send/receive operations.
virtual int activemq::cmsutil::CmsTemplate::getDeliveryMode ( ) const [inline, virtual]

Return the delivery mode to use when sending a message.

virtual int activemq::cmsutil::CmsTemplate::getPriority ( ) const [inline, virtual]

Return the priority of a message when sending.

virtual long long activemq::cmsutil::CmsTemplate::getReceiveTimeout ( ) const [inline, virtual]
virtual long long activemq::cmsutil::CmsTemplate::getTimeToLive ( ) const [inline, virtual]

Return the time-to-live of the message when sending.

void activemq::cmsutil::CmsTemplate::init ( ) [protected, virtual]

Initializes this object and prepares it for use.

This should be called before any other methods are called. This version does nothing.

Exceptions:
CMSExceptionif an error occurs during initialization.
IllegalStateExceptionif this object has already been initialized.

Reimplemented from activemq::cmsutil::CmsDestinationAccessor.

virtual bool activemq::cmsutil::CmsTemplate::isExplicitQosEnabled ( ) const [inline, virtual]

If "true", then the values of deliveryMode, priority, and timeToLive will be used when sending a message.

Otherwise, the default values, that may be set administratively, will be used.

Returns:
true if overriding default values of QOS parameters (deliveryMode, priority, and timeToLive)
See also:
setDeliveryMode
setPriority
setTimeToLive
virtual bool activemq::cmsutil::CmsTemplate::isMessageIdEnabled ( ) const [inline, virtual]
virtual bool activemq::cmsutil::CmsTemplate::isMessageTimestampEnabled ( ) const [inline, virtual]
virtual bool activemq::cmsutil::CmsTemplate::isNoLocal ( ) const [inline, virtual]
virtual cms::Message* activemq::cmsutil::CmsTemplate::receive ( cms::Destination destination) [virtual]

Performs a synchronous read from the specified destination.

Parameters:
destinationthe destination to receive on
Returns:
the message
Exceptions:
cms::CMSExceptionthrown if an error occurs
virtual cms::Message* activemq::cmsutil::CmsTemplate::receive ( const std::string &  destinationName) [virtual]

Performs a synchronous read from the specified destination.

Parameters:
destinationNamethe name of the destination to receive on (will be resolved to destination internally).
Returns:
the message
Exceptions:
cms::CMSExceptionthrown if an error occurs
virtual cms::Message* activemq::cmsutil::CmsTemplate::receive ( ) [virtual]

Performs a synchronous read from the default destination.

Returns:
the message
Exceptions:
cms::CMSExceptionthrown if an error occurs
virtual cms::Message* activemq::cmsutil::CmsTemplate::receiveSelected ( const std::string &  selector) [virtual]

Performs a synchronous read consuming only messages identified by the given selector.

Parameters:
selectorthe selector expression.
Returns:
the message
Exceptions:
cms::CMSExceptionthrown if an error occurs
virtual cms::Message* activemq::cmsutil::CmsTemplate::receiveSelected ( cms::Destination destination,
const std::string &  selector 
) [virtual]

Performs a synchronous read from the specified destination, consuming only messages identified by the given selector.

Parameters:
destinationthe destination to receive on.
selectorthe selector expression.
Returns:
the message
Exceptions:
cms::CMSExceptionthrown if an error occurs
virtual cms::Message* activemq::cmsutil::CmsTemplate::receiveSelected ( const std::string &  destinationName,
const std::string &  selector 
) [virtual]

Performs a synchronous read from the specified destination, consuming only messages identified by the given selector.

Parameters:
destinationNamethe name of the destination to receive on (will be resolved to destination internally).
selectorthe selector expression.
Returns:
the message
Exceptions:
cms::CMSExceptionthrown if an error occurs
virtual void activemq::cmsutil::CmsTemplate::send ( cms::Destination dest,
MessageCreator messageCreator 
) [virtual]

Convenience method for sending a message to the specified destination.

Parameters:
destThe destination to send to
messageCreatorResponsible for creating the message to be sent
Exceptions:
cms::CMSExceptionthrown if an error occurs.
virtual void activemq::cmsutil::CmsTemplate::send ( const std::string &  destinationName,
MessageCreator messageCreator 
) [virtual]

Convenience method for sending a message to the specified destination.

Parameters:
destinationNameThe name of the destination to send to.
messageCreatorResponsible for creating the message to be sent
Exceptions:
cms::CMSExceptionthrown if an error occurs.
virtual void activemq::cmsutil::CmsTemplate::send ( MessageCreator messageCreator) [virtual]

Convenience method for sending a message to the default destination.

Parameters:
messageCreatorResponsible for creating the message to be sent
Exceptions:
cms::CMSExceptionthrown if an error occurs.
virtual void activemq::cmsutil::CmsTemplate::setDefaultDestination ( cms::Destination defaultDestination) [inline, virtual]

Sets the destination object to be used by default for send/receive operations.

If no default destination is provided, the defaultDestinationName property is used to resolve this default destination for send/receive operations.

Parameters:
defaultDestinationthe default destination
virtual void activemq::cmsutil::CmsTemplate::setDefaultDestinationName ( const std::string &  defaultDestinationName) [inline, virtual]

Sets the name of the default destination to be used from send/receive operations.

Calling this method will set the defaultDestination property to NULL. The destination type (topic/queue) is determined by the pubSubDomain property.

Parameters:
defaultDestinationNamethe name of the destination for send/receive to by default.
virtual void activemq::cmsutil::CmsTemplate::setDeliveryMode ( int  deliveryMode) [inline, virtual]

Set the delivery mode to use when sending a message.

Default is the Message default: "PERSISTENT".

Since a default value may be defined administratively, this is only used when "isExplicitQosEnabled" equals "true".

Parameters:
deliveryModethe delivery mode to use
See also:
isExplicitQosEnabled
virtual void activemq::cmsutil::CmsTemplate::setDeliveryPersistent ( bool  deliveryPersistent) [inline, virtual]

Set whether message delivery should be persistent or non-persistent, specified as boolean value ("true" or "false").

This will set the delivery mode accordingly, to either "PERSISTENT" or "NON_PERSISTENT".

Default it "true" aka delivery mode "PERSISTENT".

See also:
setDeliveryMode(int)
virtual void activemq::cmsutil::CmsTemplate::setExplicitQosEnabled ( bool  explicitQosEnabled) [inline, virtual]

Set if the QOS values (deliveryMode, priority, timeToLive) should be used for sending a message.

See also:
setDeliveryMode
setPriority
setTimeToLive
virtual void activemq::cmsutil::CmsTemplate::setMessageIdEnabled ( bool  messageIdEnabled) [inline, virtual]
virtual void activemq::cmsutil::CmsTemplate::setMessageTimestampEnabled ( bool  messageTimestampEnabled) [inline, virtual]
virtual void activemq::cmsutil::CmsTemplate::setNoLocal ( bool  noLocal) [inline, virtual]
virtual void activemq::cmsutil::CmsTemplate::setPriority ( int  priority) [inline, virtual]

Set the priority of a message when sending.

Since a default value may be defined administratively, this is only used when "isExplicitQosEnabled" equals "true".

See also:
isExplicitQosEnabled
virtual void activemq::cmsutil::CmsTemplate::setPubSubDomain ( bool  pubSubDomain) [inline, virtual]

Indicates whether the default destination is a topic (true) or a queue (false).

Calling this method will set the defaultDestination property to NULL.

Parameters:
pubSubDomainindicates whether to use pub-sub messaging (topics).

Reimplemented from activemq::cmsutil::CmsDestinationAccessor.

References activemq::cmsutil::CmsDestinationAccessor::setPubSubDomain().

virtual void activemq::cmsutil::CmsTemplate::setReceiveTimeout ( long long  receiveTimeout) [inline, virtual]
virtual void activemq::cmsutil::CmsTemplate::setTimeToLive ( long long  timeToLive) [inline, virtual]

Set the time-to-live of the message when sending.

Since a default value may be defined administratively, this is only used when "isExplicitQosEnabled" equals "true".

Parameters:
timeToLivethe message's lifetime (in milliseconds)
See also:
isExplicitQosEnabled

Friends And Related Function Documentation

friend class ProducerExecutor [friend]
friend class ReceiveExecutor [friend]
friend class ResolveProducerExecutor [friend]
friend class ResolveReceiveExecutor [friend]
friend class SendExecutor [friend]

Field Documentation

Default message priority.

My default, messages should live forever.

Timeout value indicating a blocking receive without timeout.

Timeout value indicating that a receive operation should check if a message is immediately available without blocking.


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