summaryrefslogtreecommitdiff
path: root/qpid/cpp/src/qmf/ConsoleSession.cpp
blob: 7b839930e15bb117b8b5aa603bacbcc059f6c4a6 (plain)
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
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
/*
 *
 * 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.
 *
 */

#include "qmf/PrivateImplRef.h"
#include "qmf/ConsoleSessionImpl.h"
#include "qmf/AgentImpl.h"
#include "qmf/SchemaId.h"
#include "qmf/SchemaImpl.h"
#include "qmf/ConsoleEventImpl.h"
#include "qmf/constants.h"
#include "qpid/log/Statement.h"
#include "qpid/messaging/AddressParser.h"
#include "qpid/messaging/Sender.h"
#include "qpid/messaging/Receiver.h"

using namespace std;
using namespace qmf;
using qpid::messaging::Address;
using qpid::messaging::Connection;
using qpid::messaging::Receiver;
using qpid::messaging::Sender;
using qpid::messaging::Duration;
using qpid::messaging::Message;
using qpid::types::Variant;

typedef qmf::PrivateImplRef<ConsoleSession> PI;

ConsoleSession::ConsoleSession(ConsoleSessionImpl* impl) { PI::ctor(*this, impl); }
ConsoleSession::ConsoleSession(const ConsoleSession& s) : qmf::Handle<ConsoleSessionImpl>() { PI::copy(*this, s); }
ConsoleSession::~ConsoleSession() { PI::dtor(*this); }
ConsoleSession& ConsoleSession::operator=(const ConsoleSession& s) { return PI::assign(*this, s); }

ConsoleSession::ConsoleSession(Connection& c, const string& o) { PI::ctor(*this, new ConsoleSessionImpl(c, o)); }
void ConsoleSession::setDomain(const string& d) { impl->setDomain(d); }
void ConsoleSession::setAgentFilter(const string& f) { impl->setAgentFilter(f); }
void ConsoleSession::open() { impl->open(); }
void ConsoleSession::close() { impl->close(); }
bool ConsoleSession::nextEvent(ConsoleEvent& e, Duration t) { return impl->nextEvent(e, t); }
int ConsoleSession::pendingEvents() const { return impl->pendingEvents(); }
uint32_t ConsoleSession::getAgentCount() const { return impl->getAgentCount(); }
Agent ConsoleSession::getAgent(uint32_t i) const { return impl->getAgent(i); }
Agent ConsoleSession::getConnectedBrokerAgent() const { return impl->getConnectedBrokerAgent(); }
Subscription ConsoleSession::subscribe(const Query& q, const string& f, const string& o) { return impl->subscribe(q, f, o); }
Subscription ConsoleSession::subscribe(const string& q, const string& f, const string& o) { return impl->subscribe(q, f, o); }

//========================================================================================
// Impl Method Bodies
//========================================================================================

ConsoleSessionImpl::ConsoleSessionImpl(Connection& c, const string& options) :
    connection(c), domain("default"), maxAgentAgeMinutes(5),
    opened(false), thread(0), threadCanceled(false), lastVisit(0), lastAgePass(0),
    connectedBrokerInAgentList(false), schemaCache(new SchemaCache())
{
    if (!options.empty()) {
        qpid::messaging::AddressParser parser(options);
        Variant::Map optMap;
        Variant::Map::const_iterator iter;

        parser.parseMap(optMap);

        iter = optMap.find("domain");
        if (iter != optMap.end())
            domain = iter->second.asString();

        iter = optMap.find("max-agent-age");
        if (iter != optMap.end())
            maxAgentAgeMinutes = iter->second.asUint32();

        iter = optMap.find("listen-on-direct");
        if (iter != optMap.end())
            listenOnDirect = iter->second.asBool();

        iter = optMap.find("strict-security");
        if (iter != optMap.end())
            strictSecurity = iter->second.asBool();
    }
}


ConsoleSessionImpl::~ConsoleSessionImpl()
{
    if (opened)
        close();
}


