00001 #ifndef QPID_BROKER_SEMANTICSTATE_H
00002 #define QPID_BROKER_SEMANTICSTATE_H
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include "Consumer.h"
00026 #include "Deliverable.h"
00027 #include "DeliveryAdapter.h"
00028 #include "DeliveryRecord.h"
00029 #include "DeliveryToken.h"
00030 #include "DtxBuffer.h"
00031 #include "DtxManager.h"
00032 #include "NameGenerator.h"
00033 #include "Prefetch.h"
00034 #include "TxBuffer.h"
00035
00036 #include "qpid/framing/FrameHandler.h"
00037 #include "qpid/framing/SequenceSet.h"
00038 #include "qpid/framing/Uuid.h"
00039 #include "qpid/sys/AggregateOutput.h"
00040 #include "qpid/shared_ptr.h"
00041 #include "AclModule.h"
00042
00043 #include <list>
00044 #include <map>
00045 #include <vector>
00046
00047 #include <boost/intrusive_ptr.hpp>
00048
00049 namespace qpid {
00050 namespace broker {
00051
00052 class SessionContext;
00053
00058 class SemanticState : public sys::OutputTask,
00059 private boost::noncopyable
00060 {
00061 class ConsumerImpl : public Consumer, public sys::OutputTask
00062 {
00063 SemanticState* const parent;
00064 const DeliveryToken::shared_ptr token;
00065 const string name;
00066 const Queue::shared_ptr queue;
00067 const bool ackExpected;
00068 const bool nolocal;
00069 const bool acquire;
00070 bool blocked;
00071 bool windowing;
00072 uint32_t msgCredit;
00073 uint32_t byteCredit;
00074
00075 bool checkCredit(boost::intrusive_ptr<Message>& msg);
00076 void allocateCredit(boost::intrusive_ptr<Message>& msg);
00077
00078 public:
00079 ConsumerImpl(SemanticState* parent, DeliveryToken::shared_ptr token,
00080 const string& name, Queue::shared_ptr queue,
00081 bool ack, bool nolocal, bool acquire);
00082 ~ConsumerImpl();
00083 OwnershipToken* getSession();
00084 bool deliver(QueuedMessage& msg);
00085 bool filter(boost::intrusive_ptr<Message> msg);
00086 bool accept(boost::intrusive_ptr<Message> msg);
00087 void notify();
00088
00089 void setWindowMode();
00090 void setCreditMode();
00091 void addByteCredit(uint32_t value);
00092 void addMessageCredit(uint32_t value);
00093 void flush();
00094 void stop();
00095 void complete(DeliveryRecord&);
00096 Queue::shared_ptr getQueue() { return queue; }
00097 bool isBlocked() const { return blocked; }
00098
00099 bool hasOutput();
00100 bool doOutput();
00101 };
00102
00103 typedef boost::ptr_map<std::string,ConsumerImpl> ConsumerImplMap;
00104 typedef std::map<std::string, DtxBuffer::shared_ptr> DtxBufferMap;
00105
00106 SessionContext& session;
00107 DeliveryAdapter& deliveryAdapter;
00108 Queue::shared_ptr defaultQueue;
00109 ConsumerImplMap consumers;
00110 uint32_t prefetchSize;
00111 uint16_t prefetchCount;
00112 Prefetch outstanding;
00113 NameGenerator tagGenerator;
00114 std::list<DeliveryRecord> unacked;
00115 TxBuffer::shared_ptr txBuffer;
00116 DtxBuffer::shared_ptr dtxBuffer;
00117 bool dtxSelected;
00118 DtxBufferMap suspendedXids;
00119 framing::SequenceSet accumulatedAck;
00120 boost::shared_ptr<Exchange> cacheExchange;
00121 sys::AggregateOutput outputTasks;
00122 AclModule* acl;
00123
00124 void route(boost::intrusive_ptr<Message> msg, Deliverable& strategy);
00125 void record(const DeliveryRecord& delivery);
00126 bool checkPrefetch(boost::intrusive_ptr<Message>& msg);
00127 void checkDtxTimeout();
00128 ConsumerImpl& find(const std::string& destination);
00129 void complete(DeliveryRecord&);
00130 AckRange findRange(DeliveryId first, DeliveryId last);
00131 void requestDispatch();
00132 void requestDispatch(ConsumerImpl&);
00133 void cancel(ConsumerImpl&);
00134
00135 public:
00136 SemanticState(DeliveryAdapter&, SessionContext&);
00137 ~SemanticState();
00138
00139 SessionContext& getSession() { return session; }
00140
00147 Queue::shared_ptr getQueue(const std::string& name) const;
00148
00149 uint32_t setPrefetchSize(uint32_t size){ return prefetchSize = size; }
00150 uint16_t setPrefetchCount(uint16_t n){ return prefetchCount = n; }
00151
00152 bool exists(const string& consumerTag);
00153
00157 void consume(DeliveryToken::shared_ptr token, string& tagInOut, Queue::shared_ptr queue,
00158 bool nolocal, bool ackRequired, bool acquire, bool exclusive, const framing::FieldTable* = 0);
00159
00160 void cancel(const string& tag);
00161
00162 void setWindowMode(const std::string& destination);
00163 void setCreditMode(const std::string& destination);
00164 void addByteCredit(const std::string& destination, uint32_t value);
00165 void addMessageCredit(const std::string& destination, uint32_t value);
00166 void flush(const std::string& destination);
00167 void stop(const std::string& destination);
00168
00169 bool get(DeliveryToken::shared_ptr token, Queue::shared_ptr queue, bool ackExpected);
00170 void startTx();
00171 void commit(MessageStore* const store);
00172 void rollback();
00173 void selectDtx();
00174 void startDtx(const std::string& xid, DtxManager& mgr, bool join);
00175 void endDtx(const std::string& xid, bool fail);
00176 void suspendDtx(const std::string& xid);
00177 void resumeDtx(const std::string& xid);
00178 void recover(bool requeue);
00179 DeliveryId redeliver(QueuedMessage& msg, DeliveryToken::shared_ptr token);
00180 void acquire(DeliveryId first, DeliveryId last, DeliveryIds& acquired);
00181 void release(DeliveryId first, DeliveryId last, bool setRedelivered);
00182 void reject(DeliveryId first, DeliveryId last);
00183 void handle(boost::intrusive_ptr<Message> msg);
00184 bool hasOutput() { return outputTasks.hasOutput(); }
00185 bool doOutput() { return outputTasks.doOutput(); }
00186
00187
00188 void completed(DeliveryId deliveryTag, DeliveryId endTag);
00189 void accepted(DeliveryId deliveryTag, DeliveryId endTag);
00190 };
00191
00192 }}
00193
00194
00195
00196
00197 #endif