00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef _Dispatcher_
00022 #define _Dispatcher_
00023
00024 #include <map>
00025 #include <memory>
00026 #include <string>
00027 #include <boost/shared_ptr.hpp>
00028 #include "qpid/client/Session.h"
00029 #include "qpid/client/SessionBase_0_10Access.h"
00030 #include "qpid/sys/Mutex.h"
00031 #include "qpid/sys/Runnable.h"
00032 #include "qpid/sys/Thread.h"
00033 #include "ClientImportExport.h"
00034 #include "MessageListener.h"
00035 #include "SubscriptionImpl.h"
00036
00037 namespace qpid {
00038 namespace client {
00039
00040 class SubscriptionImpl;
00041
00043 typedef framing::Handler<framing::FrameSet> FrameSetHandler;
00044
00046 class Dispatcher : public sys::Runnable
00047 {
00048 typedef std::map<std::string, boost::intrusive_ptr<SubscriptionImpl> >Listeners;
00049 sys::Mutex lock;
00050 sys::Thread worker;
00051 Session session;
00052 Demux::QueuePtr queue;
00053 bool running;
00054 bool autoStop;
00055 Listeners listeners;
00056 boost::intrusive_ptr<SubscriptionImpl> defaultListener;
00057 std::auto_ptr<FrameSetHandler> handler;
00058
00059 boost::intrusive_ptr<SubscriptionImpl> find(const std::string& name);
00060 bool isStopped();
00061
00062 boost::function<void ()> failoverHandler;
00063
00064 public:
00065 Dispatcher(const Session& session, const std::string& queue = "");
00066 ~Dispatcher() {}
00067
00068 void start();
00069 void wait();
00070
00071
00072 QPID_CLIENT_EXTERN void run();
00073 void stop();
00074 void setAutoStop(bool b);
00075
00076 void registerFailoverHandler ( boost::function<void ()> fh )
00077 {
00078 failoverHandler = fh;
00079 }
00080
00081 void listen(const boost::intrusive_ptr<SubscriptionImpl>& subscription);
00082 void cancel(const std::string& destination);
00083 };
00084
00085 }}
00086
00087 #endif