void ConsoleSessionImpl::setAgentFilter(const string& predicate)
{
    agentQuery = Query(QUERY_OBJECT, predicate);

    //
    // Purge the agent list of any agents that don't match the filter.
    //
    {
        qpid::sys::Mutex::ScopedLock l(lock);
        map<string, Agent> toDelete;
        for (map<string, Agent>::iterator iter = agents.begin(); iter != agents.end(); iter++)
            if (!agentQuery.matchesPredicate(iter->second.getAttributes())) {
                toDelete[iter->first] = iter->second;
                if (iter->second.getName() == connectedBrokerAgent.getName())
                    connectedBrokerInAgentList = false;
            }

        for (map<string, Agent>::iterator iter = toDelete.begin(); iter != toDelete.end(); iter++) {
            agents.erase(iter->first);
            auto_ptr<ConsoleEventImpl> eventImpl(new ConsoleEventImpl(CONSOLE_AGENT_DEL, AGENT_DEL_FILTER));
            eventImpl->setAgent(iter->second);
            enqueueEventLH(eventImpl.release());
        }

        if (!connectedBrokerInAgentList && connectedBrokerAgent.isValid() &&
            agentQuery.matchesPredicate(connectedBrokerAgent.getAttributes())) {
            agents[connectedBrokerAgent.getName()] = connectedBrokerAgent;
            connectedBrokerInAgentList = true;

            //
            // Enqueue a notification of the new agent.
            //
            auto_ptr<ConsoleEventImpl> eventImpl(new ConsoleEventImpl(CONSOLE_AGENT_ADD));
            eventImpl->setAgent(connectedBrokerAgent);
            enqueueEventLH(ConsoleEvent(eventImpl.release()));
        }
    }

    //
    // Broadcast an agent locate request with our new criteria.
    //
    if (opened)
        sendAgentLocate();
}


void ConsoleSessionImpl::open()
{
    if (opened)
        throw QmfException("The session is already open");

    // Establish messaging addresses
    directBase = "qmf." + domain + ".direct";
    topicBase = "qmf." + domain + ".topic";

    string myKey("direct-console." + qpid::types::Uuid(true).str());

    replyAddress = Address(topicBase + "/" + myKey + ";{node:{type:topic}}");

    // Create AMQP session, receivers, and senders
    session = connection.createSession();
    Receiver directRx = session.createReceiver(replyAddress);
    Receiver topicRx = session.createReceiver(topicBase + "/agent.#"); // TODO: be more discriminating
    if (!strictSecurity) {
        Receiver legacyRx = session.createReceiver("amq.direct/" + myKey + ";{node:{type:topic}}");
        legacyRx.setCapacity(64);
        directSender = session.createSender(directBase + ";{create:never,node:{type:topic}}");
        directSender.setCapacity(128);
    }

    directRx.setCapacity(64);
    topicRx.setCapacity(128);

    topicSender = session.createSender(topicBase + ";{create:never,node:{type:topic}}");

    topicSender.setCapacity(128);

    // Start the receiver thread
    threadCanceled = false;
    thread = new qpid::sys::Thread(*this);

    // Send an agent_locate to direct address 'broker' to identify the connected-broker-agent.
    sendBrokerLocate();
    if (agentQuery)
        sendAgentLocate();

    opened = true;
}


void ConsoleSessionImpl::close()
{
    if (!opened)
        throw QmfException("The session is already closed");

    // Stop and join the receiver thread
    threadCanceled = true;
    thread->join();
    delete thread;

    // Close the AMQP session
    session.close();
    opened = false;
}


bool ConsoleSessionImpl::nextEvent(ConsoleEvent& event, Duration timeout)
{
    uint64_t milliseconds = timeout.getMilliseconds();
    qpid::sys::Mutex::ScopedLock l(lock);

    if (eventQueue.empty() && milliseconds > 0)
        cond.wait(lock, qpid::sys::AbsTime(qpid::sys::now(),
                                           qpid::sys::Duration(milliseconds * qpid::sys::TIME_MSEC)));

    if (!eventQueue.empty()) {
        event = eventQueue.front();
        eventQueue.pop();
        return true;
    }

    return false;
}


int ConsoleSessionImpl::pendingEvents() const
{
    qpid::sys::Mutex::ScopedLock l(lock);
    return eventQueue.size();
}


uint32_t ConsoleSessionImpl::getAgentCount() const
{
    qpid::sys::Mutex::ScopedLock l(lock);
    return agents.size();
}


Agent ConsoleSessionImpl::getAgent(uint32_t i) const
{
    qpid::sys::Mutex::ScopedLock l(lock);
    uint32_t count = 0;
    for (map<string, Agent>::const_iterator iter = agents.begin(); iter != agents.end(); iter++)
        if (count++ == i)
            return iter->second;
    throw IndexOutOfRange();
}


Subscription ConsoleSessionImpl::subscribe(const Query&, const string&, const string&)
{
    return Subscription();
}


