-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtile_broker.cpp
164 lines (142 loc) · 4.53 KB
/
tile_broker.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
/*------------------------------------------------------------------------------
*
* This file is part of rendermq
*
* Author: [email protected]
*
* Copyright 2010-1 Mapquest, Inc. All Rights reserved.
*
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*-----------------------------------------------------------------------------*/
#include <zmq.hpp>
#include "zmq_utils.hpp"
#include "tile_protocol.hpp"
#include "zstream.hpp"
#include "zstream_pbuf.hpp"
#include "dqueue/distributed_queue_config.hpp"
#include "tile_broker_impl.hpp"
#include "config.hpp"
#include "logging/logger.hpp"
#include <boost/format.hpp>
#include <boost/thread.hpp>
#include <boost/utility.hpp>
#include <boost/array.hpp>
#include <boost/tokenizer.hpp>
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/ini_parser.hpp>
#include <boost/program_options.hpp>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
using std::string;
using std::list;
using std::map;
using std::string;
using std::ostringstream;
using boost::format;
namespace manip = zstream::manip;
namespace pt = boost::property_tree;
namespace po = boost::program_options;
int main (int argc, char** argv)
{
using namespace rendermq;
std::string config_file, broker_name;
po::options_description cmdline_options("Tile broker\n"
"Version: " VERSION "\n"
"\n"
"Generic options:");
cmdline_options.add_options()
("help,h", "Print help message")
("logging-config,l", po::value<std::string>(), "Location of the logging configuration file.")
("queue-config,C", po::value<std::string>(&config_file), "Path to the dqueue configuration file.")
("name,n", po::value<std::string>(&broker_name), "The broker name (as used in the dqueue config).")
;
po::positional_options_description pos;
pos.add("queue-config", 1);
pos.add("name", 1);
po::variables_map vm;
try
{
po::store(po::command_line_parser(argc, argv)
.options(cmdline_options)
.positional(pos)
.run(), vm);
po::notify(vm);
if (vm.count("help"))
{
std::cerr << cmdline_options << "\n";
return EXIT_SUCCESS;
}
}
catch (std::exception &e)
{
std::cerr << e.what() << "\n";
return EXIT_FAILURE;
}
if (!vm.count("name") || !vm.count("queue-config"))
{
std::cerr << cmdline_options << "\n";
}
// read config file
pt::ptree config;
try
{
pt::read_ini(config_file, config);
}
catch (pt::ptree_error & err)
{
std::cerr << "ERROR while parsing: " << config_file << std::endl;
std::cerr << err.what() << std::endl;
return EXIT_FAILURE;
}
// check the loaded version of 0MQ library
zmq_check_version_ok();
// try to load the logging configuration
if (vm.count("logging-config"))
{
std::string logging_conf_file = vm["logging_config"].as<std::string>();
try
{
pt::ptree logging_config;
pt::read_ini(logging_conf_file, logging_config);
rendermq::log::configure(logging_config);
}
catch (const std::exception &e)
{
std::cerr << "Error while setting up logging from: " << logging_conf_file << "\n";
exit(EXIT_FAILURE);
}
}
// main entry point for broker:
try {
// set up the broker
zmq::context_t context(1);
broker_impl impl(config, argv[2], context);
// run the broker
impl();
} catch (const std::exception &e) {
LOG_ERROR(e.what());
return EXIT_FAILURE;
} catch (...) {
LOG_ERROR("UNKNOWN ERROR");
return EXIT_FAILURE;
}
// give some time for sockets to drain.
sleep (1);
return EXIT_SUCCESS;
}