/
prefix_store.cc
47 lines (38 loc) · 1.09 KB
/
prefix_store.cc
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
/**
* Copyright (c) 2017-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/
#include "prefix_store.h"
#include <sstream>
namespace gloo {
namespace rendezvous {
PrefixStore::PrefixStore(
const std::string& prefix,
Store& store)
: prefix_(prefix), store_(store) {}
std::string PrefixStore::joinKey(const std::string& key) {
std::stringstream ss;
ss << prefix_ << "/" << key;
return ss.str();
}
void PrefixStore::set(const std::string& key, const std::vector<char>& data) {
store_.set(joinKey(key), data);
}
std::vector<char> PrefixStore::get(const std::string& key) {
return store_.get(joinKey(key));
}
void PrefixStore::wait(
const std::vector<std::string>& keys,
const std::chrono::milliseconds& timeout) {
std::vector<std::string> joinedKeys;
joinedKeys.reserve(keys.size());
for (const auto& key : keys) {
joinedKeys.push_back(joinKey(key));
}
store_.wait(joinedKeys, timeout);
}
} // namespace rendezvous
} // namespace gloo