Subscription ConsoleSessionImpl::subscribe(const string&, const string&, const string&)
{
    return Subscription();
}


void ConsoleSessionImpl::enqueueEvent(const ConsoleEvent& event)
{
    qpid::sys::Mutex::ScopedLock l(lock);
    enqueueEventLH(event);
}


void ConsoleSessionImpl::enqueueEventLH(const ConsoleEvent& event)
{
    bool notify = eventQueue.empty();
    eventQueue.push(event);
    if (notify)
        cond.notify();
}


void ConsoleSessionImpl::dispatch(Message msg)
{
    const Variant::Map& properties(msg.getProperties());
    Variant::Map::const_iterator iter;
    Variant::Map::const_iterator oiter;

    oiter = properties.find(protocol::HEADER_KEY_OPCODE);
    iter = properties.find(protocol::HEADER_KEY_APP_ID);
    if (iter == properties.end())
        iter = properties.find("app_id");
    if (iter != properties.end() && iter->second.asString() == protocol::HEADER_APP_ID_QMF && oiter != properties.end()) {
        //
        // Dispatch a QMFv2 formatted message
        //
        const string& opcode = oiter->second.asString();

        iter = properties.find(protocol::HEADER_KEY_AGENT);
        if (iter == properties.end()) {
            QPID_LOG(trace, "Message received with no 'qmf.agent' header");
            return;
        }
        const string& agentName = iter->second.asString();

        Agent agent;
        {
            qpid::sys::Mutex::ScopedLock l(lock);
            map<string, Agent>::iterator aIter = agents.find(agentName);
            if (aIter != agents.end()) {
                agent = aIter->second;
                AgentImplAccess::get(agent).touch();
            }
        }

        if (msg.getContentType() == "amqp/map" &&
            (opcode == protocol::HEADER_OPCODE_AGENT_HEARTBEAT_INDICATION || opcode == protocol::HEADER_OPCODE_AGENT_LOCATE_RESPONSE)) {
            //
            // This is the one case where it's ok (necessary actually) to receive a QMFv2
            // message from an unknown agent (how else are they going to get known?)
            //
            Variant::Map content;
            decode(msg, content);
            handleAgentUpdate(agentName, content, msg);
            return;
        }

        if (!agent.isValid())
            return;

        AgentImpl& agentImpl(AgentImplAccess::get(agent));

        if (msg.getContentType() == "amqp/map") {
            Variant::Map content;
            decode(msg, content);

            if      (opcode == protocol::HEADER_OPCODE_EXCEPTION)       agentImpl.handleException(content, msg);
            else if (opcode == protocol::HEADER_OPCODE_METHOD_RESPONSE) agentImpl.handleMethodResponse(content, msg);
            else
                QPID_LOG(error, "Received a map-formatted QMFv2 message with opcode=" << opcode);

            return;
        }

        if (msg.getContentType() == "amqp/list") {
            Variant::List content;
            decode(msg, content);

            if      (opcode == protocol::HEADER_OPCODE_QUERY_RESPONSE)  agentImpl.handleQueryResponse(content, msg);
            else if (opcode == protocol::HEADER_OPCODE_DATA_INDICATION) agentImpl.handleDataIndication(content, msg);
            else
                QPID_LOG(error, "Received a list-formatted QMFv2 message with opcode=" << opcode);

            return;
        }
    } else {
        //
        // Dispatch a QMFv1 formatted message
        //
        const string& body(msg.getContent());
        if (body.size() < 8)
            return;
        qpid::management::Buffer buffer(const_cast<char*>(body.c_str()), body.size());

        if (buffer.getOctet() != 'A') return;
        if (buffer.getOctet() != 'M') return;
        if (buffer.getOctet() != '2') return;
        char v1Opcode(buffer.getOctet());
        uint32_t seq(buffer.getLong());

        if (v1Opcode == 's') handleV1SchemaResponse(buffer, seq, msg);
        else {
            QPID_LOG(trace, "Unknown or Unsupported QMFv1 opcode: " << v1Opcode);
        }
    }
}


void ConsoleSessionImpl::sendBrokerLocate()
{
    Message msg;
    Variant::Map& headers(msg.getProperties());

    headers[protocol::HEADER_KEY_METHOD] = protocol::HEADER_METHOD_REQUEST;
    headers[protocol::HEADER_KEY_OPCODE] = protocol::HEADER_OPCODE_AGENT_LOCATE_REQUEST;
    headers[protocol::HEADER_KEY_APP_ID] = protocol::HEADER_APP_ID_QMF;

    msg.setReplyTo(replyAddress);
    msg.setCorrelationId("broker-locate");
    msg.setSubject("broker");

    Sender sender = session.createSender(directBase + ";{create:never,node:{type:topic}}");
    sender.send(msg);
    sender.close();

    QPID_LOG(trace, "SENT AgentLocate to broker");
}


