activemq-cpp-3.8.2
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>
25 #include <activemq/util/Config.h>
26 
27 namespace activemq {
28 namespace cmsutil {
29 
30  // Forward declarations.
31  class SessionPool;
32 
38  private:
39 
40  SessionPool* pool;
41 
42  cms::Session* session;
43 
45 
47 
48  private:
49 
51  PooledSession& operator=(const PooledSession&);
52 
53  public:
54 
55  PooledSession(SessionPool* pool, cms::Session* session);
56 
60  virtual ~PooledSession();
61 
67  virtual cms::Session* getSession() {
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 
108  virtual cms::MessageConsumer* createConsumer(const cms::Destination* destination) {
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 
146  virtual cms::MessageConsumer* createCachedConsumer(const cms::Destination* destination,
147  const std::string& selector, bool noLocal);
148 
149  virtual cms::MessageProducer* createProducer(const cms::Destination* destination) {
150  return session->createProducer(destination);
151  }
152 
165  virtual cms::MessageProducer* createCachedProducer(const cms::Destination* destination);
166 
167  virtual cms::QueueBrowser* createBrowser(const cms::Queue* queue);
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 
227  virtual void setMessageTransformer(cms::MessageTransformer* transformer) {
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_*/
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::Topic * createTopic(const std::string &topicName)
Creates a topic identity given a Queue name.
Definition: PooledSession.h:175
virtual void recover()
Stops message delivery in this session, and restarts message delivery with the oldest unacknowledged ...
Definition: PooledSession.h:104
An interface encapsulating a provider-specific topic name.
Definition: Topic.h:36
Provides an interface for clients to transform cms::Message objects inside the CMS MessageProducer an...
Definition: MessageTransformer.h:37
virtual cms::TemporaryQueue * createTemporaryQueue()
Creates a TemporaryQueue object.
Definition: PooledSession.h:179
virtual void unsubscribe(const std::string &name)=0
Unsubscribes a durable subscription that has been created by a client.
virtual cms::MessageConsumer * createConsumer(const cms::Destination *destination)
Creates a MessageConsumer for the specified destination.
Definition: PooledSession.h:108
virtual void commit()
Commits all messages done in this transaction and releases any locks currently held.
Definition: PooledSession.h:96
virtual TemporaryTopic * createTemporaryTopic()=0
Creates a TemporaryTopic object.
virtual bool isTransacted() const =0
Gets if the Sessions is a Transacted Session.
Root of all messages.
Definition: Message.h:88
Defines a Temporary Topic based Destination.
Definition: TemporaryTopic.h:39
A Destination object encapsulates a provider-specific address.
Definition: Destination.h:39
#define AMQCPP_API
Definition: Config.h:30
virtual cms::MessageProducer * createProducer(const cms::Destination *destination)
Creates a MessageProducer to send messages to the specified destination.
Definition: PooledSession.h:149
virtual void commit()=0
Commits all messages done in this transaction and releases any locks currently held.
AcknowledgeMode
Definition: Session.h:108
virtual void start()=0
Starts the service.
Map template that wraps around a std::map to provide a more user-friendly interface and to provide co...
Definition: StlMap.h:47
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
This class implements in interface for browsing the messages in a Queue without removing them...
Definition: QueueBrowser.h:53
virtual TemporaryQueue * createTemporaryQueue()=0
Creates a TemporaryQueue object.
virtual cms::BytesMessage * createBytesMessage()
Creates a BytesMessage.
Definition: PooledSession.h:191
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 StreamMessage * createStreamMessage()=0
Creates a new StreamMessage.
virtual MapMessage * createMapMessage()=0
Creates a new MapMessage.
virtual cms::Session::AcknowledgeMode getAcknowledgeMode() const
Returns the acknowledgment mode of the session.
Definition: PooledSession.h:215
A BytesMessage object is used to send a message containing a stream of unsigned bytes.
Definition: BytesMessage.h:66
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 cms::Message * createMessage()
Creates a new Message.
Definition: PooledSession.h:187
virtual BytesMessage * createBytesMessage()=0
Creates a BytesMessage.
A pool of CMS sessions from the same connection and with the same acknowledge mode.
Definition: SessionPool.h:39
Defines a Temporary Queue based Destination.
Definition: TemporaryQueue.h:39
virtual cms::MessageTransformer * getMessageTransformer() const
Gets the currently configured MessageTransformer for this Session.
Definition: PooledSession.h:231
virtual void setMessageTransformer(cms::MessageTransformer *transformer)=0
Set an MessageTransformer instance that is passed on to all MessageProducer and MessageConsumer objec...
virtual cms::TextMessage * createTextMessage()
Creates a new TextMessage.
Definition: PooledSession.h:203
A Session object is a single-threaded context for producing and consuming messages.
Definition: Session.h:105
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
A MapMessage object is used to send a set of name-value pairs.
Definition: MapMessage.h:71
virtual void rollback()=0
Rolls back all messages done in this transaction and releases any locks currently held...
virtual void unsubscribe(const std::string &name)
Unsubscribes a durable subscription that has been created by a client.
Definition: PooledSession.h:223
virtual void recover()=0
Stops message delivery in this session, and restarts message delivery with the oldest unacknowledged ...
Interface for a StreamMessage.
Definition: StreamMessage.h:61
virtual cms::TemporaryTopic * createTemporaryTopic()
Creates a TemporaryTopic object.
Definition: PooledSession.h:183
virtual cms::MapMessage * createMapMessage()
Creates a new MapMessage.
Definition: PooledSession.h:211
virtual void stop()=0
Stops this service.
A client uses a MessageProducer object to send messages to a Destination.
Definition: MessageProducer.h:60
virtual Message * createMessage()=0
Creates a new Message.
virtual TextMessage * createTextMessage()=0
Creates a new TextMessage.
virtual AcknowledgeMode getAcknowledgeMode() const =0
Returns the acknowledgment mode of the session.
A client uses a MessageConsumer to received messages from a destination.
Definition: MessageConsumer.h:63
Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements...
Definition: CachedConsumer.h:24
virtual bool isTransacted() const
Gets if the Sessions is a Transacted Session.
Definition: PooledSession.h:219
virtual cms::Session * getSession()
Returns a non-constant reference to the internal session object.
Definition: PooledSession.h:67
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::StreamMessage * createStreamMessage()
Creates a new StreamMessage.
Definition: PooledSession.h:199
virtual const cms::Session * getSession() const
Returns a constant reference to the internal session object.
Definition: PooledSession.h:76
virtual MessageConsumer * createConsumer(const Destination *destination)=0
Creates a MessageConsumer for the specified destination.
virtual void start()
Starts the service.
Definition: PooledSession.h:88
virtual cms::MessageTransformer * getMessageTransformer() const =0
Gets the currently configured MessageTransformer for this Session.
virtual MessageProducer * createProducer(const Destination *destination=NULL)=0
Creates a MessageProducer to send messages to the specified destination.
virtual void stop()
Stops this service.
Definition: PooledSession.h:92
A pooled session object that wraps around a delegate session.
Definition: PooledSession.h:37
Interface for a text message.
Definition: TextMessage.h:41
virtual void rollback()
Rolls back all messages done in this transaction and releases any locks currently held...
Definition: PooledSession.h:100
virtual Topic * createTopic(const std::string &topicName)=0
Creates a topic identity given a Queue name.
virtual cms::Queue * createQueue(const std::string &queueName)
Creates a queue identity given a Queue name.
Definition: PooledSession.h:171
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 Queue * createQueue(const std::string &queueName)=0
Creates a queue identity given a Queue name.
An interface encapsulating a provider-specific queue name.
Definition: Queue.h:37