activemq-cpp-3.4.0
|
A Session object is a single-threaded context for producing and consuming messages. More...
#include <src/main/cms/Session.h>
Public Types | |
enum | AcknowledgeMode { AUTO_ACKNOWLEDGE, DUPS_OK_ACKNOWLEDGE, CLIENT_ACKNOWLEDGE, SESSION_TRANSACTED, INDIVIDUAL_ACKNOWLEDGE } |
Public Member Functions | |
virtual | ~Session () throw () |
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 MessageConsumer * | createConsumer (const Destination *destination)=0 |
Creates a MessageConsumer for the specified destination. | |
virtual MessageConsumer * | createConsumer (const Destination *destination, const std::string &selector)=0 |
Creates a MessageConsumer for the specified destination, using a message selector. | |
virtual MessageConsumer * | createConsumer (const Destination *destination, const std::string &selector, bool noLocal)=0 |
Creates a MessageConsumer for the specified destination, using a message selector. | |
virtual MessageConsumer * | createDurableConsumer (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 MessageProducer * | createProducer (const Destination *destination=NULL)=0 |
Creates a MessageProducer to send messages to the specified destination. | |
virtual QueueBrowser * | createBrowser (const cms::Queue *queue)=0 |
Creates a new QueueBrowser to peek at Messages on the given Queue. | |
virtual QueueBrowser * | createBrowser (const cms::Queue *queue, const std::string &selector)=0 |
Creates a new QueueBrowser to peek at Messages on the given Queue. | |
virtual Queue * | createQueue (const std::string &queueName)=0 |
Creates a queue identity given a Queue name. | |
virtual Topic * | createTopic (const std::string &topicName)=0 |
Creates a topic identity given a Queue name. | |
virtual TemporaryQueue * | createTemporaryQueue ()=0 |
Creates a TemporaryQueue object. | |
virtual TemporaryTopic * | createTemporaryTopic ()=0 |
Creates a TemporaryTopic object. | |
virtual Message * | createMessage ()=0 |
Creates a new Message. | |
virtual BytesMessage * | createBytesMessage ()=0 |
Creates a BytesMessage. | |
virtual BytesMessage * | createBytesMessage (const unsigned char *bytes, int bytesSize)=0 |
Creates a BytesMessage and sets the payload to the passed value. | |
virtual StreamMessage * | createStreamMessage ()=0 |
Creates a new StreamMessage. | |
virtual TextMessage * | createTextMessage ()=0 |
Creates a new TextMessage. | |
virtual TextMessage * | createTextMessage (const std::string &text)=0 |
Creates a new TextMessage and set the text to the value given. | |
virtual MapMessage * | createMapMessage ()=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. |
A Session object is a single-threaded context for producing and consuming messages.
A session serves several purposes:
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.
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.
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. |
virtual cms::Session::~Session | ( | ) | throw () [virtual] |
virtual void cms::Session::close | ( | ) | [pure virtual] |
Closes this session as well as any active child consumers or producers.
CMSException | - If an internal error occurs. |
Implements cms::Closeable.
Implemented in 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.
CMSException | - If an internal error occurs. |
IllegalStateException | - if the method is not called by a transacted session. |
Implemented in activemq::cmsutil::PooledSession, activemq::core::ActiveMQSession, and activemq::core::ActiveMQXASession.
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.
queue | the Queue to browse |
CMSException | - If an internal error occurs. |
InvalidDestinationException | - if the destination given is invalid. |
Implemented in 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.
queue | the Queue to browse |
selector | the Message selector to filter which messages are browsed. |
CMSException | - If an internal error occurs. |
InvalidDestinationException | - if the destination given is invalid. |
Implemented in activemq::cmsutil::PooledSession, and activemq::core::ActiveMQSession.
virtual BytesMessage* cms::Session::createBytesMessage | ( | ) | [pure virtual] |
Creates a BytesMessage.
CMSException | - If an internal error occurs. |
Implemented in activemq::cmsutil::PooledSession, and activemq::core::ActiveMQSession.
Referenced by activemq::cmsutil::PooledSession::createBytesMessage().
virtual BytesMessage* cms::Session::createBytesMessage | ( | const unsigned char * | bytes, |
int | bytesSize | ||
) | [pure virtual] |
Creates a BytesMessage and sets the payload to the passed value.
bytes | an array of bytes to set in the message |
bytesSize | the size of the bytes array, or number of bytes to use |
CMSException | - If an internal error occurs. |
Implemented in activemq::cmsutil::PooledSession, and activemq::core::ActiveMQSession.
virtual MessageConsumer* cms::Session::createConsumer | ( | const Destination * | destination | ) | [pure virtual] |
Creates a MessageConsumer for the specified destination.
destination | the Destination that this consumer receiving messages for. |
CMSException | - If an internal error occurs. |
InvalidDestinationException | - if an invalid destination is specified. |
Implemented in 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.
destination | the Destination that this consumer receiving messages for. |
selector | the Message Selector to use |
CMSException | - If an internal error occurs. |
InvalidDestinationException | - if an invalid destination is specified. |
InvalidSelectorException | - if the message selector is invalid. |
Implemented in 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.
destination | the Destination that this consumer receiving messages for. |
selector | the Message Selector to use |
noLocal | if 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. |
CMSException | - If an internal error occurs. |
InvalidDestinationException | - if an invalid destination is specified. |
InvalidSelectorException | - if the message selector is invalid. |
Implemented in 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.
destination | the topic to subscribe to |
name | The name used to identify the subscription |
selector | the Message Selector to use |
noLocal | if 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. |
CMSException | - If an internal error occurs. |
InvalidDestinationException | - if an invalid destination is specified. |
InvalidSelectorException | - if the message selector is invalid. |
Implemented in activemq::cmsutil::PooledSession, and activemq::core::ActiveMQSession.
Referenced by activemq::cmsutil::PooledSession::createDurableConsumer().
virtual MapMessage* cms::Session::createMapMessage | ( | ) | [pure virtual] |
Creates a new MapMessage.
CMSException | - If an internal error occurs. |
Implemented in activemq::cmsutil::PooledSession, and activemq::core::ActiveMQSession.
Referenced by activemq::cmsutil::PooledSession::createMapMessage().
virtual Message* cms::Session::createMessage | ( | ) | [pure virtual] |
Creates a new Message.
CMSException | - If an internal error occurs. |
Implemented in activemq::cmsutil::PooledSession, and activemq::core::ActiveMQSession.
Referenced by activemq::cmsutil::PooledSession::createMessage().
virtual MessageProducer* cms::Session::createProducer | ( | const Destination * | destination = NULL | ) | [pure virtual] |
Creates a MessageProducer to send messages to the specified destination.
destination | the Destination to send on |
CMSException | - If an internal error occurs. |
InvalidDestinationException | - if an invalid destination is specified. |
Implemented in 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.
queueName | the name of the new Queue |
CMSException | - If an internal error occurs. |
Implemented in activemq::cmsutil::PooledSession, and activemq::core::ActiveMQSession.
Referenced by activemq::cmsutil::PooledSession::createQueue().
virtual StreamMessage* cms::Session::createStreamMessage | ( | ) | [pure virtual] |
Creates a new StreamMessage.
CMSException | - If an internal error occurs. |
Implemented in activemq::cmsutil::PooledSession, and activemq::core::ActiveMQSession.
Referenced by activemq::cmsutil::PooledSession::createStreamMessage().
virtual TemporaryQueue* cms::Session::createTemporaryQueue | ( | ) | [pure virtual] |
Creates a TemporaryQueue object.
CMSException | - If an internal error occurs. |
Implemented in activemq::cmsutil::PooledSession, and activemq::core::ActiveMQSession.
Referenced by activemq::cmsutil::PooledSession::createTemporaryQueue().
virtual TemporaryTopic* cms::Session::createTemporaryTopic | ( | ) | [pure virtual] |
Creates a TemporaryTopic object.
CMSException | - If an internal error occurs. |
Implemented in activemq::cmsutil::PooledSession, and activemq::core::ActiveMQSession.
Referenced by activemq::cmsutil::PooledSession::createTemporaryTopic().
virtual TextMessage* cms::Session::createTextMessage | ( | const std::string & | text | ) | [pure virtual] |
Creates a new TextMessage and set the text to the value given.
text | the initial text for the message |
CMSException | - If an internal error occurs. |
Implemented in activemq::cmsutil::PooledSession, and activemq::core::ActiveMQSession.
virtual TextMessage* cms::Session::createTextMessage | ( | ) | [pure virtual] |
Creates a new TextMessage.
CMSException | - If an internal error occurs. |
Implemented in activemq::cmsutil::PooledSession, and activemq::core::ActiveMQSession.
Referenced by activemq::cmsutil::PooledSession::createTextMessage().
virtual Topic* cms::Session::createTopic | ( | const std::string & | topicName | ) | [pure virtual] |
Creates a topic identity given a Queue name.
topicName | the name of the new Topic |
CMSException | - If an internal error occurs. |
Implemented in 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.
CMSException | - If an internal error occurs. |
Implemented in activemq::cmsutil::PooledSession, and activemq::core::ActiveMQSession.
Referenced by activemq::cmsutil::PooledSession::getAcknowledgeMode().
virtual bool cms::Session::isTransacted | ( | ) | const [pure virtual] |
Gets if the Sessions is a Transacted Session.
CMSException | - If an internal error occurs. |
Implemented in activemq::cmsutil::PooledSession, activemq::core::ActiveMQSession, and activemq::core::ActiveMQXASession.
Referenced by activemq::cmsutil::PooledSession::isTransacted().
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:
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::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.
CMSException | - If an internal error occurs. |
IllegalStateException | - if the method is not called by a transacted session. |
Implemented in activemq::cmsutil::PooledSession, activemq::core::ActiveMQSession, and activemq::core::ActiveMQXASession.
Referenced by activemq::cmsutil::PooledSession::rollback().
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.
name | The name used to identify this subscription |
CMSException | - If an internal error occurs. |
Implemented in activemq::cmsutil::PooledSession, and activemq::core::ActiveMQSession.
Referenced by activemq::cmsutil::PooledSession::unsubscribe().