void ConsoleSessionImpl::sendAgentLocate()
{
    Message msg;
    Variant::Map& headers(msg.getProperties());
    static const string subject("console.request.agent_locate");

    headers[protocol::HEADER_KEY_METHOD] = protocol::HEADER_METHOD_REQUEST;
    headers[protocol::HEADER_KEY_OPCODE] = protocol::HEADER_OPCODE_AGENT_LOCATE_REQUEST;
    headers[protocol::HEADER_KEY_APP_ID] = protocol::HEADER_APP_ID_QMF;

    msg.setReplyTo(replyAddress);
    msg.setCorrelationId("agent-locate");
    msg.setSubject(subject);
    encode(agentQuery.getPredicate(), msg);

    topicSender.send(msg);

    QPID_LOG(trace, "SENT AgentLocate to=" << topicSender.getName() << "/" << subject);
}


void ConsoleSessionImpl::handleAgentUpdate(const string& agentName, const Variant::Map& content, const Message& msg)
{
    Variant::Map::const_iterator iter;
    Agent agent;
    uint32_t epoch(0);
    string cid(msg.getCorrelationId());

    iter = content.find("_values");
    if (iter == content.end())
        return;
    const Variant::Map& in_attrs(iter->second.asMap());
    Variant::Map attrs;

    //
    // Copy the map from the message to "attrs".  Translate any old-style
    // keys to their new key values in the process.
    //
    for (iter = in_attrs.begin(); iter != in_attrs.end(); iter++) {
        if      (iter->first == "epoch")
            attrs[protocol::AGENT_ATTR_EPOCH] = iter->second;
        else if (iter->first == "timestamp")
            attrs[protocol::AGENT_ATTR_TIMESTAMP] = iter->second;
        else if (iter->first == "heartbeat_interval")
            attrs[protocol::AGENT_ATTR_HEARTBEAT_INTERVAL] = iter->second;
        else
            attrs[iter->first] = iter->second;
    }

    iter = attrs.find(protocol::AGENT_ATTR_EPOCH);
    if (iter != attrs.end())
        epoch = iter->second.asUint32();

    if (cid == "broker-locate") {
        qpid::sys::Mutex::ScopedLock l(lock);
        auto_ptr<AgentImpl> impl(new AgentImpl(agentName, epoch, *this));
        for (iter = attrs.begin(); iter != attrs.end(); iter++)
            if (iter->first != protocol::AGENT_ATTR_EPOCH)
                impl->setAttribute(iter->first, iter->second);
        agent = Agent(impl.release());
        connectedBrokerAgent = agent;
        if (!agentQuery || agentQuery.matchesPredicate(attrs)) {
            connectedBrokerInAgentList = true;
            agents[agentName] = agent;

            //
            // Enqueue a notification of the new agent.
            //
            auto_ptr<ConsoleEventImpl> eventImpl(new ConsoleEventImpl(CONSOLE_AGENT_ADD));
            eventImpl->setAgent(agent);
            enqueueEventLH(ConsoleEvent(eventImpl.release()));
        }
        return;
    }

    //
    // Check this agent against the agent filter.  Exit if it doesn't match.
    // (only if this isn't the connected broker agent)
    //
    if (agentQuery && (!agentQuery.matchesPredicate(attrs)))
        return;

    QPID_LOG(trace, "RCVD AgentHeartbeat from an agent matching our filter: " << agentName);

    {
        qpid::sys::Mutex::ScopedLock l(lock);
        map<string, Agent>::iterator aIter = agents.find(agentName);
        if (aIter == agents.end()) {
            //
            // This is a new agent.  We have no current record of its existence.
            //
            auto_ptr<AgentImpl> impl(new AgentImpl(agentName, epoch, *this));
            for (iter = attrs.begin(); iter != attrs.end(); iter++)
                if (iter->first != protocol::AGENT_ATTR_EPOCH)
                    impl->setAttribute(iter->first, iter->second);
            agent = Agent(impl.release());
            agents[agentName] = agent;

            //
            // Enqueue a notification of the new agent.
            //
            auto_ptr<ConsoleEventImpl> eventImpl(new ConsoleEventImpl(CONSOLE_AGENT_ADD));
            eventImpl->setAgent(agent);
            enqueueEventLH(ConsoleEvent(eventImpl.release()));
        } else {
            //
            // This is a refresh of an agent we are already tracking.
            //
            bool detectedRestart(false);
            agent = aIter->second;
            AgentImpl& impl(AgentImplAccess::get(agent));
            impl.touch();
            if (impl.getEpoch() != epoch) {
                //
                // The agent has restarted since the last time we heard from it.
                // Enqueue a notification.
                //
                impl.setEpoch(epoch);
                auto_ptr<ConsoleEventImpl> eventImpl(new ConsoleEventImpl(CONSOLE_AGENT_RESTART));
                eventImpl->setAgent(agent);
                enqueueEventLH(ConsoleEvent(eventImpl.release()));
                detectedRestart = true;
            }

            iter = attrs.find(protocol::AGENT_ATTR_SCHEMA_UPDATED_TIMESTAMP);
            if (iter != attrs.end()) {
                uint64_t ts(iter->second.asUint64());
                if (ts > impl.getAttribute(protocol::AGENT_ATTR_SCHEMA_UPDATED_TIMESTAMP).asUint64()) {
                    //
                    // The agent has added new schema entries since we last heard from it.
                    // Update the attribute and, if this doesn't accompany a restart, enqueue a notification.
                    //
                    if (!detectedRestart) {
                        auto_ptr<ConsoleEventImpl> eventImpl(new ConsoleEventImpl(CONSOLE_AGENT_SCHEMA_UPDATE));
                        eventImpl->setAgent(agent);
                        enqueueEventLH(ConsoleEvent(eventImpl.release()));
                    }
                    impl.setAttribute(protocol::AGENT_ATTR_SCHEMA_UPDATED_TIMESTAMP, iter->second);
                }
            }
        }
    }
}


