16 #include "tensorflow_serving/core/log_collector.h"
19 #include <unordered_map>
21 #include "tensorflow/core/lib/core/errors.h"
22 #include "tensorflow/core/lib/strings/scanner.h"
23 #include "tensorflow/core/platform/mutex.h"
24 #include "tensorflow/core/platform/thread_annotations.h"
26 namespace tensorflow {
33 Status Register(
const string& type,
const LogCollector::Factory& factory)
34 TF_LOCKS_EXCLUDED(mu_) {
36 const auto found_it = factory_map_.find(type);
37 if (found_it != factory_map_.end()) {
38 return errors::AlreadyExists(
"Type ", type,
" already registered.");
40 factory_map_.insert({type, factory});
44 const LogCollector::Factory* Lookup(
const string& type)
const
45 TF_LOCKS_EXCLUDED(mu_) {
47 const auto found_it = factory_map_.find(type);
48 if (found_it == factory_map_.end()) {
51 return &(found_it->second);
56 std::unordered_map<string, LogCollector::Factory> factory_map_
60 Registry* GetRegistry() {
61 static auto* registry =
new Registry();
67 Status LogCollector::RegisterFactory(
const string& type,
68 const Factory& factory) {
69 return GetRegistry()->Register(type, factory);
72 Status LogCollector::Create(
73 const LogCollectorConfig& config,
const uint32
id,
74 std::unique_ptr<LogCollector>*
const log_collector) {
75 auto* factory = GetRegistry()->Lookup(config.type());
76 if (factory ==
nullptr) {
77 return errors::NotFound(
"Cannot find LogCollector::Factory for type: ",
80 return (*factory)(config, id, log_collector);