RTBKit  0.9
Open-source framework to create real-time ad bidding systems.
core/banker/banker_service_runner.cc
00001 /* banker_service_runner.cc                                        -*- C++ -*-
00002    Jeremy Barnes, 20 November 2012
00003    Copyright (c) 2012 Datacratic.  All rights reserved.
00004 
00005    Runner for the banker service.
00006 */
00007 
00008 
00009 #include <boost/program_options/cmdline.hpp>
00010 #include <boost/program_options/options_description.hpp>
00011 #include <boost/program_options/positional_options.hpp>
00012 #include <boost/program_options/parsers.hpp>
00013 #include <boost/program_options/variables_map.hpp>
00014 #include <boost/algorithm/string.hpp>
00015 #include <boost/thread/thread.hpp>
00016 #include <boost/make_shared.hpp>
00017 
00018 #include "rtbkit/core/banker/master_banker.h"
00019 #include "soa/service/service_utils.h"
00020 #include "jml/utils/pair_utils.h"
00021 #include "jml/arch/timers.h"
00022 #include "jml/arch/futex.h"
00023 
00024 
00025 using namespace std;
00026 using namespace ML;
00027 using namespace Datacratic;
00028 using namespace RTBKIT;
00029 
00030 
00031 int main(int argc, char ** argv)
00032 {
00033     using namespace boost::program_options;
00034 
00035     ServiceProxyArguments serviceArgs;
00036 
00037     options_description configuration_options("Configuration options");
00038 
00039     std::string redisUri;  
00040 
00041     std::vector<std::string> fixedHttpBindAddresses;
00042 
00043     configuration_options.add_options()
00044         ("redis-uri,r", value<string>(&redisUri)->required(),
00045          "URI of connection to redis")
00046         ("fixed-http-bind-address,a", value(&fixedHttpBindAddresses),
00047          "Fixed address (host:port or *:port) at which we will always listen");
00048 
00049     options_description all_opt;
00050     all_opt
00051         .add(serviceArgs.makeProgramOptions())
00052         .add(configuration_options);
00053     all_opt.add_options()
00054         ("help,h", "print this message");
00055     
00056     variables_map vm;
00057     store(command_line_parser(argc, argv)
00058           .options(all_opt)
00059           //.positional(p)
00060           .run(),
00061           vm);
00062     notify(vm);
00063 
00064     if (vm.count("help")) {
00065         cerr << all_opt << endl;
00066         exit(1);
00067     }
00068 
00069     auto proxies = serviceArgs.makeServiceProxies();
00070 
00071     MasterBanker banker(proxies, "masterBanker");
00072     std::shared_ptr<Redis::AsyncConnection> redis;
00073 
00074     if (redisUri != "nopersistence") {
00075         auto address = Redis::Address(redisUri);
00076         redis = std::make_shared<Redis::AsyncConnection>(redisUri);
00077         redis->test();
00078 
00079         banker.init(std::make_shared<RedisBankerPersistence>(redisUri));
00080     }
00081     else {
00082         cerr << "*** WARNING ***" << endl;
00083         cerr << "BANKER IS RUNNING WITH NO PERSISTENCE" << endl;
00084         cerr << "IF THIS IS NOT A TESTING ENVIRONEMNT, SPEND WILL BE LOST" << endl;
00085         banker.init(std::make_shared<NoBankerPersistence>());
00086     }
00087 
00088     // Bind to any fixed addresses
00089     for (auto a: fixedHttpBindAddresses)
00090         banker.bindFixedHttpAddress(a);
00091 
00092     auto addr = banker.bindTcp();
00093     cerr << "master banker is listening on " << addr.first << ","
00094          << addr.second << endl;
00095 
00096     banker.start();
00097     proxies->config->dump(cerr);
00098 
00099     for (;;) {
00100         ML::sleep(10);
00101     }
00102 }
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator