aboutsummaryrefslogtreecommitdiffstats
path: root/storage/src/vespa/storage/common/cluster_context.h
blob: 379c40cb0e37aca5c4d1e3fed865408092af869e (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
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#pragma once

#include <vespa/vespalib/stllike/string.h>

namespace storage {

/**
 * Cluster ontext common to all storage components.
 * For now just the cluster name, but we can consider
 * moving other global context into this API.
 **/
struct ClusterContext {
protected:
    virtual ~ClusterContext() = default;
public:
    // Returns a pointer to the cluster name.
    // Must be a valid pointer to a constant string for the
    // lifetime of all the components that may ask for it.
    // This API is for the benefit of StorageMessageAddress
    // which wants to contain the pointer returned here.
    virtual const vespalib::string * cluster_name_ptr() const noexcept = 0;

    // convenience method
    const vespalib::string &cluster_name() const noexcept {
        return *cluster_name_ptr();
    }
};

/**
 * Simple ClusterContext with an exposed string.
 **/
struct SimpleClusterContext : ClusterContext {
    vespalib::string my_cluster_name;
    const vespalib::string * cluster_name_ptr() const noexcept override {
        return &my_cluster_name;
    }
    SimpleClusterContext() : my_cluster_name("") {}
    explicit SimpleClusterContext(const vespalib::string& value)
      : my_cluster_name(value)
    {}
    ~SimpleClusterContext() override = default;
};

} // namespace