RTBKit
0.9
Open-source framework to create real-time ad bidding systems.
|
00001 /* monitor_provider.h -*- C++ -*- 00002 Wolfgang Sourdeau, January 2013 00003 Copyright (c) 2013 Datacratic. All rights reserved. 00004 00005 Rest endpoint queried by the monitor in the provider processes 00006 */ 00007 00008 #pragma once 00009 00010 #include <memory> 00011 00012 #include "soa/types/date.h" 00013 #include "soa/service/rest_proxy.h" 00014 00015 namespace zmq { 00016 struct context_t; 00017 } // namespace zmq 00018 00019 namespace Json { 00020 struct Value; 00021 } // namespace Json 00022 00023 namespace RTBKIT { 00024 using namespace Datacratic; 00025 00026 struct MonitorProvider 00027 { 00028 /* this method returns the service identifier to use when sending status 00029 information to the Monitor */ 00030 virtual std::string getProviderName() const = 0; 00031 00032 /* this method returns the service status: "true" indicates that all the 00033 service-specific conditions are fulfilled, "false" otherwise */ 00034 virtual Json::Value getProviderIndicators() const = 0; 00035 }; 00036 00037 struct MonitorProviderClient : public RestProxy 00038 { 00039 MonitorProviderClient(const std::shared_ptr<zmq::context_t> & context, 00040 MonitorProvider & provider); 00041 00042 ~MonitorProviderClient(); 00043 00044 void init(std::shared_ptr<ConfigurationService> & config, 00045 const std::string & serviceName = "monitor"); 00046 00049 void shutdown(); 00050 00053 void postStatus(); 00054 00056 void onResponseReceived(std::exception_ptr ext, 00057 int responseCode, const std::string & body); 00058 00060 MonitorProvider & provider_; 00061 00063 bool inhibit_; 00064 00066 std::string restUrlPath_; 00067 00069 RestProxy::OnDone onDone; 00070 00072 bool pendingRequest; 00073 00075 typedef std::unique_lock<std::mutex> Guard; 00076 mutable std::mutex requestLock; 00077 }; 00078 00079 } // namespace RTBKIT