activemq-cpp-3.6.0
cms::Session Class Reference

A Session object is a single-threaded context for producing and consuming messages. More...

#include <src/main/cms/Session.h>

Inheritance diagram for cms::Session:

Public Types

enum  AcknowledgeMode {
  AUTO_ACKNOWLEDGE, DUPS_OK_ACKNOWLEDGE, CLIENT_ACKNOWLEDGE, SESSION_TRANSACTED,
  INDIVIDUAL_ACKNOWLEDGE
}

Public Member Functions

virtual ~Session ()
virtual void close ()=0
 Closes this session as well as any active child consumers or producers.
virtual void commit ()=0
 Commits all messages done in this transaction and releases any locks currently held.
virtual void rollback ()=0
 Rolls back all messages done in this transaction and releases any locks currently held.
virtual void recover ()=0
 Stops message delivery in this session, and restarts message delivery with the oldest unacknowledged message.
virtual MessageConsumercreateConsumer (const Destination *destination)=0
 Creates a MessageConsumer for the specified destination.
virtual MessageConsumercreateConsumer (const Destination *destination, const std::string &selector)=0
 Creates a MessageConsumer for the specified destination, using a message selector.
virtual MessageConsumercreateConsumer (const Destination *destination, const std::string &selector, bool noLocal)=0
 Creates a MessageConsumer for the specified destination, using a message selector.
virtual MessageConsumercreateDurableConsumer (const Topic *destination, const std::string &name, const std::string &selector, bool noLocal=false)=0
 Creates a durable subscriber to the specified topic, using a Message selector.
virtual MessageProducercreateProducer (const Destination *destination=NULL)=0
 Creates a MessageProducer to send messages to the specified destination.
virtual QueueBrowsercreateBrowser (const cms::Queue *queue)=0
 Creates a new QueueBrowser to peek at Messages on the given Queue.
virtual QueueBrowsercreateBrowser (const cms::Queue *queue, const std::string &selector)=0
 Creates a new QueueBrowser to peek at Messages on the given Queue.
virtual QueuecreateQueue (const std::string &queueName)=0
 Creates a queue identity given a Queue name.
virtual TopiccreateTopic (const std::string &topicName)=0
 Creates a topic identity given a Queue name.
virtual TemporaryQueuecreateTemporaryQueue ()=0
 Creates a TemporaryQueue object.
virtual TemporaryTopiccreateTemporaryTopic ()=0
 Creates a TemporaryTopic object.
virtual MessagecreateMessage ()=0
 Creates a new Message.
virtual BytesMessagecreateBytesMessage ()=0
 Creates a BytesMessage.
virtual BytesMessagecreateBytesMessage (const unsigned char *bytes, int bytesSize)=0
 Creates a BytesMessage and sets the payload to the passed value.
virtual StreamMessagecreateStreamMessage ()=0
 Creates a new StreamMessage.
virtual TextMessagecreateTextMessage ()=0
 Creates a new TextMessage.
virtual TextMessagecreateTextMessage (const std::string &text)=0
 Creates a new TextMessage and set the text to the value given.
virtual MapMessagecreateMapMessage ()=0
 Creates a new MapMessage.
virtual AcknowledgeMode getAcknowledgeMode () const =0
 Returns the acknowledgment mode of the session.
virtual bool isTransacted () const =0
 Gets if the Sessions is a Transacted Session.
virtual void unsubscribe (const std::string &name)=0
 Unsubscribes a durable subscription that has been created by a client.
virtual void setMessageTransformer (cms::MessageTransformer *transformer)=0
 Set an MessageTransformer instance that is passed on to all MessageProducer and MessageConsumer objects created from this Session.
virtual cms::MessageTransformergetMessageTransformer () const =0
 Gets the currently configured MessageTransformer for this Session.
- Public Member Functions inherited from cms::Closeable
virtual ~Closeable ()
- Public Member Functions inherited from cms::Startable
virtual ~Startable ()
virtual void start ()=0
 Starts the service.
- Public Member Functions inherited from cms::Stoppable
virtual ~Stoppable ()
virtual void stop ()=0
 Stops this service.

Detailed Description

A Session object is a single-threaded context for producing and consuming messages.

A session serves several purposes:

  • It is a factory for its message producers and consumers.
  • It supplies provider-optimized message factories.
  • It is a factory for TemporaryTopics and TemporaryQueues.
  • It provides a way to create Queue or Topic objects for those clients that need to dynamically manipulate provider-specific destination names.
  • It supports a single series of transactions that combine work spanning its producers and consumers into atomic units.
  • It defines a serial order for the messages it consumes and the messages it produces.
  • It retains messages it consumes until they have been acknowledged.
  • It serializes execution of message listeners registered with its message consumers.

A session can create and service multiple message producers and consumers.

One typical use is to have a thread block on a synchronous MessageConsumer until a message arrives. The thread may then use one or more of the Session's MessageProducers.

If a client desires to have one thread produce messages while others consume them, the client should use a separate session for its producing thread.

Certain rules apply to a session's close method and are detailed below.

  • There is no need to close the producers and consumers of a closed session.
  • The close call will block until a receive call or message listener in progress has completed. A blocked message consumer receive call returns null when this session is closed.
  • Closing a transacted session must roll back the transaction in progress.
  • The close method is the only Session method that can be called concurrently.
  • Invoking any other Session method on a closed session must throw an IllegalStateException. Closing a closed session must not throw any exceptions.

Transacted Sessions

When a Session is created it can be set to operate in a Transaction based mode. Each Session then operates in a single transaction for all Producers and Consumers of that Session. Messages sent and received within a Transaction are grouped into an atomic unit that is committed or rolled back together.

For a MessageProducer this implies that all messages sent by the producer are not sent to the Provider unit the commit call is made. Rolling back the Transaction results in all produced Messages being dropped.

For a MessageConsumer this implies that all received messages are not Acknowledged until the Commit call is made. Rolling back the Transaction results in all Consumed Message being redelivered to the client, the Provider may allow configuration that limits the Maximum number of redeliveries for a Message.

While the Session interface implements the Startable and Stoppable interfaces it is not required to implement these methods and can throw an UnsupportedOperation exception if they are not available for the given CMS provider.

Since
1.0

Member Enumeration Documentation

Enumerator:
AUTO_ACKNOWLEDGE 

With this acknowledgment mode, the session automatically acknowledges a client's receipt of a message either when the session has successfully returned from a call to receive or when the message listener the session has called to process the message successfully returns.

DUPS_OK_ACKNOWLEDGE 

With this acknowledgment mode, the session automatically acknowledges a client's receipt of a message either when the session has successfully returned from a call to receive or when the message listener the session has called to process the message successfully returns.

Acknowledgments may be delayed in this mode to increase performance at the cost of the message being redelivered this client fails.

CLIENT_ACKNOWLEDGE 

With this acknowledgment mode, the client acknowledges a consumed message by calling the message's acknowledge method.

SESSION_TRANSACTED 

Messages will be consumed when the transaction commits.

INDIVIDUAL_ACKNOWLEDGE 

Message will be acknowledged individually.

Normally the acks sent acknowledge the given message and all messages received before it, this mode only acknowledges one message.

Constructor & Destructor Documentation

virtual cms::Session::~Session ( )
virtual

Member Function Documentation

virtual void cms::Session::close ( )
pure virtual

Closes this session as well as any active child consumers or producers.

Exceptions
CMSException- If an internal error occurs.

Implements cms::Closeable.

Implemented in activemq::core::kernels::ActiveMQSessionKernel, activemq::cmsutil::PooledSession, and activemq::core::ActiveMQSession.

virtual void cms::Session::commit ( )
pure virtual

Commits all messages done in this transaction and releases any locks currently held.

Exceptions
CMSException- If an internal error occurs.
IllegalStateException- if the method is not called by a transacted session.

Implemented in activemq::core::kernels::ActiveMQSessionKernel, activemq::cmsutil::PooledSession, activemq::core::ActiveMQSession, activemq::core::ActiveMQXASession, and activemq::core::kernels::ActiveMQXASessionKernel.

Referenced by activemq::cmsutil::PooledSession::commit().

virtual QueueBrowser* cms::Session::createBrowser ( const cms::Queue queue)
pure virtual

Creates a new QueueBrowser to peek at Messages on the given Queue.

Parameters
queuethe Queue to browse
Returns
New QueueBrowser that is owned by the caller.
Exceptions
CMSException- If an internal error occurs.
InvalidDestinationException- if the destination given is invalid.

Implemented in activemq::core::kernels::ActiveMQSessionKernel, activemq::cmsutil::PooledSession, and activemq::core::ActiveMQSession.

virtual QueueBrowser* cms::Session::createBrowser ( const cms::Queue queue,
const std::string &  selector 
)
pure virtual

Creates a new QueueBrowser to peek at Messages on the given Queue.

Parameters
queuethe Queue to browse
selectorthe Message selector to filter which messages are browsed.
Returns
New QueueBrowser that is owned by the caller.
Exceptions
CMSException- If an internal error occurs.
InvalidDestinationException- if the destination given is invalid.

Implemented in activemq::core::kernels::ActiveMQSessionKernel, activemq::cmsutil::PooledSession, and activemq::core::ActiveMQSession.

virtual BytesMessage* cms::Session::createBytesMessage ( )
pure virtual
virtual BytesMessage* cms::Session::createBytesMessage ( const unsigned char *  bytes,
int  bytesSize 
)
pure virtual

Creates a BytesMessage and sets the payload to the passed value.

Parameters
bytesan array of bytes to set in the message
bytesSizethe size of the bytes array, or number of bytes to use
Exceptions
CMSException- If an internal error occurs.

Implemented in activemq::core::kernels::ActiveMQSessionKernel, activemq::cmsutil::PooledSession, and activemq::core::ActiveMQSession.

virtual MessageConsumer* cms::Session::createConsumer ( const Destination destination)
pure virtual

Creates a MessageConsumer for the specified destination.

Parameters
destinationthe Destination that this consumer receiving messages for.
Returns
pointer to a new MessageConsumer that is owned by the caller ( caller deletes )
Exceptions
CMSException- If an internal error occurs.
InvalidDestinationException- if an invalid destination is specified.

Implemented in activemq::core::kernels::ActiveMQSessionKernel, activemq::cmsutil::PooledSession, and activemq::core::ActiveMQSession.

Referenced by activemq::cmsutil::PooledSession::createConsumer().

virtual MessageConsumer* cms::Session::createConsumer ( const Destination destination,
const std::string &  selector 
)
pure virtual

Creates a MessageConsumer for the specified destination, using a message selector.

Parameters
destinationthe Destination that this consumer receiving messages for.
selectorthe Message Selector to use
Returns
pointer to a new MessageConsumer that is owned by the caller ( caller deletes )
Exceptions
CMSException- If an internal error occurs.
InvalidDestinationException- if an invalid destination is specified.
InvalidSelectorException- if the message selector is invalid.

Implemented in activemq::core::kernels::ActiveMQSessionKernel, activemq::cmsutil::PooledSession, and activemq::core::ActiveMQSession.

virtual MessageConsumer* cms::Session::createConsumer ( const Destination destination,
const std::string &  selector,
bool  noLocal 
)
pure virtual

Creates a MessageConsumer for the specified destination, using a message selector.

Parameters
destinationthe Destination that this consumer receiving messages for.
selectorthe Message Selector to use
noLocalif true, and the destination is a topic, inhibits the delivery of messages published by its own connection. The behavior for NoLocal is not specified if the destination is a queue.
Returns
pointer to a new MessageConsumer that is owned by the caller ( caller deletes )
Exceptions
CMSException- If an internal error occurs.
InvalidDestinationException- if an invalid destination is specified.
InvalidSelectorException- if the message selector is invalid.

Implemented in activemq::core::kernels::ActiveMQSessionKernel, activemq::cmsutil::PooledSession, and activemq::core::ActiveMQSession.

virtual MessageConsumer* cms::Session::createDurableConsumer ( const Topic destination,
const std::string &  name,
const std::string &  selector,
bool  noLocal = false 
)
pure virtual

Creates a durable subscriber to the specified topic, using a Message selector.

Sessions that create durable consumers must use the same client Id as was used the last time the subscription was created in order to receive all messages that were delivered while the client was offline.

Parameters
destinationthe topic to subscribe to
nameThe name used to identify the subscription
selectorthe Message Selector to use
noLocalif true, and the destination is a topic, inhibits the delivery of messages published by its own connection. The behavior for NoLocal is not specified if the destination is a queue.
Returns
pointer to a new durable MessageConsumer that is owned by the caller ( caller deletes )
Exceptions
CMSException- If an internal error occurs.
InvalidDestinationException- if an invalid destination is specified.
InvalidSelectorException- if the message selector is invalid.

Implemented in activemq::core::kernels::ActiveMQSessionKernel, activemq::cmsutil::PooledSession, and activemq::core::ActiveMQSession.

Referenced by activemq::cmsutil::PooledSession::createDurableConsumer().

virtual MapMessage* cms::Session::createMapMessage ( )
pure virtual
virtual Message* cms::Session::createMessage ( )
pure virtual
virtual MessageProducer* cms::Session::createProducer ( const Destination destination = NULL)
pure virtual

Creates a MessageProducer to send messages to the specified destination.

Parameters
destinationthe Destination to send on
Returns
New MessageProducer that is owned by the caller.
Exceptions
CMSException- If an internal error occurs.
InvalidDestinationException- if an invalid destination is specified.

Implemented in activemq::core::kernels::ActiveMQSessionKernel, activemq::cmsutil::PooledSession, and activemq::core::ActiveMQSession.

Referenced by activemq::cmsutil::PooledSession::createProducer().

virtual Queue* cms::Session::createQueue ( const std::string &  queueName)
pure virtual

Creates a queue identity given a Queue name.

Parameters
queueNamethe name of the new Queue
Returns
new Queue pointer that is owned by the caller.
Exceptions
CMSException- If an internal error occurs.

Implemented in activemq::core::kernels::ActiveMQSessionKernel, activemq::cmsutil::PooledSession, and activemq::core::ActiveMQSession.

Referenced by activemq::cmsutil::PooledSession::createQueue().

virtual StreamMessage* cms::Session::createStreamMessage ( )
pure virtual
virtual TemporaryQueue* cms::Session::createTemporaryQueue ( )
pure virtual

Creates a TemporaryQueue object.

Returns
new TemporaryQueue pointer that is owned by the caller.
Exceptions
CMSException- If an internal error occurs.

Implemented in activemq::core::kernels::ActiveMQSessionKernel, activemq::cmsutil::PooledSession, and activemq::core::ActiveMQSession.

Referenced by activemq::cmsutil::PooledSession::createTemporaryQueue().

virtual TemporaryTopic* cms::Session::createTemporaryTopic ( )
pure virtual
virtual TextMessage* cms::Session::createTextMessage ( )
pure virtual
virtual TextMessage* cms::Session::createTextMessage ( const std::string &  text)
pure virtual

Creates a new TextMessage and set the text to the value given.

Parameters
textthe initial text for the message
Exceptions
CMSException- If an internal error occurs.

Implemented in activemq::core::kernels::ActiveMQSessionKernel, activemq::cmsutil::PooledSession, and activemq::core::ActiveMQSession.

virtual Topic* cms::Session::createTopic ( const std::string &  topicName)
pure virtual

Creates a topic identity given a Queue name.

