-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathFDBFactory.h
More file actions
191 lines (116 loc) · 5.17 KB
/
FDBFactory.h
File metadata and controls
191 lines (116 loc) · 5.17 KB
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
/*
* (C) Copyright 1996- ECMWF.
*
* This software is licensed under the terms of the Apache Licence Version 2.0
* which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
* In applying this licence, ECMWF does not waive the privileges and immunities
* granted to it by virtue of its status as an intergovernmental organisation nor
* does it submit to any jurisdiction.
*/
/*
* This software was developed as part of the EC H2020 funded project NextGenIO
* (Project ID: 671951) www.nextgenio.eu
*/
/// @author Simon Smart
/// @date Mar 2018
#ifndef fdb5_api_FDBFactory_H
#define fdb5_api_FDBFactory_H
#include <memory>
#include "fdb5/api/helpers/AxesIterator.h"
#include "fdb5/api/helpers/Callback.h"
#include "fdb5/api/helpers/ControlIterator.h"
#include "fdb5/api/helpers/DumpIterator.h"
#include "fdb5/api/helpers/ListIterator.h"
#include "fdb5/api/helpers/MoveIterator.h"
#include "fdb5/api/helpers/PurgeIterator.h"
#include "fdb5/api/helpers/StatsIterator.h"
#include "fdb5/api/helpers/StatusIterator.h"
#include "fdb5/config/Config.h"
#include "fdb5/database/WipeState.h"
namespace eckit::message {
class Message;
} // namespace eckit::message
namespace metkit::mars {
class MarsRequest;
} // namespace metkit::mars
namespace fdb5 {
class Key;
class FDBToolRequest;
class FieldLocation;
//----------------------------------------------------------------------------------------------------------------------
/// The base class that FDB implementations are derived from
class FDBBase : public std::enable_shared_from_this<FDBBase>, public CallbackRegistry {
public: // methods
FDBBase(const Config& config, const std::string& name);
FDBBase(const FDBBase&) = delete;
FDBBase& operator=(const FDBBase&) = delete;
FDBBase(FDBBase&&) = delete;
FDBBase& operator=(FDBBase&&) = delete;
virtual ~FDBBase() = default;
std::shared_ptr<FDBBase> shared() { return shared_from_this(); }
// -------------- Primary API functions ----------------------------
virtual void archive(const Key& key, const void* data, size_t length) = 0;
virtual void reindex(const Key& key, const FieldLocation& location) { NOTIMP; }
virtual void flush() = 0;
virtual ListIterator inspect(const metkit::mars::MarsRequest& request) = 0;
virtual ListIterator list(const FDBToolRequest& request, int level) = 0;
virtual DumpIterator dump(const FDBToolRequest& request, bool simple) = 0;
virtual StatusIterator status(const FDBToolRequest& request) = 0;
virtual WipeStateIterator wipe(const FDBToolRequest& request, bool doit, bool porcelain, bool unsafeWipeAll) = 0;
virtual PurgeIterator purge(const FDBToolRequest& request, bool doit, bool porcelain) = 0;
virtual StatsIterator stats(const FDBToolRequest& request) = 0;
virtual ControlIterator control(const FDBToolRequest& request, ControlAction action,
ControlIdentifiers identifier) = 0;
virtual MoveIterator move(const FDBToolRequest& request, const eckit::URI& dest) = 0;
virtual AxesIterator axesIterator(const FDBToolRequest& request, int axes) = 0;
// -------------- API management ----------------------------
/// ID used for hashing in the Rendezvous hash. Should be unique amongst those used
/// within a DistFDB (i.e. within one Rendezvous hash).
virtual std::string id() const;
const std::string& name() const;
const Config& config() const;
bool enabled(const ControlIdentifier& controlIdentifier) const;
private: // methods
virtual void print(std::ostream& s) const = 0;
friend std::ostream& operator<<(std::ostream& s, const FDBBase& f) {
f.print(s);
return s;
}
protected: // members
const std::string name_;
Config config_;
ControlIdentifiers controlIdentifiers_;
};
//----------------------------------------------------------------------------------------------------------------------
class FDBBuilderBase;
class FDBFactory {
public:
static FDBFactory& instance();
void add(const std::string& name, const FDBBuilderBase*);
std::shared_ptr<FDBBase> build(const Config& config);
private:
FDBFactory() {} ///< private constructor only used by singleton
eckit::Mutex mutex_;
std::map<std::string, const FDBBuilderBase*> registry_;
};
class FDBBuilderBase {
public: // methods
virtual std::shared_ptr<FDBBase> make(const Config& config) const = 0;
protected: // methods
FDBBuilderBase(const std::string& name);
virtual ~FDBBuilderBase();
protected: // members
std::string name_;
};
template <typename T>
class FDBBuilder : public FDBBuilderBase {
static_assert(std::is_base_of<FDBBase, T>::value,
"FDB Factorys can only build implementations of the FDB interface");
public: // methods
FDBBuilder(const std::string& name) : FDBBuilderBase(name) {}
private: // methods
std::shared_ptr<FDBBase> make(const Config& config) const override { return std::make_shared<T>(config, name_); }
};
//----------------------------------------------------------------------------------------------------------------------
} // namespace fdb5
#endif // fdb5_api_FDBFactory_H