1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
|
/*
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
#ifndef _SessionHandlerImpl_
#define _SessionHandlerImpl_
#include <map>
#include <sstream>
#include <vector>
#include <exception>
#include <AMQFrame.h>
#include <AMQP_ClientProxy.h>
#include <AMQP_ServerOperations.h>
#include <AutoDelete.h>
#include <ExchangeRegistry.h>
#include <BrokerChannel.h>
#include <ConnectionToken.h>
#include <DirectExchange.h>
#include <OutputHandler.h>
#include <ProtocolInitiation.h>
#include <QueueRegistry.h>
#include <sys/SessionContext.h>
#include <sys/SessionHandler.h>
#include <sys/TimeoutHandler.h>
#include <TopicExchange.h>
namespace qpid {
namespace broker {
struct ChannelException : public std::exception {
u_int16_t code;
string text;
ChannelException(u_int16_t _code, string _text) : code(_code), text(_text) {}
~ChannelException() throw() {}
const char* what() const throw() { return text.c_str(); }
};
struct ConnectionException : public std::exception {
u_int16_t code;
string text;
ConnectionException(u_int16_t _code, string _text) : code(_code), text(_text) {}
~ConnectionException() throw() {}
const char* what() const throw() { return text.c_str(); }
};
class Settings {
public:
const u_int32_t timeout;//timeout for auto-deleted queues (in ms)
const u_int64_t stagingThreshold;
Settings(u_int32_t _timeout, u_int64_t _stagingThreshold) : timeout(_timeout), stagingThreshold(_stagingThreshold) {}
};
class SessionHandlerImpl : public qpid::sys::SessionHandler,
public qpid::framing::AMQP_ServerOperations,
public ConnectionToken
{
typedef std::map<u_int16_t, Channel*>::iterator channel_iterator;
typedef std::vector<Queue::shared_ptr>::iterator queue_iterator;
qpid::sys::SessionContext* context;
qpid::framing::AMQP_ClientProxy* client;
QueueRegistry* queues;
ExchangeRegistry* const exchanges;
AutoDelete* const cleaner;
const Settings settings;
std::auto_ptr<BasicHandler> basicHandler;
std::auto_ptr<ChannelHandler> channelHandler;
std::auto_ptr<ConnectionHandler> connectionHandler;
std::auto_ptr<ExchangeHandler> exchangeHandler;
std::auto_ptr<QueueHandler> queueHandler;
std::auto_ptr<TxHandler> txHandler;
std::auto_ptr<MessageHandler> messageHandler;
std::map<u_int16_t, Channel*> channels;
std::vector<Queue::shared_ptr> exclusiveQueues;
u_int32_t framemax;
u_int16_t heartbeat;
void handleHeader(u_int16_t channel, qpid::framing::AMQHeaderBody::shared_ptr body);
void handleContent(u_int16_t channel, qpid::framing::AMQContentBody::shared_ptr body);
void handleHeartbeat(qpid::framing::AMQHeartbeatBody::shared_ptr body);
Channel* getChannel(u_int16_t channel);
/**
* Get named queue, never returns 0.
* @return: named queue or default queue for channel if name=""
* @exception: ChannelException if no queue of that name is found.
* @exception: ConnectionException if no queue specified and channel has not declared one.
*/
Queue::shared_ptr getQueue(const string& name, u_int16_t channel);
Exchange::shared_ptr findExchange(const string& name);
public:
SessionHandlerImpl(qpid::sys::SessionContext* context, QueueRegistry* queues,
ExchangeRegistry* exchanges, AutoDelete* cleaner, const Settings& settings);
virtual void received(qpid::framing::AMQFrame* frame);
virtual void initiated(qpid::framing::ProtocolInitiation* header);
virtual void idleOut();
virtual void idleIn();
virtual void closed();
virtual ~SessionHandlerImpl();
class ConnectionHandlerImpl : public ConnectionHandler{
SessionHandlerImpl* parent;
public:
inline ConnectionHandlerImpl(SessionHandlerImpl* _parent) : parent(_parent) {}
virtual void startOk(u_int16_t channel, const qpid::framing::FieldTable& clientProperties, const string& mechanism,
const string& response, const string& locale);
// Change to match new code generator function signature (adding const to string&) - kpvdr 2006-11-20
virtual void secureOk(u_int16_t channel, const string& response);
virtual void tuneOk(u_int16_t channel, u_int16_t channelMax, u_int32_t frameMax, u_int16_t heartbeat);
// Change to match new code generator function signature (adding const to string&) - kpvdr 2006-11-20
virtual void open(u_int16_t channel, const string& virtualHost, const string& capabilities, bool insist);
// Change to match new code generator function signature (adding const to string&) - kpvdr 2006-11-20
virtual void close(u_int16_t channel, u_int16_t replyCode, const string& replyText, u_int16_t classId,
u_int16_t methodId);
virtual void closeOk(u_int16_t channel);
virtual ~ConnectionHandlerImpl(){}
};
class ChannelHandlerImpl : public ChannelHandler{
SessionHandlerImpl* parent;
public:
inline ChannelHandlerImpl(SessionHandlerImpl* _parent) : parent(_parent) {}
// Change to match new code generator function signature (adding const to string&) - kpvdr 2006-11-20
virtual void open(u_int16_t channel, const string& outOfBand);
virtual void flow(u_int16_t channel, bool active);
virtual void flowOk(u_int16_t channel, bool active);
virtual void ok( u_int16_t channel );
virtual void ping( u_int16_t channel );
virtual void pong( u_int16_t channel );
virtual void resume( u_int16_t channel,
const string& channelId );
virtual void close(u_int16_t channel, u_int16_t replyCode, const string& replyText,
u_int16_t classId, u_int16_t methodId);
virtual void closeOk(u_int16_t channel);
virtual ~ChannelHandlerImpl(){}
};
class ExchangeHandlerImpl : public ExchangeHandler{
SessionHandlerImpl* parent;
public:
inline ExchangeHandlerImpl(SessionHandlerImpl* _parent) : parent(_parent) {}
virtual void declare(u_int16_t channel, u_int16_t ticket, const string& exchange, const string& type,
bool passive, bool durable, bool autoDelete, bool internal, bool nowait,
const qpid::framing::FieldTable& arguments);
virtual void delete_(u_int16_t channel, u_int16_t ticket, const string& exchange, bool ifUnused, bool nowait);
virtual void unbind(u_int16_t channel,
u_int16_t ticket,
const string& queue,
const string& exchange,
const string& routingKey,
const qpid::framing::FieldTable& arguments );
virtual ~ExchangeHandlerImpl(){}
};
class QueueHandlerImpl : public QueueHandler{
SessionHandlerImpl* parent;
public:
inline QueueHandlerImpl(SessionHandlerImpl* _parent) : parent(_parent) {}
virtual void declare(u_int16_t channel, u_int16_t ticket, const string& queue,
bool passive, bool durable, bool exclusive,
bool autoDelete, bool nowait, const qpid::framing::FieldTable& arguments);
virtual void bind(u_int16_t channel, u_int16_t ticket, const string& queue,
const string& exchange, const string& routingKey, bool nowait,
const qpid::framing::FieldTable& arguments);
virtual void unbind(u_int16_t channel,
u_int16_t ticket,
const string& queue,
const string& exchange,
const string& routingKey,
const qpid::framing::FieldTable& arguments );
virtual void purge(u_int16_t channel, u_int16_t ticket, const string& queue,
bool nowait);
// Change to match new code generator function signature (adding const to string&) - kpvdr 2006-11-20
virtual void delete_(u_int16_t channel, u_int16_t ticket, const string& queue, bool ifUnused, bool ifEmpty,
bool nowait);
virtual ~QueueHandlerImpl(){}
};
class BasicHandlerImpl : public BasicHandler{
SessionHandlerImpl* parent;
public:
inline BasicHandlerImpl(SessionHandlerImpl* _parent) : parent(_parent) {}
virtual void qos(u_int16_t channel, u_int32_t prefetchSize, u_int16_t prefetchCount, bool global);
virtual void consume(
u_int16_t channel, u_int16_t ticket, const string& queue,
const string& consumerTag, bool noLocal, bool noAck,
bool exclusive, bool nowait,
const qpid::framing::FieldTable& fields);
virtual void cancel(u_int16_t channel, const string& consumerTag, bool nowait);
virtual void publish(u_int16_t channel, u_int16_t ticket, const string& exchange, const string& routingKey,
bool mandatory, bool immediate);
virtual void get(u_int16_t channel, u_int16_t ticket, const string& queue, bool noAck);
virtual void ack(u_int16_t channel, u_int64_t deliveryTag, bool multiple);
virtual void reject(u_int16_t channel, u_int64_t deliveryTag, bool requeue);
virtual void recover(u_int16_t channel, bool requeue);
virtual ~BasicHandlerImpl(){}
};
class TxHandlerImpl : public TxHandler{
SessionHandlerImpl* parent;
public:
TxHandlerImpl(SessionHandlerImpl* _parent) : parent(_parent) {}
virtual ~TxHandlerImpl() {}
virtual void select(u_int16_t channel);
virtual void commit(u_int16_t channel);
virtual void rollback(u_int16_t channel);
};
class MessageHandlerImpl : public MessageHandler {
SessionHandlerImpl* parent;
// Constructors and destructors
public:
MessageHandlerImpl() {}
MessageHandlerImpl(SessionHandlerImpl* _parent) : parent(_parent) {}
virtual ~MessageHandlerImpl() {}
// Protocol methods
virtual void append( u_int16_t channel,
const string& reference,
const string& bytes );
virtual void cancel( u_int16_t channel,
const string& destination );
virtual void checkpoint( u_int16_t channel,
const string& reference,
const string& identifier );
virtual void close( u_int16_t channel,
const string& reference );
virtual void consume( u_int16_t channel,
u_int16_t ticket,
const string& queue,
const string& destination,
bool noLocal,
bool noAck,
bool exclusive,
const qpid::framing::FieldTable& filter );
virtual void empty( u_int16_t channel );
virtual void get( u_int16_t channel,
u_int16_t ticket,
const string& queue,
const string& destination,
bool noAck );
virtual void offset( u_int16_t channel,
u_int64_t value );
virtual void ok( u_int16_t channel );
virtual void open( u_int16_t channel,
const string& reference );
virtual void qos( u_int16_t channel,
u_int32_t prefetchSize,
u_int16_t prefetchCount,
bool global );
virtual void recover( u_int16_t channel,
bool requeue );
virtual void reject( u_int16_t channel,
u_int16_t code,
const string& text );
virtual void resume( u_int16_t channel,
const string& reference,
const string& identifier );
virtual void transfer( u_int16_t channel,
u_int16_t ticket,
const string& destination,
bool redelivered,
bool immediate,
u_int64_t ttl,
u_int8_t priority,
u_int64_t timestamp,
u_int8_t deliveryMode,
u_int64_t expiration,
const string& exchange,
const string& routingKey,
const string& messageId,
const string& correlationId,
const string& replyTo,
const string& contentType,
const string& contentEncoding,
const string& userId,
const string& appId,
const string& transactionId,
const string& securityToken,
const qpid::framing::FieldTable& applicationHeaders,
qpid::framing::Content body );
};
virtual ChannelHandler* getChannelHandler(){ return channelHandler.get(); }
virtual ConnectionHandler* getConnectionHandler(){ return connectionHandler.get(); }
virtual BasicHandler* getBasicHandler(){ return basicHandler.get(); }
virtual ExchangeHandler* getExchangeHandler(){ return exchangeHandler.get(); }
virtual QueueHandler* getQueueHandler(){ return queueHandler.get(); }
virtual TxHandler* getTxHandler(){ return txHandler.get(); }
virtual MessageHandler* getMessageHandler(){ return messageHandler.get(); }
virtual AccessHandler* getAccessHandler(){ throw ConnectionException(540, "Access class not implemented"); }
virtual FileHandler* getFileHandler(){ throw ConnectionException(540, "File class not implemented"); }
virtual StreamHandler* getStreamHandler(){ throw ConnectionException(540, "Stream class not implemented"); }
virtual DtxHandler* getDtxHandler(){ throw ConnectionException(540, "Dtx class not implemented"); }
virtual TunnelHandler* getTunnelHandler(){ throw ConnectionException(540, "Tunnel class not implemented"); }
};
}
}
#endif
|