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);
39 namespace apache {
namespace thrift {
namespace server {
class TServer; } } }
50 d_application_initilized(false),
52 d_start_thrift_thread() {;}
78 template<
typename TserverBase,
typename TserverClass>
96 static TserverBase* i();
101 static const std::vector<std::string> endpoints();
110 void set_endpoint(
const std::string& endpoint);
112 virtual TserverBase* i_impl() = 0;
169 bool application_started();
175 static void start_application();
179 static boost::scoped_ptr<thrift_application_base_impl > p_impl;
187 bool d_thirft_is_running;
190 template<
typename TserverBase,
typename TserverClass>
193 template<
typename TserverBase,
typename TserverClass>
196 d_thirft_is_running(false)
202 template<
typename TserverBase,
typename TserverClass>
205 unsigned int max_init_attempts = \
209 if(!p_impl->d_application_initilized) {
210 p_impl->d_start_thrift_thread.reset(
213 bool app_started(
false);
214 for(
unsigned int attempts(0); (!app_started && attempts < max_init_attempts); ++attempts) {
215 boost::this_thread::sleep(boost::posix_time::milliseconds(THRIFTAPPLICATION_ACTIVATION_TIMEOUT_MS));
220 GR_WARN(
"thrift_application_base",
"thrift_application_base::start_application(), " 221 "timeout waiting to port number might have failed?");
224 p_impl->d_application_initilized =
true;
228 template<
typename TserverBase,
typename TserverClass>
231 std::vector<std::string> ep;
232 ep.push_back(p_impl->d_endpointStr);
236 template<
typename TserverBase,
typename TserverClass>
240 p_impl->d_endpointStr = endpoint;
243 template<
typename TserverBase,
typename TserverClass>
246 if(!p_impl->d_application_initilized) {
boost::unique_lock< boost::mutex > scoped_lock
Definition: thread.h:49
#define GR_WARN(name, msg)
Definition: logger.h:727
gr::logger_ptr d_logger
Definition: thrift_application_base.h:154
std::string d_endpointStr
Definition: thrift_application_base.h:57
static const unsigned int d_default_max_init_attempts
Definition: thrift_application_base.h:129
static const std::vector< std::string > endpoints()
Definition: thrift_application_base.h:229
static TserverClass * d_application
Definition: thrift_application_base.h:117
static const unsigned int d_default_num_thrift_threads
Definition: thrift_application_base.h:143
boost::thread thread
Definition: thread.h:47
void * logger_ptr
Definition: logger.h:696
static TserverBase * i()
Definition: thrift_application_base.h:244
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:122
Base class for a Thrift application with a singleton with instance function thrift_application_base::...
Definition: thrift_application_base.h:79
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:46
thrift_application_base(TserverClass *_app)
Definition: thrift_application_base.h:194
Definition: thrift_application_base.h:39
static const unsigned int d_default_thrift_port
Definition: thrift_application_base.h:136
bool d_application_initilized
Definition: thrift_application_base.h:55
boost::mutex mutex
Definition: thread.h:48
static prefs * singleton()
thrift_application_base_impl()
Definition: thrift_application_base.h:49
boost::shared_ptr< gr::thread::thread > d_start_thrift_thread
Definition: thrift_application_base.h:59
static const unsigned int d_default_thrift_buffer_size
Definition: thrift_application_base.h:149
gr::logger_ptr d_debug_logger
Definition: thrift_application_base.h:154
void set_endpoint(const std::string &endpoint)
Definition: thrift_application_base.h:237