Parameters
topicNamethe name of the new Topic
Returns
new Topic pointer that is owned by the caller.
Exceptions
CMSException- If an internal error occurs.

Implemented in activemq::core::kernels::ActiveMQSessionKernel, activemq::cmsutil::PooledSession, and activemq::core::ActiveMQSession.

Referenced by activemq::cmsutil::PooledSession::createTopic().

virtual AcknowledgeMode cms::Session::getAcknowledgeMode ( ) const
pure virtual

Returns the acknowledgment mode of the session.

Returns
the Sessions Acknowledge Mode
Exceptions
CMSException- If an internal error occurs.

Implemented in activemq::core::kernels::ActiveMQSessionKernel, activemq::cmsutil::PooledSession, and activemq::core::ActiveMQSession.

Referenced by activemq::cmsutil::PooledSession::getAcknowledgeMode().

virtual cms::MessageTransformer* cms::Session::getMessageTransformer ( ) const
pure virtual
virtual bool cms::Session::isTransacted ( ) const
pure virtual
virtual void cms::Session::recover ( )
pure virtual

Stops message delivery in this session, and restarts message delivery with the oldest unacknowledged message.

All consumers deliver messages in a serial order. Acknowledging a received message automatically acknowledges all messages that have been delivered to the client.

Restarting a session causes it to take the following actions:

  • Stop message delivery
  • Mark all messages that might have been delivered but not acknowledged as "redelivered"
  • Restart the delivery sequence including all unacknowledged messages that had been previously delivered. Redelivered messages do not have to be delivered in exactly their original delivery order.
Exceptions
CMSException- if the CMS provider fails to stop and restart message delivery due to some internal error.
IllegalStateException- if the method is called by a transacted session.

Implemented in activemq::core::kernels::ActiveMQSessionKernel, activemq::cmsutil::PooledSession, and activemq::core::ActiveMQSession.

Referenced by activemq::cmsutil::PooledSession::recover().

virtual void cms::Session::rollback ( )
pure virtual

Rolls back all messages done in this transaction and releases any locks currently held.

Exceptions
CMSException- If an internal error occurs.
IllegalStateException- if the method is not called by a transacted session.

Implemented in activemq::core::kernels::ActiveMQSessionKernel, activemq::cmsutil::PooledSession, activemq::core::ActiveMQSession, activemq::core::ActiveMQXASession, and activemq::core::kernels::ActiveMQXASessionKernel.

Referenced by activemq::cmsutil::PooledSession::rollback().

virtual void cms::Session::setMessageTransformer ( cms::MessageTransformer transformer)
pure virtual

Set an MessageTransformer instance that is passed on to all MessageProducer and MessageConsumer objects created from this Session.

The CMS code never takes ownership of the MessageTransformer pointer which implies that the client code must ensure that the object remains valid for the lifetime of the CMS object to which the MessageTransformer has been assigned.

Parameters
transformerPointer to the cms::MessageTransformer to set on all MessageConsumers and MessageProducers.

Implemented in activemq::core::kernels::ActiveMQSessionKernel, activemq::cmsutil::PooledSession, and activemq::core::ActiveMQSession.

Referenced by activemq::cmsutil::PooledSession::setMessageTransformer().

virtual void cms::Session::unsubscribe ( const std::string &  name)
pure virtual

Unsubscribes a durable subscription that has been created by a client.

This method deletes the state being maintained on behalf of the subscriber by its provider. It is erroneous for a client to delete a durable subscription while there is an active MessageConsumer or Subscriber for the subscription, or while a consumed message is part of a pending transaction or has not been acknowledged in the session.

Parameters
nameThe name used to identify this subscription
Exceptions
CMSException- If an internal error occurs.

Implemented in activemq::core::kernels::ActiveMQSessionKernel, activemq::cmsutil::PooledSession, and activemq::core::ActiveMQSession.

Referenced by activemq::cmsutil::PooledSession::unsubscribe().


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