activemq-cpp-3.9.5
PooledSession.h
Go to the documentation of this file.
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18#ifndef _ACTIVEMQ_CMSUTIL_POOLEDSESSION_H_
19#define _ACTIVEMQ_CMSUTIL_POOLEDSESSION_H_
20
21#include <cms/Session.h>
22#include <decaf/util/StlMap.h>
26
27namespace activemq {
28namespace cmsutil {
29
30 // Forward declarations.
31 class SessionPool;
32
37 class AMQCPP_API PooledSession : public cms::Session {
38 private:
39
40 SessionPool* pool;
41
42 cms::Session* session;
43
45
47
48 private:
49
50 PooledSession(const PooledSession&);
51 PooledSession& operator=(const PooledSession&);
52
53 public:
54
56
60 virtual ~PooledSession();
61
68 return session;
69 }
70
76 virtual const cms::Session* getSession() const {
77 return session;
78 }
79
86 virtual void close();
87
88 virtual void start() {
89 session->start();
90 }
91
92 virtual void stop() {
93 session->stop();
94 }
95
96 virtual void commit() {
97 session->commit();
98 }
99
100 virtual void rollback() {
101 session->rollback();
102 }
103
104 virtual void recover() {
105 session->recover();
106 }
107
109 return session->createConsumer(destination);
110 }
111
113 const std::string& selector) {
114 return session->createConsumer(destination, selector);
115 }
116
118 const std::string& selector,
119 bool noLocal) {
120 return session->createConsumer(destination, selector, noLocal);
121 }
122
124 const std::string& name,
125 const std::string& selector,
126 bool noLocal = false) {
127 return session->createDurableConsumer(destination, name, selector, noLocal);
128 }
129
147 const std::string& selector, bool noLocal);
148
150 return session->createProducer(destination);
151 }
152
166
168
169 virtual cms::QueueBrowser* createBrowser(const cms::Queue* queue, const std::string& selector);
170
171 virtual cms::Queue* createQueue(const std::string& queueName) {
172 return session->createQueue(queueName);
173 }
174
175 virtual cms::Topic* createTopic(const std::string& topicName) {
176 return session->createTopic(topicName);
177 }
178
180 return session->createTemporaryQueue();
181 }
182
184 return session->createTemporaryTopic();
185 }
186
188 return session->createMessage();
189 }
190
192 return session->createBytesMessage();
193 }
194
195 virtual cms::BytesMessage* createBytesMessage(const unsigned char* bytes, int bytesSize) {
196 return session->createBytesMessage(bytes, bytesSize);
197 }
198
200 return session->createStreamMessage();
201 }
202
204 return session->createTextMessage();
205 }
206
207 virtual cms::TextMessage* createTextMessage(const std::string& text) {
208 return session->createTextMessage(text);
209 }
210
212 return session->createMapMessage();
213 }
214
216 return session->getAcknowledgeMode();
217 }
218
219 virtual bool isTransacted() const {
220 return session->isTransacted();
221 }
222
223 virtual void unsubscribe(const std::string& name) {
224 session->unsubscribe(name);
225 }
226
228 session->setMessageTransformer(transformer);
229 }
230
232 return session->getMessageTransformer();
233 }
234
235 private:
236
237 std::string getUniqueDestName(const cms::Destination* dest);
238
239 };
240
241}}
242
243#endif /*_ACTIVEMQ_CMSUTIL_POOLEDSESSION_H_*/
#define AMQCPP_API
Definition Config.h:30
virtual cms::MessageConsumer * createDurableConsumer(const cms::Topic *destination, const std::string &name, const std::string &selector, bool noLocal=false)
Creates a durable subscriber to the specified topic, using a Message selector.
Definition PooledSession.h:123
virtual cms::MessageConsumer * createCachedConsumer(const cms::Destination *destination, const std::string &selector, bool noLocal)
First checks the internal consumer cache and creates on if none exist for the given destination,...
virtual void setMessageTransformer(cms::MessageTransformer *transformer)
Set an MessageTransformer instance that is passed on to all MessageProducer and MessageConsumer objec...
Definition PooledSession.h:227
virtual cms::Queue * createQueue(const std::string &queueName)
Creates a queue identity given a Queue name.
Definition PooledSession.h:171
virtual cms::Message * createMessage()
Creates a new Message.
Definition PooledSession.h:187
virtual cms::StreamMessage * createStreamMessage()
Creates a new StreamMessage.
Definition PooledSession.h:199
virtual cms::MessageConsumer * createConsumer(const cms::Destination *destination, const std::string &selector)
Creates a MessageConsumer for the specified destination, using a message selector.
Definition PooledSession.h:112
virtual void rollback()
Rolls back all messages done in this transaction and releases any locks currently held.
Definition PooledSession.h:100
virtual cms::QueueBrowser * createBrowser(const cms::Queue *queue)
Creates a new QueueBrowser to peek at Messages on the given Queue.
virtual cms::MapMessage * createMapMessage()
Creates a new MapMessage.
Definition PooledSession.h:211
virtual cms::Session * getSession()
Returns a non-constant reference to the internal session object.
Definition PooledSession.h:67
virtual const cms::Session * getSession() const
Returns a constant reference to the internal session object.
Definition PooledSession.h:76
virtual ~PooledSession()
Does nothing.
virtual cms::MessageConsumer * createConsumer(const cms::Destination *destination, const std::string &selector, bool noLocal)
Creates a MessageConsumer for the specified destination, using a message selector.
Definition PooledSession.h:117
virtual cms::TemporaryQueue * createTemporaryQueue()
Creates a TemporaryQueue object.
Definition PooledSession.h:179
virtual cms::QueueBrowser * createBrowser(const cms::Queue *queue, const std::string &selector)
Creates a new QueueBrowser to peek at Messages on the given Queue.
virtual void recover()
Stops message delivery in this session, and restarts message delivery with the oldest unacknowledged ...
Definition PooledSession.h:104
virtual void unsubscribe(const std::string &name)
Unsubscribes a durable subscription that has been created by a client.
Definition PooledSession.h:223
virtual void commit()
Commits all messages done in this transaction and releases any locks currently held.
Definition PooledSession.h:96
virtual cms::MessageConsumer * createConsumer(const cms::Destination *destination)
Creates a MessageConsumer for the specified destination.
Definition PooledSession.h:108
virtual void close()
Returns this session back to the pool, but does not close or destroy the internal session object.
virtual cms::TextMessage * createTextMessage(const std::string &text)
Creates a new TextMessage and set the text to the value given.
Definition PooledSession.h:207
virtual void stop()
Stops this service.
Definition PooledSession.h:92
virtual cms::BytesMessage * createBytesMessage(const unsigned char *bytes, int bytesSize)
Creates a BytesMessage and sets the payload to the passed value.
Definition PooledSession.h:195
virtual cms::TemporaryTopic * createTemporaryTopic()
Creates a TemporaryTopic object.
Definition PooledSession.h:183
virtual cms::Session::AcknowledgeMode getAcknowledgeMode() const
Returns the acknowledgment mode of the session.
Definition PooledSession.h:215
PooledSession(SessionPool *pool, cms::Session *session)
virtual cms::TextMessage * createTextMessage()
Creates a new TextMessage.
Definition PooledSession.h:203
virtual bool isTransacted() const
Gets if the Sessions is a Transacted Session.
Definition PooledSession.h:219
virtual cms::Topic * createTopic(const std::string &topicName)
Creates a topic identity given a Queue name.
Definition PooledSession.h:175
virtual cms::MessageProducer * createCachedProducer(const cms::Destination *destination)
First checks the internal producer cache and creates one if none exist for the given destination.
virtual cms::BytesMessage * createBytesMessage()
Creates a BytesMessage.
Definition PooledSession.h:191
virtual void start()
Starts the service.
Definition PooledSession.h:88
virtual cms::MessageProducer * createProducer(const cms::Destination *destination)
Creates a MessageProducer to send messages to the specified destination.
Definition PooledSession.h:149
virtual cms::MessageTransformer * getMessageTransformer() const
Gets the currently configured MessageTransformer for this Session.
Definition PooledSession.h:231
A pool of CMS sessions from the same connection and with the same acknowledge mode.
Definition SessionPool.h:39
A BytesMessage object is used to send a message containing a stream of unsigned bytes.
Definition BytesMessage.h:66
A Destination object encapsulates a provider-specific address.
Definition Destination.h:39
A MapMessage object is used to send a set of name-value pairs.
Definition MapMessage.h:71
A client uses a MessageConsumer to received messages from a destination.
Definition MessageConsumer.h:63
Root of all messages.
Definition Message.h:88
A client uses a MessageProducer object to send messages to a Destination.
Definition MessageProducer.h:60
Provides an interface for clients to transform cms::Message objects inside the CMS MessageProducer an...
Definition MessageTransformer.h:37
This class implements in interface for browsing the messages in a Queue without removing them.
Definition QueueBrowser.h:53
An interface encapsulating a provider-specific queue name.
Definition Queue.h:37
A Session object is a single-threaded context for producing and consuming messages.
Definition Session.h:105
AcknowledgeMode
Definition Session.h:108
Interface for a StreamMessage.
Definition StreamMessage.h:61
Defines a Temporary Queue based Destination.
Definition TemporaryQueue.h:39
Defines a Temporary Topic based Destination.
Definition TemporaryTopic.h:39
Interface for a text message.
Definition TextMessage.h:41
An interface encapsulating a provider-specific topic name.
Definition Topic.h:36
Map template that wraps around a std::map to provide a more user-friendly interface and to provide co...
Definition StlMap.h:48
Definition CachedConsumer.h:25
Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements.
Definition CachedConsumer.h:24