00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef _SessionImpl_
00023 #define _SessionImpl_
00024
00025 #include "Demux.h"
00026 #include "Execution.h"
00027 #include "Results.h"
00028
00029 #include "qpid/SessionId.h"
00030 #include "qpid/shared_ptr.h"
00031 #include "qpid/framing/FrameHandler.h"
00032 #include "qpid/framing/ChannelHandler.h"
00033 #include "qpid/framing/SequenceNumber.h"
00034 #include "qpid/framing/AMQP_ClientOperations.h"
00035 #include "qpid/framing/AMQP_ServerProxy.h"
00036 #include "qpid/sys/Semaphore.h"
00037 #include "qpid/sys/StateMonitor.h"
00038
00039 #include <boost/optional.hpp>
00040
00041 namespace qpid {
00042
00043 namespace framing {
00044
00045 class FrameSet;
00046 class MethodContent;
00047 class SequenceSet;
00048
00049 }
00050
00051 namespace client {
00052
00053 class Future;
00054 class ConnectionImpl;
00055
00057 class SessionImpl : public framing::FrameHandler::InOutHandler,
00058 public Execution,
00059 private framing::AMQP_ClientOperations::SessionHandler,
00060 private framing::AMQP_ClientOperations::ExecutionHandler
00061 {
00062 public:
00063 SessionImpl(const std::string& name, shared_ptr<ConnectionImpl>, uint16_t channel, uint64_t maxFrameSize);
00064 ~SessionImpl();
00065
00066
00067
00068 framing::FrameSet::shared_ptr get();
00069
00070 const SessionId getId() const;
00071
00072 uint16_t getChannel() const;
00073 void setChannel(uint16_t channel);
00074
00075 void open(uint32_t detachedLifetime);
00076 void close();
00077 void resume(shared_ptr<ConnectionImpl>);
00078 void suspend();
00079
00080 void assertOpen() const;
00081
00082 Future send(const framing::AMQBody& command);
00083 Future send(const framing::AMQBody& command, const framing::MethodContent& content);
00084
00085 Demux& getDemux();
00086 void markCompleted(const framing::SequenceNumber& id, bool cumulative, bool notifyPeer);
00087 bool isComplete(const framing::SequenceNumber& id);
00088 bool isCompleteUpTo(const framing::SequenceNumber& id);
00089 void waitForCompletion(const framing::SequenceNumber& id);
00090 void sendCompletion();
00091 void sendFlush();
00092
00093
00094 void connectionClosed(uint16_t code, const std::string& text);
00095 void connectionBroke(uint16_t code, const std::string& text);
00096
00097 private:
00098 enum ErrorType {
00099 OK,
00100 CONNECTION_CLOSE,
00101 SESSION_DETACH,
00102 EXCEPTION
00103 };
00104 enum State {
00105 INACTIVE,
00106 ATTACHING,
00107 ATTACHED,
00108 DETACHING,
00109 DETACHED
00110 };
00111 typedef framing::AMQP_ClientOperations::SessionHandler SessionHandler;
00112 typedef framing::AMQP_ClientOperations::ExecutionHandler ExecutionHandler;
00113 typedef sys::StateMonitor<State, DETACHED> StateMonitor;
00114 typedef StateMonitor::Set States;
00115
00116 inline void setState(State s);
00117 inline void waitFor(State);
00118
00119 void detach();
00120
00121 void check() const;
00122 void checkOpen() const;
00123 void handleClosed();
00124
00125 void handleIn(framing::AMQFrame& frame);
00126 void handleOut(framing::AMQFrame& frame);
00127 void proxyOut(framing::AMQFrame& frame);
00128 void deliver(framing::AMQFrame& frame);
00129
00130 Future sendCommand(const framing::AMQBody&, const framing::MethodContent* = 0);
00131 void sendContent(const framing::MethodContent&);
00132 void waitForCompletionImpl(const framing::SequenceNumber& id);
00133 void requestTimeout(uint32_t timeout);
00134
00135 void sendCompletionImpl();
00136
00137
00138
00139 void attach(const std::string& name, bool force);
00140 void attached(const std::string& name);
00141 void detach(const std::string& name);
00142 void detached(const std::string& name, uint8_t detachCode);
00143 void timeout(uint32_t timeout);
00144 void commandPoint(const framing::SequenceNumber& commandId, uint64_t commandOffset);
00145 void expected(const framing::SequenceSet& commands, const framing::Array& fragments);
00146 void confirmed(const framing::SequenceSet& commands, const framing::Array& fragments);
00147 void completed(const framing::SequenceSet& commands, bool timelyReply);
00148 void knownCompleted(const framing::SequenceSet& commands);
00149 void flush(bool expected, bool confirmed, bool completed);
00150 void gap(const framing::SequenceSet& commands);
00151
00152
00153
00154 void sync();
00155 void result(const framing::SequenceNumber& commandId, const std::string& value);
00156 void exception(uint16_t errorCode,
00157 const framing::SequenceNumber& commandId,
00158 uint8_t classCode,
00159 uint8_t commandCode,
00160 uint8_t fieldIndex,
00161 const std::string& description,
00162 const framing::FieldTable& errorInfo);
00163
00164 ErrorType error;
00165 int code;
00166 std::string text;
00167 mutable StateMonitor state;
00168 mutable sys::Semaphore sendLock;
00169 uint32_t detachedLifetime;
00170 const uint64_t maxFrameSize;
00171 const SessionId id;
00172
00173 shared_ptr<ConnectionImpl> connection;
00174 framing::FrameHandler::MemFunRef<SessionImpl, &SessionImpl::proxyOut> ioHandler;
00175 framing::ChannelHandler channel;
00176 framing::AMQP_ServerProxy::Session proxy;
00177
00178 Results results;
00179 Demux demux;
00180 framing::FrameSet::shared_ptr arriving;
00181
00182 framing::SequenceSet incompleteIn;
00183 framing::SequenceSet completedIn;
00184 framing::SequenceSet incompleteOut;
00185 framing::SequenceSet completedOut;
00186 framing::SequenceNumber nextIn;
00187 framing::SequenceNumber nextOut;
00188
00189 };
00190
00191 }}
00192
00193 #endif