aboutsummaryrefslogtreecommitdiffstats
path: root/messagebus/src/vespa/messagebus/replygate.cpp
blob: e1418783747ff5e0a049edbcf9eed38608a89435 (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
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include "replygate.h"
#include "message.h"
#include "reply.h"

namespace mbus {

ReplyGate::ReplyGate(IMessageHandler &sender) :
    _sender(sender),
    _open(true)
{ }

void
ReplyGate::handleMessage(Message::UP msg)
{
    internal_addref();
    msg->pushHandler(*this, *this);
    _sender.handleMessage(std::move(msg));
}

void
ReplyGate::close()
{
    _open.store(false, std::memory_order_relaxed);
}

void
ReplyGate::handleReply(Reply::UP reply)
{
    if (_open.load(std::memory_order_relaxed)) {
        IReplyHandler &handler = reply->getCallStack().pop(*reply);
        handler.handleReply(std::move(reply));
    } else {
        reply->discard();
    }
    internal_subref();
}

void
ReplyGate::handleDiscard(Context)
{
    internal_subref();
}

} // namespace mbus