void ConsoleSessionImpl::handleV1SchemaResponse(qpid::management::Buffer& buffer, uint32_t, const Message&)
{
    QPID_LOG(trace, "RCVD V1SchemaResponse");
    Schema schema(new SchemaImpl(buffer));
    schemaCache->declareSchema(schema);
}


void ConsoleSessionImpl::periodicProcessing(uint64_t seconds)
{
    //
    // The granularity of this timer is seconds.  Don't waste time looking for work if
    // it's been less than a second since we last visited.
    //
    if (seconds == lastVisit)
        return;
    lastVisit = seconds;

    //
    // Handle the aging of agent records
    //
    if (lastAgePass == 0)
        lastAgePass = seconds;
    if (seconds - lastAgePass >= 60) {
        lastAgePass = seconds;
        map<string, Agent> toDelete;
        qpid::sys::Mutex::ScopedLock l(lock);

        for (map<string, Agent>::iterator iter = agents.begin(); iter != agents.end(); iter++)
            if ((iter->second.getName() != connectedBrokerAgent.getName()) &&
                (AgentImplAccess::get(iter->second).age() > maxAgentAgeMinutes))
                toDelete[iter->first] = iter->second;

        for (map<string, Agent>::iterator iter = toDelete.begin(); iter != toDelete.end(); iter++) {
            agents.erase(iter->first);
            auto_ptr<ConsoleEventImpl> eventImpl(new ConsoleEventImpl(CONSOLE_AGENT_DEL, AGENT_DEL_AGED));
            eventImpl->setAgent(iter->second);
            enqueueEventLH(eventImpl.release());
        }
    }
}


void ConsoleSessionImpl::run()
{
    QPID_LOG(debug, "ConsoleSession thread started");

    try {
        while (!threadCanceled) {
            periodicProcessing((uint64_t) qpid::sys::Duration(qpid::sys::EPOCH, qpid::sys::now()) /
                               qpid::sys::TIME_SEC);

            Receiver rx;
            bool valid = session.nextReceiver(rx, Duration::SECOND);
            if (threadCanceled)
                break;
            if (valid) {
                try {
                    dispatch(rx.fetch());
                } catch (qpid::types::Exception& e) {
                    QPID_LOG(error, "Exception caught in message dispatch: " << e.what());
                }
                session.acknowledge();
            }
        }
    } catch (qpid::types::Exception& e) {
        QPID_LOG(error, "Exception caught in message thread - exiting: " << e.what());
        enqueueEvent(ConsoleEvent(new ConsoleEventImpl(CONSOLE_THREAD_FAILED)));
    }

    QPID_LOG(debug, "ConsoleSession thread exiting");
}