Line data Source code
1 : #pragma once 2 : 3 : #include <memory> 4 : #include <string> 5 : 6 : #include "envoy/common/random_generator.h" 7 : #include "envoy/common/time.h" 8 : #include "envoy/config/bootstrap/v3/bootstrap.pb.h" 9 : #include "envoy/event/dispatcher.h" 10 : #include "envoy/event/scaled_range_timer_manager.h" 11 : #include "envoy/filesystem/filesystem.h" 12 : #include "envoy/server/process_context.h" 13 : #include "envoy/stats/custom_stat_namespaces.h" 14 : #include "envoy/stats/store.h" 15 : #include "envoy/thread/thread.h" 16 : 17 : namespace Envoy { 18 : namespace Api { 19 : 20 : /** 21 : * "Public" API that different components use to interact with the various system abstractions. 22 : */ 23 : class Api { 24 : public: 25 2309 : virtual ~Api() = default; 26 : 27 : /** 28 : * Allocate a dispatcher. 29 : * @param name the identity name for a dispatcher, e.g. "worker_2" or "main_thread". 30 : * This name will appear in per-handler/worker statistics, such as 31 : * "server.worker_2.watchdog_miss". 32 : * @return Event::DispatcherPtr which is owned by the caller. 33 : */ 34 : virtual Event::DispatcherPtr allocateDispatcher(const std::string& name) PURE; 35 : 36 : /** 37 : * Allocate a dispatcher. 38 : * @param name the identity name for a dispatcher, e.g. "worker_2" or "main_thread". 39 : * This name will appear in per-handler/worker statistics, such as 40 : * "server.worker_2.watchdog_miss". 41 : * @param scaled_timer_factory the factory to use when creating the scaled timer manager. 42 : * @return Event::DispatcherPtr which is owned by the caller. 43 : */ 44 : virtual Event::DispatcherPtr 45 : allocateDispatcher(const std::string& name, 46 : const Event::ScaledRangeTimerManagerFactory& scaled_timer_factory) PURE; 47 : 48 : /** 49 : * Allocate a dispatcher. 50 : * @param name the identity name for a dispatcher, e.g. "worker_2" or "main_thread". 51 : * This name will appear in per-handler/worker statistics, such as 52 : * "server.worker_2.watchdog_miss". 53 : * @param watermark_factory the watermark factory, ownership is transferred to the dispatcher. 54 : * @return Event::DispatcherPtr which is owned by the caller. 55 : */ 56 : virtual Event::DispatcherPtr 57 : allocateDispatcher(const std::string& name, Buffer::WatermarkFactoryPtr&& watermark_factory) PURE; 58 : 59 : /** 60 : * @return a reference to the ThreadFactory 61 : */ 62 : virtual Thread::ThreadFactory& threadFactory() PURE; 63 : 64 : /** 65 : * @return a reference to the Filesystem::Instance 66 : */ 67 : virtual Filesystem::Instance& fileSystem() PURE; 68 : 69 : /** 70 : * @return a reference to the TimeSource 71 : */ 72 : virtual TimeSource& timeSource() PURE; 73 : 74 : /** 75 : * @return a reference to the root Stats::Scope 76 : */ 77 : virtual Stats::Scope& rootScope() PURE; 78 : 79 : /** 80 : * @return a reference to the RandomGenerator. 81 : */ 82 : virtual Random::RandomGenerator& randomGenerator() PURE; 83 : 84 : /** 85 : * @return an optional reference to the ProcessContext 86 : */ 87 : virtual ProcessContextOptRef processContext() PURE; 88 : 89 : /** 90 : * @return the bootstrap Envoy started with. 91 : */ 92 : virtual const envoy::config::bootstrap::v3::Bootstrap& bootstrap() const PURE; 93 : 94 : /** 95 : * @return a reference to the Stats::CustomStatNamespaces. 96 : */ 97 : virtual Stats::CustomStatNamespaces& customStatNamespaces() PURE; 98 : }; 99 : 100 : using ApiPtr = std::unique_ptr<Api>; 101 : 102 : } // namespace Api 103 : } // namespace Envoy