11 #ifndef THRIFT_APPLICATION_BASE_H
12 #define THRIFT_APPLICATION_BASE_H
18 #include <boost/date_time/posix_time/posix_time.hpp>
24 static constexpr
unsigned int THRIFTAPPLICATION_ACTIVATION_TIMEOUT_MS(200);
73 template <
typename TserverBase,
typename TserverClass>
91 static TserverBase*
i();
164 bool application_started();
170 static void start_application();
174 static std::unique_ptr<thrift_application_base_impl> p_impl;
182 bool d_thirft_is_running;
185 template <
typename TserverBase,
typename TserverClass>
188 template <
typename TserverBase,
typename TserverClass>
191 : d_lock(), d_thirft_is_running(false)
197 template <
typename TserverBase,
typename TserverClass>
200 unsigned int max_init_attempts =
202 "thrift",
"init_attempts", d_default_max_init_attempts));
204 if (!p_impl->d_application_initialized) {
206 boost::bind(&thrift_application_base::start_thrift, d_application))));
208 bool app_started(
false);
209 for (
unsigned int attempts(0); (!app_started && attempts < max_init_attempts);
211 boost::this_thread::sleep(
212 boost::posix_time::milliseconds(THRIFTAPPLICATION_ACTIVATION_TIMEOUT_MS));
213 app_started = d_application->application_started();
217 GR_WARN(
"thrift_application_base",
218 "thrift_application_base::start_application(), "
219 "timeout waiting to port number might have failed?");
222 p_impl->d_application_initialized =
true;
226 template <
typename TserverBase,
typename TserverClass>
227 const std::vector<std::string>
230 std::vector<std::string> ep;
231 ep.push_back(p_impl->d_endpointStr);
235 template <
typename TserverBase,
typename TserverClass>
237 const std::string& endpoint)
240 p_impl->d_endpointStr = endpoint;
243 template <
typename TserverBase,
typename TserverClass>
246 if (!p_impl->d_application_initialized) {
249 return d_application->i_impl();
virtual 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:41
std::string d_endpointStr
Definition: thrift_application_base.h:52
bool d_application_initialized
Definition: thrift_application_base.h:50
std::shared_ptr< gr::thread::thread > d_start_thrift_thread
Definition: thrift_application_base.h:54
thrift_application_base_impl()
Definition: thrift_application_base.h:43
Base class for a Thrift application with a singleton with instance function thrift_application_base::...
Definition: thrift_application_base.h:75
virtual TserverBase * i_impl()=0
static const unsigned int d_default_thrift_buffer_size
Definition: thrift_application_base.h:144
gr::logger_ptr d_logger
Definition: thrift_application_base.h:150
thrift_application_base(TserverClass *_app)
Definition: thrift_application_base.h:189
std::unique_ptr< apache::thrift::server::TServer > d_thriftserver
Definition: thrift_application_base.h:117
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:138
static const std::vector< std::string > endpoints()
Definition: thrift_application_base.h:228
static TserverClass * d_application
Definition: thrift_application_base.h:112
static const unsigned int d_default_thrift_port
Definition: thrift_application_base.h:131
static const unsigned int d_default_max_init_attempts
Definition: thrift_application_base.h:124
~thrift_application_base()
static TserverBase * i()
Definition: thrift_application_base.h:244
gr::logger_ptr d_debug_logger
Definition: thrift_application_base.h:150
#define GR_WARN(name, msg)
Definition: logger.h:177
Definition: thrift_application_base.h:27
boost::mutex mutex
Definition: thread.h:37
boost::unique_lock< boost::mutex > scoped_lock
Definition: thread.h:38
boost::thread thread
Definition: thread.h:36
GR_RUNTIME_API bool configure_default_loggers(gr::logger_ptr &l, gr::logger_ptr &d, const std::string name)
log4cpp::Category * logger_ptr
GR_LOG macros.
Definition: logger.h:60