blob: ef6390501c3f151afd76721293ec1683a06818ea (
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
|
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#pragma once
#include "cfg.h"
#include <mutex>
namespace slobrok::api {
/**
* @brief List of connection specs for service location brokers
**/
class SlobrokList : public Configurable {
public:
/**
* @brief Create a new SlobrokList object, initially empty
**/
SlobrokList();
/**
* setup with a list of connection specs;
* should be called at least once.
* @param specList should not be an empty list.
**/
void setup(const std::vector<std::string> &specList) override;
/**
* retrieve the spec for next slobrok server to try.
* NOTE: when the list is exhausted the empty string will
* be returned once before looping and retrying.
**/
std::string nextSlobrokSpec();
/** obtain how many times we have tried all possible servers */
size_t retryCount() const { return _retryCount; }
/** check if setup has been called successfully */
bool ok() const { return _slobrokSpecs.size() > 0; }
/** return a string (for logging) with all specs in the list */
std::string logString();
/** check if the list contains a given spec */
bool contains(const std::string &spec);
private:
std::mutex _lock;
std::vector<std::string> _slobrokSpecs;
size_t _nextSpec;
size_t _currSpec;
size_t _retryCount;
};
}
|