00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <map>
00022 #include <string>
00023 #include <queue>
00024 #include "sys/types.h"
00025
00026 #ifndef _Channel_
00027 #define _Channel_
00028
00029 #include <framing/amqp_framing.h>
00030 #include <Connection.h>
00031 #include <ClientExchange.h>
00032 #include <IncomingMessage.h>
00033 #include <ClientMessage.h>
00034 #include <MessageListener.h>
00035 #include <ClientQueue.h>
00036 #include <ResponseHandler.h>
00037 #include <ReturnedMessageHandler.h>
00038
00039 namespace qpid {
00040 namespace client {
00046 enum ack_modes {
00050 NO_ACK = 0,
00054 AUTO_ACK = 1,
00057 LAZY_ACK = 2,
00060 CLIENT_ACK = 3
00061 };
00062
00070 class Channel : private virtual qpid::framing::BodyHandler, public virtual qpid::sys::Runnable{
00071 struct Consumer{
00072 MessageListener* listener;
00073 int ackMode;
00074 int count;
00075 u_int64_t lastDeliveryTag;
00076 };
00077 typedef std::map<std::string,Consumer*>::iterator consumer_iterator;
00078
00079 u_int16_t id;
00080 Connection* con;
00081 qpid::sys::Thread dispatcher;
00082 qpid::framing::OutputHandler* out;
00083 IncomingMessage* incoming;
00084 ResponseHandler responses;
00085 std::queue<IncomingMessage*> messages;
00086 IncomingMessage* retrieved;
00087 qpid::sys::Monitor dispatchMonitor;
00088 qpid::sys::Monitor retrievalMonitor;
00089 std::map<std::string, Consumer*> consumers;
00090 ReturnedMessageHandler* returnsHandler;
00091 bool closed;
00092
00093 u_int16_t prefetch;
00094 const bool transactional;
00095 qpid::framing::ProtocolVersion version;
00096
00097 void enqueue();
00098 void retrieve(Message& msg);
00099 IncomingMessage* dequeue();
00100 void dispatch();
00101 void stop();
00102 void sendAndReceive(qpid::framing::AMQFrame* frame, const qpid::framing::AMQMethodBody& body);
00103 void deliver(Consumer* consumer, Message& msg);
00104 void setQos();
00105 void cancelAll();
00106
00107 virtual void handleMethod(qpid::framing::AMQMethodBody::shared_ptr body);
00108 virtual void handleHeader(qpid::framing::AMQHeaderBody::shared_ptr body);
00109 virtual void handleContent(qpid::framing::AMQContentBody::shared_ptr body);
00110 virtual void handleHeartbeat(qpid::framing::AMQHeartbeatBody::shared_ptr body);
00111
00112 public:
00124 Channel(bool transactional = false, u_int16_t prefetch = 500);
00125 ~Channel();
00126
00141 void declareExchange(Exchange& exchange, bool synch = true);
00150 void deleteExchange(Exchange& exchange, bool synch = true);
00159 void declareQueue(Queue& queue, bool synch = true);
00168 void deleteQueue(Queue& queue, bool ifunused = false, bool ifempty = false, bool synch = true);
00187 void bind(const Exchange& exchange, const Queue& queue, const std::string& key,
00188 const qpid::framing::FieldTable& args, bool synch = true);
00216 void consume(
00217 Queue& queue, std::string& tag, MessageListener* listener,
00218 int ackMode = NO_ACK, bool noLocal = false, bool synch = true,
00219 const qpid::framing::FieldTable* fields = 0);
00220
00230 void cancel(std::string& tag, bool synch = true);
00245 bool get(Message& msg, const Queue& queue, int ackMode = NO_ACK);
00263 void publish(Message& msg, const Exchange& exchange, const std::string& routingKey,
00264 bool mandatory = false, bool immediate = false);
00265
00278 void commit();
00285 void rollback();
00286
00290 void setPrefetch(u_int16_t prefetch);
00291
00295 void start();
00299 void run();
00300
00304 void close();
00305
00312 void setReturnedMessageHandler(ReturnedMessageHandler* handler);
00313
00314 friend class Connection;
00315 };
00316
00317 }
00318 }
00319
00320
00321 #endif