blob: b4cd2c846aa15e8ce72ae1f8773f1852742023c9 (
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
|
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include "slobrok.h"
#include <vespa/slobrok/server/sbenv.h>
#include <vespa/fnet/frt/supervisor.h>
#include <vespa/fnet/transport.h>
#include <vespa/vespalib/util/stringfmt.h>
#include <vespa/log/log.h>
LOG_SETUP(".slobrok");
namespace mbus {
void
Slobrok::init()
{
slobrok::ConfigShim shim(_port);
_env = std::make_unique<slobrok::SBEnv>(shim);
_thread = std::thread([env = _env.get()]()
{
if (env->MainLoop() != 0) {
LOG_ABORT("Slobrok main failed");
}
});
_env->getTransport()->sync();
int p = _env->getSupervisor()->GetListenPort();
LOG_ASSERT(p != 0 && (p == _port || _port == 0));
_port = p;
}
Slobrok::Slobrok()
: _env(),
_port(0),
_thread()
{
init();
}
Slobrok::Slobrok(int p)
: _env(),
_port(p),
_thread()
{
init();
}
Slobrok::~Slobrok()
{
_env->getTransport()->ShutDown(true);
_thread.join();
}
int
Slobrok::port() const
{
return _port;
}
config::ConfigUri
Slobrok::config() const
{
cloud::config::SlobroksConfigBuilder builder;
cloud::config::SlobroksConfig::Slobrok sb;
sb.connectionspec = vespalib::make_string("tcp/localhost:%d", port());
builder.slobrok.push_back(sb);
return config::ConfigUri::createFromInstance(builder);
}
} // namespace mbus
|