activemq-cpp-3.6.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 ()
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.
- Public Member Functions inherited from activemq::cmsutil::CmsDestinationAccessor
 CmsDestinationAccessor ()
virtual ~CmsDestinationAccessor ()
virtual bool isPubSubDomain () const
virtual DestinationResolvergetDestinationResolver ()
virtual const DestinationResolvergetDestinationResolver () const
virtual void setDestinationResolver (DestinationResolver *destRes)
- Public Member Functions inherited from activemq::cmsutil::CmsAccessor
 CmsAccessor ()
virtual ~CmsAccessor ()
virtual ResourceLifecycleManagergetResourceLifecycleManager ()
virtual const
ResourceLifecycleManager
getResourceLifecycleManager () const
virtual void setConnectionFactory (cms::ConnectionFactory *connectionFactory)
 Set the ConnectionFactory to use for obtaining CMS Connections.
virtual const
cms::ConnectionFactory
getConnectionFactory () const
 Return the ConnectionFactory that this accessor uses for obtaining CMS Connections.
virtual cms::ConnectionFactorygetConnectionFactory ()
 Return the ConnectionFactory that this accessor uses for obtaining CMS Connections.
virtual void setSessionAcknowledgeMode (cms::Session::AcknowledgeMode sessionAcknowledgeMode)
 Set the CMS acknowledgment mode that is used when creating a CMS Session to send a message.
virtual
cms::Session::AcknowledgeMode 
getSessionAcknowledgeMode () const
 Return the acknowledgment mode for CMS sessions.

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.
- Protected Member Functions inherited from activemq::cmsutil::CmsDestinationAccessor
virtual cms::DestinationresolveDestinationName (cms::Session *session, const std::string &destName)
virtual void checkDestinationResolver ()
- Protected Member Functions inherited from activemq::cmsutil::CmsAccessor
 CmsAccessor (const CmsAccessor &)
CmsAccessoroperator= (const CmsAccessor &)
virtual cms::ConnectioncreateConnection ()
 Create a CMS Connection via this template's ConnectionFactory.
virtual cms::SessioncreateSession (cms::Connection *con)
 Create a CMS Session for the given Connection.
virtual void checkConnectionFactory ()
 Verifies that the connection factory is valid.

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 ( )
virtual

Member Function Documentation

void activemq::cmsutil::CmsTemplate::destroy ( )
protectedvirtual

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 const cms::Destination* activemq::cmsutil::CmsTemplate::getDefaultDestination ( ) const
inlinevirtual

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

Returns
the default destination. Const version of this method.
virtual cms::Destination* activemq::cmsutil::CmsTemplate::getDefaultDestination ( )
inlinevirtual

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

Returns
the default destination. Non-const version of this method.
virtual const std::string activemq::cmsutil::CmsTemplate::getDefaultDestinationName ( ) const
inlinevirtual

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
inlinevirtual

Return the delivery mode to use when sending a message.

virtual int activemq::cmsutil::CmsTemplate::getPriority ( ) const
inlinevirtual

Return the priority of a message when sending.

virtual long long activemq::cmsutil::CmsTemplate::getReceiveTimeout ( ) const
inlinevirtual
virtual long long activemq::cmsutil::CmsTemplate::getTimeToLive ( ) const
inlinevirtual

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

void activemq::cmsutil::CmsTemplate::init ( )
protectedvirtual

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
inlinevirtual

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
inlinevirtual
virtual bool activemq::cmsutil::CmsTemplate::isMessageTimestampEnabled ( ) const
inlinevirtual
virtual bool activemq::cmsutil::CmsTemplate::isNoLocal ( ) const
inlinevirtual
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::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::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 ( 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::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::setDefaultDestination ( cms::Destination defaultDestination)
inlinevirtual

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)
inlinevirtual

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.

References NULL.

virtual void activemq::cmsutil::CmsTemplate::setDeliveryMode ( int  deliveryMode)
inlinevirtual

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)
inlinevirtual

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)
inlinevirtual

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)
inlinevirtual
virtual void activemq::cmsutil::CmsTemplate::setMessageTimestampEnabled ( bool  messageTimestampEnabled)
inlinevirtual
virtual void activemq::cmsutil::CmsTemplate::setNoLocal ( bool  noLocal)
inlinevirtual
virtual void activemq::cmsutil::CmsTemplate::setPriority ( int  priority)
inlinevirtual

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)
inlinevirtual

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 NULL, and activemq::cmsutil::CmsDestinationAccessor::setPubSubDomain().

virtual void activemq::cmsutil::CmsTemplate::setReceiveTimeout ( long long  receiveTimeout)
inlinevirtual
virtual void activemq::cmsutil::CmsTemplate::setTimeToLive ( long long  timeToLive)
inlinevirtual

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

const int activemq::cmsutil::CmsTemplate::DEFAULT_PRIORITY
static

Default message priority.

const long long activemq::cmsutil::CmsTemplate::DEFAULT_TIME_TO_LIVE
static

My default, messages should live forever.

const long long activemq::cmsutil::CmsTemplate::RECEIVE_TIMEOUT_INDEFINITE_WAIT
static

Timeout value indicating a blocking receive without timeout.

const long long activemq::cmsutil::CmsTemplate::RECEIVE_TIMEOUT_NO_WAIT
static

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: