-
Notifications
You must be signed in to change notification settings - Fork 436
Expand file tree
/
Copy pathPluginRegistry.h
More file actions
101 lines (83 loc) · 3.82 KB
/
PluginRegistry.h
File metadata and controls
101 lines (83 loc) · 3.82 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
/*
* Copyright 2023 iLogtail Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once
#include <memory>
#include <set>
#include <string>
#include <unordered_map>
#include "collection_pipeline/plugin/creator/PluginCreator.h"
#include "collection_pipeline/plugin/instance/FlusherInstance.h"
#include "collection_pipeline/plugin/instance/InputInstance.h"
#include "collection_pipeline/plugin/instance/PluginInstance.h"
#include "collection_pipeline/plugin/instance/ProcessorInstance.h"
#include "common/DynamicLibHelper.h"
#include "runner/sink/SinkType.h"
struct processor_interface_t;
namespace logtail {
class PluginRegistry {
public:
PluginRegistry(const PluginRegistry&) = delete;
PluginRegistry& operator=(const PluginRegistry&) = delete;
static PluginRegistry* GetInstance() {
static PluginRegistry instance;
return &instance;
}
void LoadPlugins();
void UnloadPlugins();
std::unique_ptr<InputInstance> CreateInput(const std::string& name, const PluginInstance::PluginMeta& pluginMeta);
std::unique_ptr<ProcessorInstance> CreateProcessor(const std::string& name,
const PluginInstance::PluginMeta& pluginMeta);
std::unique_ptr<FlusherInstance> CreateFlusher(const std::string& name,
const PluginInstance::PluginMeta& pluginMeta);
bool IsValidGoPlugin(const std::string& name) const;
bool IsValidNativeInputPlugin(const std::string& name) const;
bool IsValidNativeProcessorPlugin(const std::string& name) const;
bool IsValidNativeFlusherPlugin(const std::string& name) const;
bool IsGlobalSingletonInputPlugin(const std::string& name) const;
void RegisterInputCreator(PluginCreator* creator, bool isSingleton = false);
void RegisterProcessorCreator(PluginCreator* creator);
void RegisterFlusherCreator(PluginCreator* creator, bool isSingleton = false);
private:
enum PluginCat { INPUT_PLUGIN, PROCESSOR_PLUGIN, FLUSHER_PLUGIN };
struct PluginKey {
PluginCat cat;
std::string name;
PluginKey(PluginCat cat, const std::string& name) : cat(cat), name(name) {}
bool operator==(const PluginKey& other) const { return cat == other.cat && name == other.name; }
};
struct PluginKeyHash {
size_t operator()(const PluginKey& obj) const {
return std::hash<int>()(obj.cat) ^ std::hash<std::string>()(obj.name);
}
};
using PluginCreatorWithInfo = std::pair<std::shared_ptr<PluginCreator>, bool>;
PluginRegistry() {}
~PluginRegistry() = default;
void LoadStaticPlugins();
void LoadDynamicPlugins(const std::set<std::string>& plugins);
PluginCreator* LoadProcessorPlugin(DynamicLibLoader& loader, const std::string pluginType);
void RegisterCreator(PluginCat cat, PluginCreator* creator, bool isSingleton);
std::unique_ptr<PluginInstance>
Create(PluginCat cat, const std::string& name, const PluginInstance::PluginMeta& pluginMeta);
bool IsGlobalSingleton(PluginCat cat, const std::string& name) const;
std::unordered_map<PluginKey, PluginCreatorWithInfo, PluginKeyHash> mPluginDict;
#ifdef APSARA_UNIT_TEST_MAIN
friend class PluginRegistryUnittest;
friend class PipelineUpdateUnittest;
friend void LoadPluginMock();
#endif
};
} // namespace logtail