23 #ifndef THRIFT_APPLICATION_BASE_H 24 #define THRIFT_APPLICATION_BASE_H 30 #include <boost/date_time/posix_time/posix_time.hpp> 31 #include <boost/scoped_ptr.hpp> 36 static const unsigned int THRIFTAPPLICATION_ACTIVATION_TIMEOUT_MS(200);
56 : d_application_initialized(false), d_endpointStr(
""), d_start_thrift_thread()
85 template <
typename TserverBase,
typename TserverClass>
103 static TserverBase* i();
108 static const std::vector<std::string> endpoints();
117 void set_endpoint(
const std::string& endpoint);
119 virtual TserverBase* i_impl() = 0;
176 bool application_started();
182 static void start_application();
186 static boost::scoped_ptr<thrift_application_base_impl> p_impl;
194 bool d_thirft_is_running;
197 template <
typename TserverBase,
typename TserverClass>
200 template <
typename TserverBase,
typename TserverClass>
203 : d_lock(), d_thirft_is_running(false)
209 template <
typename TserverBase,
typename TserverClass>
212 unsigned int max_init_attempts =
216 if (!p_impl->d_application_initialized) {
218 boost::bind(&thrift_application_base::start_thrift,
d_application))));
220 bool app_started(
false);
221 for (
unsigned int attempts(0); (!app_started && attempts < max_init_attempts);
223 boost::this_thread::sleep(
224 boost::posix_time::milliseconds(THRIFTAPPLICATION_ACTIVATION_TIMEOUT_MS));
229 GR_WARN(
"thrift_application_base",
230 "thrift_application_base::start_application(), " 231 "timeout waiting to port number might have failed?");
234 p_impl->d_application_initialized =
true;
238 template <
typename TserverBase,
typename TserverClass>
239 const std::vector<std::string>
242 std::vector<std::string> ep;
243 ep.push_back(p_impl->d_endpointStr);
247 template <
typename TserverBase,
typename TserverClass>
249 const std::string& endpoint)
252 p_impl->d_endpointStr = endpoint;
255 template <
typename TserverBase,
typename TserverClass>
258 if (!p_impl->d_application_initialized) {
boost::unique_lock< boost::mutex > scoped_lock
Definition: thread.h:49
#define GR_WARN(name, msg)
Definition: logger.h:188
gr::logger_ptr d_logger
Definition: thrift_application_base.h:162
std::string d_endpointStr
Definition: thrift_application_base.h:64
static const unsigned int d_default_max_init_attempts
Definition: thrift_application_base.h:136
static const std::vector< std::string > endpoints()
Definition: thrift_application_base.h:240
static TserverClass * d_application
Definition: thrift_application_base.h:124
static const unsigned int d_default_num_thrift_threads
Definition: thrift_application_base.h:150
boost::thread thread
Definition: thread.h:47
static TserverBase * i()
Definition: thrift_application_base.h:256
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. ...
boost::scoped_ptr< apache::thrift::server::TServer > d_thriftserver
Definition: thrift_application_base.h:129
Base class for a Thrift application with a singleton with instance function thrift_application_base::...
Definition: thrift_application_base.h:86
GR_RUNTIME_API bool configure_default_loggers(gr::logger_ptr &l, gr::logger_ptr &d, const std::string name)
Class to be statically initialized by thrift_application_base. Used to store state for thrift_applica...
Definition: thrift_application_base.h:52
thrift_application_base(TserverClass *_app)
Definition: thrift_application_base.h:201
Definition: thrift_application_base.h:39
bool d_application_initialized
Definition: thrift_application_base.h:62
static const unsigned int d_default_thrift_port
Definition: thrift_application_base.h:143
log4cpp::Category * logger_ptr
GR_LOG macrosThese macros wrap the standard LOG4CPP_LEVEL macros. The availablie macros are: LOG_DEBU...
Definition: logger.h:71
boost::mutex mutex
Definition: thread.h:48
static prefs * singleton()
thrift_application_base_impl()
Definition: thrift_application_base.h:55
boost::shared_ptr< gr::thread::thread > d_start_thrift_thread
Definition: thrift_application_base.h:66
static const unsigned int d_default_thrift_buffer_size
Definition: thrift_application_base.h:156
gr::logger_ptr d_debug_logger
Definition: thrift_application_base.h:162
void set_endpoint(const std::string &endpoint)
Definition: thrift_application_base.h:248