/usr/share/cruisecontrol-bin-2.6.1/projects/qpid-trunk/cpp/src/qpid/broker/SessionState.h

00001 #ifndef QPID_BROKER_SESSION_H
00002 #define QPID_BROKER_SESSION_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 
00025 #include "qpid/framing/Uuid.h"
00026 #include "qpid/framing/FrameHandler.h"
00027 #include "qpid/framing/SessionState.h"
00028 #include "qpid/framing/SequenceSet.h"
00029 #include "qpid/framing/ProtocolVersion.h"
00030 #include "qpid/sys/Mutex.h"
00031 #include "qpid/sys/Time.h"
00032 #include "qpid/management/Manageable.h"
00033 #include "qpid/management/Session.h"
00034 #include "SessionAdapter.h"
00035 #include "DeliveryAdapter.h"
00036 #include "IncompleteMessageList.h"
00037 #include "MessageBuilder.h"
00038 #include "SessionContext.h"
00039 #include "SemanticState.h"
00040 
00041 #include <boost/noncopyable.hpp>
00042 #include <boost/scoped_ptr.hpp>
00043 
00044 #include <set>
00045 #include <vector>
00046 #include <ostream>
00047 
00048 namespace qpid {
00049 
00050 namespace framing {
00051 class AMQP_ClientProxy;
00052 }
00053 
00054 namespace broker {
00055 
00056 class Broker;
00057 class ConnectionState;
00058 class Message;
00059 class SessionHandler;
00060 class SessionManager;
00061 
00066 class SessionState : public framing::SessionState,
00067     public SessionContext,
00068     public DeliveryAdapter,
00069     public management::Manageable
00070 {
00071   public:
00072     ~SessionState();
00073     bool isAttached() const { return handler; }
00074 
00075     void detach();
00076     void attach(SessionHandler& handler);
00077 
00078     
00079     SessionHandler* getHandler();
00080 
00082     framing::AMQP_ClientProxy& getProxy();
00083     
00085     ConnectionState& getConnection();
00086     bool isLocal(const ConnectionToken* t) const;
00087 
00088     uint32_t getTimeout() const { return timeout; }
00089     void setTimeout(uint32_t t) { timeout = t; }
00090 
00091     Broker& getBroker() { return broker; }
00092     framing::ProtocolVersion getVersion() const { return version; }
00093 
00095     void activateOutput();
00096 
00097     void handle(framing::AMQFrame& frame);
00098 
00099     void complete(const framing::SequenceSet& ranges);    
00100     void sendCompletion();
00101 
00102     //delivery adapter methods:
00103     DeliveryId deliver(QueuedMessage& msg, DeliveryToken::shared_ptr token);
00104 
00105     // Manageable entry points
00106     management::ManagementObject::shared_ptr GetManagementObject (void) const;
00107     management::Manageable::status_t
00108         ManagementMethod (uint32_t methodId, management::Args& args);
00109 
00110     // Normally SessionManager creates sessions.
00111     SessionState(SessionManager*,
00112                  SessionHandler* out,
00113                  uint32_t timeout,
00114                  uint32_t ackInterval);
00115     
00116 
00117     framing::SequenceSet completed;
00118     framing::SequenceSet knownCompleted;
00119     framing::SequenceNumber nextIn;
00120     framing::SequenceNumber nextOut;
00121 
00122   private:
00123     typedef boost::function<void(DeliveryId, DeliveryId)> RangedOperation;    
00124 
00125     SessionManager* factory;
00126     SessionHandler* handler;    
00127     framing::Uuid id;
00128     uint32_t timeout;
00129     sys::AbsTime expiry;        // Used by SessionManager.
00130     Broker& broker;
00131     framing::ProtocolVersion version;
00132     sys::Mutex lock;
00133 
00134     SemanticState semanticState;
00135     SessionAdapter adapter;
00136     MessageBuilder msgBuilder;
00137     IncompleteMessageList incomplete;
00138 
00139     RangedOperation ackOp;
00140     IncompleteMessageList::CompletionListener enqueuedOp;
00141 
00142     management::Session::shared_ptr mgmtObject;
00143     void handleCommand(framing::AMQMethodBody* method, framing::SequenceNumber& id);
00144     void handleContent(framing::AMQFrame& frame, framing::SequenceNumber& id);
00145     void enqueued(boost::intrusive_ptr<Message> msg);
00146 
00147     friend class SessionManager;
00148 };
00149 
00150 
00151 inline std::ostream& operator<<(std::ostream& out, const SessionState& session) {
00152     return out << session.getId();
00153 }
00154 
00155 }} // namespace qpid::broker
00156 
00157 
00158 
00159 #endif  

Generated on Thu Apr 10 11:08:17 2008 for Qpid by  doxygen 1.4.7