/opt/workspace/qpid/tags/M2/Final/cpp/lib/client/ClientChannel.h

00001 /*
00002  *
00003  * Licensed to the Apache Software Foundation (ASF) under one
00004  * or more contributor license agreements.  See the NOTICE file
00005  * distributed with this work for additional information
00006  * regarding copyright ownership.  The ASF licenses this file
00007  * to you under the Apache License, Version 2.0 (the
00008  * "License"); you may not use this file except in compliance
00009  * with the License.  You may obtain a copy of the License at
00010  * 
00011  *   http://www.apache.org/licenses/LICENSE-2.0
00012  * 
00013  * Unless required by applicable law or agreed to in writing,
00014  * software distributed under the License is distributed on an
00015  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
00016  * KIND, either express or implied.  See the License for the
00017  * specific language governing permissions and limitations
00018  * under the License.
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;//holds returned messages or those delivered for a consume
00086         IncomingMessage* retrieved;//holds response to basic.get
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

Generated on Mon Nov 26 19:13:17 2007 for Qpid by  doxygen 1.5.1