![]() |
RTBKit
0.9
Open-source framework to create real-time ad bidding systems.
|
00001 /* router_stack.h -*- C++ -*- 00002 Jeremy Barnes, 21 November 2012 00003 Copyright (c) 2012 Datacratic Inc. All rights reserved. 00004 00005 The core router stack. 00006 */ 00007 00008 #pragma once 00009 00010 00011 #include "router.h" 00012 #include "rtbkit/core/monitor/monitor_endpoint.h" 00013 #include "rtbkit/core/banker/master_banker.h" 00014 #include "rtbkit/core/banker/slave_banker.h" 00015 #include "rtbkit/core/post_auction/post_auction_loop.h" 00016 #include "rtbkit/core/agent_configuration/agent_configuration_service.h" 00017 #include "soa/service/testing/redis_temporary_server.h" 00018 00019 namespace RTBKIT { 00020 00021 00022 /*****************************************************************************/ 00023 /* ROUTER STACK */ 00024 /*****************************************************************************/ 00025 00034 struct RouterStack: public ServiceBase { 00035 00036 RouterStack(std::shared_ptr<ServiceProxies> services, 00037 const std::string & serviceName = "routerStack", 00038 double secondsUntilLossAssumed = 2.0); 00039 00040 void init(); 00041 00044 virtual void 00045 start(boost::function<void ()> onStop = boost::function<void ()>()); 00046 00050 virtual void sleepUntilIdle(); 00051 00052 virtual void shutdown(); 00053 00054 virtual size_t numNonIdle() const; 00055 00056 void submitAuction(const std::shared_ptr<Auction> & auction, 00057 const Id & adSpotId, 00058 const Auction::Response & response); 00059 00060 void notifyFinishedAuction(const Id & auctionId) 00061 { 00062 router.notifyFinishedAuction(auctionId); 00063 } 00064 00065 int numAuctionsInProgress() 00066 { 00067 return router.numAuctionsInProgress(); 00068 } 00069 00070 Json::Value getStats() const 00071 { 00072 return router.getStats(); 00073 } 00074 00076 void injectWin(const Id & auctionId, 00077 const Id & adSpotId, 00078 Amount winPrice, 00079 Date timestamp, 00080 const JsonHolder & winMeta, 00081 const UserIds & uids, 00082 const AccountKey & account, 00083 Date bidTimestamp) 00084 { 00085 postAuctionLoop.injectWin(auctionId, adSpotId, winPrice, 00086 timestamp, winMeta, uids, 00087 account, bidTimestamp); 00088 } 00089 00094 void injectLoss(const Id & auctionId, 00095 const Id & adSpotId, 00096 Date timestamp, 00097 const JsonHolder & lossMeta, 00098 const AccountKey & account, 00099 Date bidTimestamp) 00100 { 00101 postAuctionLoop.injectLoss(auctionId, adSpotId, timestamp, 00102 lossMeta, account, bidTimestamp); 00103 } 00104 00111 void injectCampaignEvent(const std::string & label, 00112 const Id & auctionId, 00113 const Id & spotId, 00114 Date timestamp, 00115 const JsonHolder & eventMeta, 00116 const UserIds & uids) 00117 { 00118 postAuctionLoop.injectCampaignEvent(label, auctionId, spotId, 00119 timestamp, eventMeta, uids); 00120 } 00121 00139 void notifyFinishedSpot(const Id & auctionId, const Id & adSpotId) 00140 { 00141 postAuctionLoop.notifyFinishedSpot(auctionId, adSpotId); 00142 } 00143 00145 void initStatePersistence(const std::string & path) 00146 { 00147 postAuctionLoop.initStatePersistence(path); 00148 } 00149 00153 void addBudget(const AccountKey & account, CurrencyPool amount); 00154 00158 void setBudget(const AccountKey & account, CurrencyPool amount); 00159 00160 void topupTransfer(const AccountKey & account, CurrencyPool amount); 00161 00162 Router router; 00163 00164 Redis::RedisTemporaryServer redis; 00165 MasterBanker masterBanker; 00166 SlaveBudgetController budgetController; 00167 00168 PostAuctionLoop postAuctionLoop; 00169 AgentConfigurationService config; 00170 00171 MonitorEndpoint monitor; 00172 00173 bool initialized; 00174 }; 00175 00176 00177 00178 } // namespace RTBKIT 00179 00180