11#ifndef THRIFT_APPLICATION_BASE_H
12#define THRIFT_APPLICATION_BASE_H
25static constexpr unsigned int THRIFTAPPLICATION_ACTIVATION_TIMEOUT_MS(200);
74template <
typename TserverBase,
typename TserverClass>
92 static TserverBase*
i();
165 bool application_started();
171 static void start_application();
175 static std::unique_ptr<thrift_application_base_impl> p_impl;
183 bool d_thirft_is_running;
186template <
typename TserverBase,
typename TserverClass>
189template <
typename TserverBase,
typename TserverClass>
192 : d_lock(), d_thirft_is_running(false)
198template <
typename TserverBase,
typename TserverClass>
201 unsigned int max_init_attempts =
203 "thrift",
"init_attempts", d_default_max_init_attempts));
205 if (!p_impl->d_application_initialized) {
206 p_impl->d_start_thrift_thread = std::make_shared<gr::thread::thread>(
207 [app = d_application] { app->start_thrift(); });
209 bool app_started(
false);
210 for (
unsigned int attempts(0); (!app_started && attempts < max_init_attempts);
212 std::this_thread::sleep_for(
213 std::chrono::milliseconds(THRIFTAPPLICATION_ACTIVATION_TIMEOUT_MS));
214 app_started = d_application->application_started();
219 log.warn(
"start_application(): timeout waiting");
222 p_impl->d_application_initialized =
true;
226template <
typename TserverBase,
typename TserverClass>
227const std::vector<std::string>
230 std::vector<std::string> ep;
231 ep.push_back(p_impl->d_endpointStr);
235template <
typename TserverBase,
typename TserverClass>
237 const std::string& endpoint)
240 p_impl->d_endpointStr = endpoint;
243template <
typename TserverBase,
typename TserverClass>
246 if (!p_impl->d_application_initialized) {
249 return d_application->i_impl();
GR_LOG macros.
Definition: logger.h:119
long get_long(const std::string §ion, const std::string &option, long default_val)
If option exists and value can be converted to long, return it; else default_val.
static prefs * singleton()
Class to be statically initialized by thrift_application_base. Used to store state for thrift_applica...
Definition: thrift_application_base.h:42
std::string d_endpointStr
Definition: thrift_application_base.h:53
bool d_application_initialized
Definition: thrift_application_base.h:51
std::shared_ptr< gr::thread::thread > d_start_thrift_thread
Definition: thrift_application_base.h:55
thrift_application_base_impl()
Definition: thrift_application_base.h:44
Base class for a Thrift application with a singleton with instance function thrift_application_base::...
Definition: thrift_application_base.h:76
static const unsigned int d_default_thrift_buffer_size
Definition: thrift_application_base.h:145
gr::logger_ptr d_logger
Definition: thrift_application_base.h:151
thrift_application_base(TserverClass *_app)
Definition: thrift_application_base.h:190
std::unique_ptr< apache::thrift::server::TServer > d_thriftserver
Definition: thrift_application_base.h:118
void set_endpoint(const std::string &endpoint)
Definition: thrift_application_base.h:236
static const unsigned int d_default_num_thrift_threads
Definition: thrift_application_base.h:139
static const std::vector< std::string > endpoints()
Definition: thrift_application_base.h:228
static TserverClass * d_application
Definition: thrift_application_base.h:113
static const unsigned int d_default_thrift_port
Definition: thrift_application_base.h:132
virtual TserverBase * i_impl()=0
static const unsigned int d_default_max_init_attempts
Definition: thrift_application_base.h:125
~thrift_application_base()
static TserverBase * i()
Definition: thrift_application_base.h:244
gr::logger_ptr d_debug_logger
Definition: thrift_application_base.h:151
Definition: thrift_application_base.h:28
boost::mutex mutex
Definition: thread.h:37
boost::unique_lock< boost::mutex > scoped_lock
Definition: thread.h:38
std::shared_ptr< logger > logger_ptr
Definition: logger.h:225
GR_RUNTIME_API bool configure_default_loggers(gr::logger_ptr &l, gr::logger_ptr &d, const std::string &name)