activemq-cpp-3.4.0

src/main/activemq/cmsutil/PooledSession.h

Go to the documentation of this file.
00001 /*
00002  * Licensed to the Apache Software Foundation (ASF) under one or more
00003  * contributor license agreements.  See the NOTICE file distributed with
00004  * this work for additional information regarding copyright ownership.
00005  * The ASF licenses this file to You under the Apache License, Version 2.0
00006  * (the "License"); you may not use this file except in compliance with
00007  * the License.  You may obtain a copy of the License at
00008  *
00009  *     http://www.apache.org/licenses/LICENSE-2.0
00010  *
00011  * Unless required by applicable law or agreed to in writing, software
00012  * distributed under the License is distributed on an "AS IS" BASIS,
00013  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014  * See the License for the specific language governing permissions and
00015  * limitations under the License.
00016  */
00017 
00018 #ifndef ACTIVEMQ_CMSUTIL_POOLEDSESSION_H_
00019 #define ACTIVEMQ_CMSUTIL_POOLEDSESSION_H_
00020 
00021 #include <cms/Session.h>
00022 #include <decaf/util/StlMap.h>
00023 #include <activemq/cmsutil/CachedProducer.h>
00024 #include <activemq/cmsutil/CachedConsumer.h>
00025 #include <activemq/util/Config.h>
00026 
00027 namespace activemq {
00028 namespace cmsutil {
00029 
00030     // Forward declarations.
00031     class SessionPool;
00032 
00037     class AMQCPP_API PooledSession : public cms::Session {
00038     private:
00039 
00040         SessionPool* pool;
00041 
00042         cms::Session* session;
00043 
00044         decaf::util::StlMap<std::string, CachedProducer*> producerCache;
00045 
00046         decaf::util::StlMap<std::string, CachedConsumer*> consumerCache;
00047 
00048     private:
00049 
00050         PooledSession( const PooledSession& );
00051         PooledSession& operator= ( const PooledSession& );
00052 
00053     public:
00054 
00055         PooledSession( SessionPool* pool, cms::Session* session );
00056 
00060         virtual ~PooledSession() throw();
00061 
00067         virtual cms::Session* getSession() {
00068             return session;
00069         }
00070 
00076         virtual const cms::Session* getSession() const {
00077             return session;
00078         }
00079 
00086         virtual void close();
00087 
00088         virtual void start() {
00089             session->start();
00090         }
00091 
00092         virtual void stop() {
00093             session->stop();
00094         }
00095 
00096         virtual void commit() {
00097             session->commit();
00098         }
00099 
00100         virtual void rollback() {
00101             session->rollback();
00102         }
00103 
00104         virtual void recover() {
00105             session->recover();
00106         }
00107 
00108         virtual cms::MessageConsumer* createConsumer( const cms::Destination* destination ) {
00109             return session->createConsumer(destination);
00110         }
00111 
00112         virtual cms::MessageConsumer* createConsumer( const cms::Destination* destination,
00113                                                       const std::string& selector ) {
00114             return session->createConsumer(destination, selector);
00115         }
00116 
00117         virtual cms::MessageConsumer* createConsumer( const cms::Destination* destination,
00118                                                       const std::string& selector,
00119                                                       bool noLocal ) {
00120             return session->createConsumer(destination, selector, noLocal);
00121         }
00122 
00123         virtual cms::MessageConsumer* createDurableConsumer( const cms::Topic* destination,
00124                                                              const std::string& name,
00125                                                              const std::string& selector,
00126                                                              bool noLocal = false ) {
00127             return session->createDurableConsumer(destination, name, selector, noLocal);
00128         }
00129 
00146         virtual cms::MessageConsumer* createCachedConsumer( const cms::Destination* destination,
00147                                                             const std::string& selector,
00148                                                             bool noLocal );
00149 
00150         virtual cms::MessageProducer* createProducer( const cms::Destination* destination ) {
00151             return session->createProducer(destination);
00152         }
00153 
00166         virtual cms::MessageProducer* createCachedProducer( const cms::Destination* destination );
00167 
00168         virtual cms::QueueBrowser* createBrowser( const cms::Queue* queue );
00169 
00170         virtual cms::QueueBrowser* createBrowser( const cms::Queue* queue, const std::string& selector );
00171 
00172         virtual cms::Queue* createQueue( const std::string& queueName ) {
00173             return session->createQueue( queueName );
00174         }
00175 
00176         virtual cms::Topic* createTopic( const std::string& topicName ) {
00177             return session->createTopic( topicName );
00178         }
00179 
00180         virtual cms::TemporaryQueue* createTemporaryQueue() {
00181             return session->createTemporaryQueue();
00182         }
00183 
00184         virtual cms::TemporaryTopic* createTemporaryTopic() {
00185             return session->createTemporaryTopic();
00186         }
00187 
00188         virtual cms::Message* createMessage() {
00189             return session->createMessage();
00190         }
00191 
00192         virtual cms::BytesMessage* createBytesMessage() {
00193             return session->createBytesMessage();
00194         }
00195 
00196         virtual cms::BytesMessage* createBytesMessage( const unsigned char* bytes, int bytesSize ) {
00197             return session->createBytesMessage( bytes, bytesSize );
00198         }
00199 
00200         virtual cms::StreamMessage* createStreamMessage() {
00201             return session->createStreamMessage();
00202         }
00203 
00204         virtual cms::TextMessage* createTextMessage() {
00205             return session->createTextMessage();
00206         }
00207 
00208         virtual cms::TextMessage* createTextMessage( const std::string& text ) {
00209             return session->createTextMessage( text );
00210         }
00211 
00212         virtual cms::MapMessage* createMapMessage() {
00213             return session->createMapMessage();
00214         }
00215 
00216         virtual cms::Session::AcknowledgeMode getAcknowledgeMode() const {
00217             return session->getAcknowledgeMode();
00218         }
00219 
00220         virtual bool isTransacted() const {
00221             return session->isTransacted();
00222         }
00223 
00224         virtual void unsubscribe( const std::string& name ) {
00225             session->unsubscribe( name );
00226         }
00227 
00228     private:
00229 
00230         std::string getUniqueDestName( const cms::Destination* dest );
00231 
00232     };
00233 
00234 }}
00235 
00236 #endif /*ACTIVEMQ_CMSUTIL_POOLEDSESSION_H_*/