Apache Qpid C++ API
Apache Qpid - AMQP Messaging for Java JMS, C++, Python, Ruby, and .NET Apache Qpid Documentation

qpid/client/SubscriptionManager.h

Go to the documentation of this file.
00001 #ifndef QPID_CLIENT_SUBSCRIPTIONMANAGER_H
00002 #define QPID_CLIENT_SUBSCRIPTIONMANAGER_H
00003 
00004 /*
00005  *
00006  * Licensed to the Apache Software Foundation (ASF) under one
00007  * or more contributor license agreements.  See the NOTICE file
00008  * distributed with this work for additional information
00009  * regarding copyright ownership.  The ASF licenses this file
00010  * to you under the Apache License, Version 2.0 (the
00011  * "License"); you may not use this file except in compliance
00012  * with the License.  You may obtain a copy of the License at
00013  * 
00014  *   http://www.apache.org/licenses/LICENSE-2.0
00015  * 
00016  * Unless required by applicable law or agreed to in writing,
00017  * software distributed under the License is distributed on an
00018  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
00019  * KIND, either express or implied.  See the License for the
00020  * specific language governing permissions and limitations
00021  * under the License.
00022  *
00023  */
00024 #include "qpid/sys/Mutex.h"
00025 #include <qpid/client/Dispatcher.h>
00026 #include <qpid/client/Completion.h>
00027 #include <qpid/client/Session.h>
00028 #include <qpid/client/AsyncSession.h>
00029 #include <qpid/client/MessageListener.h>
00030 #include <qpid/client/LocalQueue.h>
00031 #include <qpid/client/Subscription.h>
00032 #include <qpid/sys/Runnable.h>
00033 #include <set>
00034 #include <sstream>
00035 
00036 namespace qpid {
00037 namespace client {
00038 
00096 class SubscriptionManager : public sys::Runnable
00097 {
00098   public:
00100     SubscriptionManager(const Session& session);
00101     
00113     Subscription subscribe(MessageListener& listener,
00114                            const std::string& queue,
00115                            const SubscriptionSettings& settings,
00116                            const std::string& name=std::string());
00117 
00128     Subscription subscribe(LocalQueue& localQueue,
00129                            const std::string& queue,
00130                            const SubscriptionSettings& settings,
00131                            const std::string& name=std::string());
00132 
00144     Subscription subscribe(MessageListener& listener,
00145                            const std::string& queue,
00146                            const std::string& name=std::string());
00147 
00157     Subscription subscribe(LocalQueue& localQueue,
00158                            const std::string& queue,
00159                            const std::string& name=std::string());
00160 
00161 
00167     bool get(Message& result, const std::string& queue, sys::Duration timeout=0);
00168 
00174     Message get(const std::string& queue, sys::Duration timeout=sys::TIME_INFINITE);
00175 
00179     Subscription getSubscription(const std::string& name) const;
00180     
00182     void cancel(const std::string& name);
00183 
00188     void run();
00189 
00194     void start();
00195 
00199     void wait();
00200     
00205     void setAutoStop(bool set=true);
00206 
00208     void stop();
00209 
00210     static const uint32_t UNLIMITED=0xFFFFFFFF;
00211 
00213     void setFlowControl(const std::string& name, const FlowControl& flow);
00214 
00221     void setFlowControl(const std::string& name, uint32_t messages,  uint32_t bytes, bool window=true);
00222 
00226     void setDefaultSettings(const SubscriptionSettings& s) { defaultSettings = s; }
00227 
00231     const SubscriptionSettings& getDefaultSettings() const { return defaultSettings; }
00232 
00236     SubscriptionSettings& getDefaultSettings() { return defaultSettings; }
00237 
00246     void setFlowControl(uint32_t messages,  uint32_t bytes, bool window=true) {
00247         defaultSettings.flowControl = FlowControl(messages, bytes, window);
00248     }
00249 
00254     void setAcceptMode(AcceptMode mode) { defaultSettings.acceptMode = mode; }
00255 
00259     void setAcquireMode(AcquireMode mode) { defaultSettings.acquireMode = mode; }
00260 
00261     void registerFailoverHandler ( boost::function<void ()> fh );
00262 
00263     Session getSession() const;
00264 
00265   private:
00266     mutable sys::Mutex lock;
00267     qpid::client::Dispatcher dispatcher;
00268     qpid::client::AsyncSession session;
00269     bool autoStop;
00270     SubscriptionSettings defaultSettings;
00271     std::map<std::string, Subscription> subscriptions;
00272 };
00273 
00275 class AutoCancel {
00276   public:
00277     AutoCancel(SubscriptionManager& sm_, const std::string& tag_) : sm(sm_), tag(tag_) {}
00278     ~AutoCancel() { sm.cancel(tag); }
00279   private:
00280     SubscriptionManager& sm;
00281     std::string tag;
00282 };
00283 
00284 }} // namespace qpid::client
00285 
00286 #endif  

Qpid C++ API Reference
Generated on Tue Dec 8 15:39:36 2009 for Qpid C++ Client API by doxygen 1.4.7