RTBKit
0.9
Open-source framework to create real-time ad bidding systems.
|
00001 /* monitor_client.h -*- C++ -*- 00002 Wolfgang Sourdeau, January 2013 00003 Copyright (c) 2013 Datacratic. All rights reserved. 00004 */ 00005 00006 #pragma once 00007 00008 #include <mutex> 00009 #include <vector> 00010 #include "soa/types/date.h" 00011 #include "soa/service/rest_proxy.h" 00012 00013 namespace RTBKIT { 00014 using namespace Datacratic; 00015 00016 /* This class connects to the Monitor service and queries it periodically to 00017 * deduce whether the current service (probably the Router) can continue 00018 * processing its client requests. */ 00019 struct MonitorClient : public RestProxy 00020 { 00021 MonitorClient(const std::shared_ptr<zmq::context_t> & context, 00022 int checkTimeout = 2) 00023 : RestProxy(context), 00024 pendingRequest(false), 00025 checkTimeout_(checkTimeout), lastStatus(false), 00026 testMode(false), testResponse(false) 00027 { 00028 onDone = std::bind(&MonitorClient::onResponseReceived, this, 00029 std::placeholders::_1, std::placeholders::_2, 00030 std::placeholders::_3); 00031 }; 00032 00033 ~MonitorClient(); 00034 00035 void init(std::shared_ptr<ConfigurationService> & config, 00036 const std::string & serviceName = "monitor"); 00037 00040 void shutdown(); 00041 00044 bool getStatus() const; 00045 00046 /* private members */ 00047 00049 void checkStatus(); 00050 00052 void onResponseReceived(std::exception_ptr ext, 00053 int responseCode, const std::string & body); 00055 RestProxy::OnDone onDone; 00056 00058 bool pendingRequest; 00059 00061 typedef std::unique_lock<std::mutex> Guard; 00062 mutable std::mutex requestLock; 00063 00065 int checkTimeout_; 00066 00068 bool lastStatus; 00069 00071 Date lastCheck; 00072 00074 bool testMode; 00075 bool testResponse; 00076 }; 00077 00078 } // RTB