RTBKit  0.9
Open-source framework to create real-time ad bidding systems.
plugins/exchange/http_auction_handler.h
00001 /* http_auction_handler.h                                          -*- C++ -*-
00002    Jeremy Barnes, 14 December 2012
00003    Copyright (c) 2012 Datacratic.  All rights reserved.
00004 
00005    Class to deal with http connections to an exchange.
00006 */
00007 
00008 #pragma once
00009 
00010 #include "soa/service/http_endpoint.h"
00011 #include "soa/service/stats_events.h"
00012 #include "rtbkit/common/auction.h"
00013 
00014 namespace RTBKIT {
00015 
00016 struct HttpExchangeConnector;
00017 
00018 
00019 /*****************************************************************************/
00020 /* HTTP AUCTION HANDLER                                                      */
00021 /*****************************************************************************/
00022 
00023 struct HttpAuctionHandler
00024     : public HttpConnectionHandler,
00025       public std::enable_shared_from_this<HttpAuctionHandler> {
00026 
00027     HttpAuctionHandler();
00028     ~HttpAuctionHandler();
00029 
00031     void onGotTransport();
00032 
00033     HttpExchangeConnector * endpoint;
00034 
00035     std::shared_ptr<Auction> auction;
00036     bool hasTimer;
00037     bool disconnected;
00038     bool servingRequest;  
00039 
00040     virtual void handleHttpPayload(const HttpHeader & header,
00041                                    const std::string & payload);
00042 
00044     virtual void handleDisconnect();
00045 
00046     void cancelTimer();
00047 
00051     virtual void sendErrorResponse(const std::string & error,
00052                                    const std::string & details = "");
00053     
00056     virtual void dropAuction(const std::string & reason = "");
00057 
00058     virtual void handleTimeout(Date date, size_t cookie);
00059 
00060     virtual void onDisassociate();
00061     virtual void onCleanup();
00062     virtual std::string status() const;
00063 
00067     void doEvent(const char * eventName,
00068                  EventType type = ET_COUNT,
00069                  float value = 1.0,
00070                  const char * units = "");
00071 
00072     void incNumServingRequest();
00073     
00078     virtual void sendResponse();
00079 
00088     virtual HttpResponse getResponse() const;
00089 
00094     virtual std::shared_ptr<BidRequest>
00095     parseBidRequest(const HttpHeader & header,
00096                     const std::string & payload);
00097 
00106     virtual double
00107     getTimeAvailableMs(const HttpHeader & header,
00108                        const std::string & payload);
00109 
00115     virtual double
00116     getRoundTripTimeMs(const HttpHeader & header);
00117 
00118     static long created;
00119     static long destroyed;
00120 };
00121 
00122 
00123 } // namespace RTBKIT
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator