activemq-cpp-3.3.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 commit() {
00089             session->commit();
00090         }
00091 
00092         virtual void rollback() {
00093             session->rollback();
00094         }
00095 
00096         virtual void recover() {
00097             session->recover();
00098         }
00099 
00100         virtual cms::MessageConsumer* createConsumer( const cms::Destination* destination ) {
00101             return session->createConsumer(destination);
00102         }
00103 
00104         virtual cms::MessageConsumer* createConsumer( const cms::Destination* destination,
00105                                                       const std::string& selector ) {
00106             return session->createConsumer(destination, selector);
00107         }
00108 
00109         virtual cms::MessageConsumer* createConsumer( const cms::Destination* destination,
00110                                                       const std::string& selector,
00111                                                       bool noLocal ) {
00112             return session->createConsumer(destination, selector, noLocal);
00113         }
00114 
00115         virtual cms::MessageConsumer* createDurableConsumer( const cms::Topic* destination,
00116                                                              const std::string& name,
00117                                                              const std::string& selector,
00118                                                              bool noLocal = false ) {
00119             return session->createDurableConsumer(destination, name, selector, noLocal);
00120         }
00121 
00138         virtual cms::MessageConsumer* createCachedConsumer( const cms::Destination* destination,
00139                                                             const std::string& selector,
00140                                                             bool noLocal );
00141 
00142         virtual cms::MessageProducer* createProducer( const cms::Destination* destination ) {
00143             return session->createProducer(destination);
00144         }
00145 
00158         virtual cms::MessageProducer* createCachedProducer( const cms::Destination* destination );
00159 
00160         virtual cms::QueueBrowser* createBrowser( const cms::Queue* queue );
00161 
00162         virtual cms::QueueBrowser* createBrowser( const cms::Queue* queue, const std::string& selector );
00163 
00164         virtual cms::Queue* createQueue( const std::string& queueName ) {
00165             return session->createQueue( queueName );
00166         }
00167 
00168         virtual cms::Topic* createTopic( const std::string& topicName ) {
00169             return session->createTopic( topicName );
00170         }
00171 
00172         virtual cms::TemporaryQueue* createTemporaryQueue() {
00173             return session->createTemporaryQueue();
00174         }
00175 
00176         virtual cms::TemporaryTopic* createTemporaryTopic() {
00177             return session->createTemporaryTopic();
00178         }
00179 
00180         virtual cms::Message* createMessage() {
00181             return session->createMessage();
00182         }
00183 
00184         virtual cms::BytesMessage* createBytesMessage() {
00185             return session->createBytesMessage();
00186         }
00187 
00188         virtual cms::BytesMessage* createBytesMessage( const unsigned char* bytes, int bytesSize ) {
00189             return session->createBytesMessage( bytes, bytesSize );
00190         }
00191 
00192         virtual cms::StreamMessage* createStreamMessage() {
00193             return session->createStreamMessage();
00194         }
00195 
00196         virtual cms::TextMessage* createTextMessage() {
00197             return session->createTextMessage();
00198         }
00199 
00200         virtual cms::TextMessage* createTextMessage( const std::string& text ) {
00201             return session->createTextMessage( text );
00202         }
00203 
00204         virtual cms::MapMessage* createMapMessage() {
00205             return session->createMapMessage();
00206         }
00207 
00208         virtual cms::Session::AcknowledgeMode getAcknowledgeMode() const {
00209             return session->getAcknowledgeMode();
00210         }
00211 
00212         virtual bool isTransacted() const {
00213             return session->isTransacted();
00214         }
00215 
00216         virtual void unsubscribe( const std::string& name ) {
00217             session->unsubscribe( name );
00218         }
00219 
00220     private:
00221 
00222         std::string getUniqueDestName( const cms::Destination* dest );
00223 
00224     };
00225 
00226 }}
00227 
00228 #endif /*ACTIVEMQ_CMSUTIL_POOLEDSESSION_H_*/