blob: b2e1a29d7bdc615d808250a11b587c1970c0bf5c (
plain) (
blame)
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
|
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include "intermediatesession.h"
#include "messagebus.h"
#include "replygate.h"
using vespalib::make_ref_counted;
namespace mbus {
IntermediateSession::IntermediateSession(MessageBus &mbus, const IntermediateSessionParams ¶ms) :
_mbus(mbus),
_name(params.getName()),
_msgHandler(params.getMessageHandler()),
_replyHandler(params.getReplyHandler()),
_gate(make_ref_counted<ReplyGate>(_mbus))
{ }
IntermediateSession::~IntermediateSession()
{
_gate->close();
close();
}
void
IntermediateSession::close()
{
_mbus.unregisterSession(_name);
_mbus.sync();
}
void
IntermediateSession::forward(Routable::UP routable)
{
if (routable->isReply()) {
forward(Reply::UP(static_cast<Reply*>(routable.release())));
} else {
forward(Message::UP(static_cast<Message*>(routable.release())));
}
}
void
IntermediateSession::forward(Reply::UP reply)
{
IReplyHandler &handler = reply->getCallStack().pop(*reply);
handler.handleReply(std::move(reply));
}
void
IntermediateSession::forward(Message::UP msg)
{
msg->pushHandler(*this);
_gate->handleMessage(std::move(msg));
}
void
IntermediateSession::handleMessage(Message::UP msg)
{
_msgHandler.handleMessage(std::move(msg));
}
void
IntermediateSession::handleReply(Reply::UP reply)
{
_replyHandler.handleReply(std::move(reply));
}
const string
IntermediateSession::getConnectionSpec() const
{
return _mbus.getConnectionSpec() + "/" + _name;
}
} // namespace mbus
|